Merge pull request #3199 from fantasticfears/seo
FEATURE: add microdata prop and more links for crawler
This commit is contained in:
commit
33879e1311
|
@ -62,8 +62,8 @@ class ListController < ApplicationController
|
|||
|
||||
|
||||
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
|
||||
list.more_topics_url = construct_next_url_with(list_opts)
|
||||
list.prev_topics_url = construct_prev_url_with(list_opts)
|
||||
list.more_topics_url = construct_url_with(:next, list_opts)
|
||||
list.prev_topics_url = construct_url_with(:prev, list_opts)
|
||||
if Discourse.anonymous_filters.include?(filter)
|
||||
@description = SiteSetting.site_description
|
||||
@rss = filter
|
||||
|
@ -122,8 +122,8 @@ class ListController < ApplicationController
|
|||
guardian.ensure_can_see_private_messages!(target_user.id) unless action == :topics_by
|
||||
list = generate_list_for(action.to_s, target_user, list_opts)
|
||||
url_prefix = "topics" unless action == :topics_by
|
||||
list.more_topics_url = url_for(construct_next_url_with(list_opts, url_prefix))
|
||||
list.prev_topics_url = url_for(construct_prev_url_with(list_opts, url_prefix))
|
||||
list.more_topics_url = url_for(construct_url_with(:next, list_opts, url_prefix))
|
||||
list.prev_topics_url = url_for(construct_url_with(:prev, list_opts, url_prefix))
|
||||
respond_with_list(list)
|
||||
end
|
||||
end
|
||||
|
@ -167,8 +167,8 @@ class ListController < ApplicationController
|
|||
user = list_target_user
|
||||
list = TopicQuery.new(user, top_options).list_top_for(period)
|
||||
list.for_period = period
|
||||
list.more_topics_url = construct_next_url_with(top_options)
|
||||
list.prev_topics_url = construct_prev_url_with(top_options)
|
||||
list.more_topics_url = construct_url_with(:next, top_options)
|
||||
list.prev_topics_url = construct_url_with(:prev, top_options)
|
||||
|
||||
if use_crawler_layout?
|
||||
@title = I18n.t("js.filters.top.#{period}.title")
|
||||
|
@ -280,14 +280,14 @@ class ListController < ApplicationController
|
|||
TopicQuery.new(current_user, opts).send("list_#{action}", target_user)
|
||||
end
|
||||
|
||||
def construct_next_url_with(opts, url_prefix = nil)
|
||||
def construct_url_with(action, opts, url_prefix = nil)
|
||||
method = url_prefix.blank? ? "#{action_name}_path" : "#{url_prefix}_#{action_name}_path"
|
||||
url = if action == :prev
|
||||
public_send(method, opts.merge(prev_page_params(opts)))
|
||||
else # :next
|
||||
public_send(method, opts.merge(next_page_params(opts)))
|
||||
end
|
||||
|
||||
def construct_prev_url_with(opts, url_prefix = nil)
|
||||
method = url_prefix.blank? ? "#{action_name}_path" : "#{url_prefix}_#{action_name}_path"
|
||||
public_send(method, opts.merge(prev_page_params(opts)))
|
||||
url.sub('.json?','?')
|
||||
end
|
||||
|
||||
def generate_top_lists(options)
|
||||
|
|
|
@ -4,4 +4,18 @@ module TopicsHelper
|
|||
link_to(topic.title,topic.relative_url)
|
||||
end
|
||||
|
||||
def categories_breadcrumb(topic)
|
||||
breadcrumb = [{url: categories_path,
|
||||
name: I18n.t('js.filters.categories.title')}]
|
||||
|
||||
category = topic.category
|
||||
if category
|
||||
if (parent = category.parent_category)
|
||||
breadcrumb.push url: parent.url, name: parent.name
|
||||
end
|
||||
breadcrumb.push url: category.url, name: category.name
|
||||
end
|
||||
breadcrumb
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,14 +1,26 @@
|
|||
<% @list.categories.each do |c| %>
|
||||
<div class="category">
|
||||
<h2><a href="<%= path ("/c/" << (c.slug.blank? ? c.id : c.slug)) %>"><%= c.name %></a></h2>
|
||||
<div class="topic-list">
|
||||
<div class='category-list' itemscope itemtype='http://schema.org/ItemList'>
|
||||
<meta itemprop='itemListOrder' content='http://schema.org/ItemListOrderDescending'>
|
||||
<% @list.categories.each do |c| %>
|
||||
<div class='category' itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
||||
<meta itemprop='url' content='<%= c.url %>'>
|
||||
<h2><a href='/c/<%= c.slug.blank? ? c.id : c.slug %>' itemprop='item'>
|
||||
<span itemprop='name'><%= c.name %></span>
|
||||
</a></h2>
|
||||
<span itemprop='description'><%= c.description %></span>
|
||||
<div class='topic-list' itemscope itemtype='http://schema.org/ItemList'>
|
||||
<%- if c.displayable_topics.present? %>
|
||||
<% c.displayable_topics.each do |t| %>
|
||||
<a href="<%= t.relative_url %>"><%= t.title %></a> <span title='<%= t 'posts' %>'>(<%= t.posts_count %>)</span><br/>
|
||||
<div itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
||||
<meta itemprop='url' content='<%= t.url %>'>
|
||||
<a href='<%= t.relative_url %>' itemprop='item'>
|
||||
<span itemprop='name'><%= t.title %></span>
|
||||
</a> <span title='<%= t 'posts' %>'>(<%= t.posts_count %>)</span>
|
||||
</div>
|
||||
<% end %>
|
||||
<%- end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% content_for :title do %><%= I18n.t('js.filters.categories.title') %><% end %>
|
||||
|
|
|
@ -42,7 +42,17 @@
|
|||
<!-- preload-content: -->
|
||||
<%= yield %>
|
||||
<!-- :preload-content -->
|
||||
<footer>
|
||||
<nav itemscope itemtype='http://schema.org/SiteNavigationElement'>
|
||||
<a href='/'><%= t 'home_title' %></a>
|
||||
<%= link_to t('js.filters.categories.title'), categories_path %>
|
||||
<%= link_to t('guidelines_topic.title'), guidelines_path %>
|
||||
<%= link_to t('tos_topic.title'), tos_path %>
|
||||
<%= link_to t('privacy_topic.title'), privacy_path %>
|
||||
</nav>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<footer id='noscript-footer'>
|
||||
<p><%= t 'powered_by_html' %></p>
|
||||
</footer>
|
||||
|
|
|
@ -25,6 +25,13 @@
|
|||
<%= yield %>
|
||||
</div>
|
||||
<footer class="container">
|
||||
<nav itemscope itemtype='http://schema.org/SiteNavigationElement'>
|
||||
<a href='/'><%= t 'home_title' %></a>
|
||||
<%= link_to t('js.filters.categories.title'), categories_path %>
|
||||
<%= link_to t('guidelines_topic.title'), guidelines_path %>
|
||||
<%= link_to t('tos_topic.title'), tos_path %>
|
||||
<%= link_to t('privacy_topic.title'), privacy_path %>
|
||||
</nav>
|
||||
<p><%= t 'powered_by_html' %></p>
|
||||
</footer>
|
||||
<%= render_google_analytics_code %>
|
||||
|
|
|
@ -1,21 +1,26 @@
|
|||
<div class="topic-list">
|
||||
<% @list.topics.each do |t| %>
|
||||
<a href="<%= t.relative_url %>"><%= t.title %></a>
|
||||
<div class='topic-list' itemscope itemtype='http://schema.org/ItemList'>
|
||||
<meta itemprop='itemListOrder' content='http://schema.org/ItemListOrderDescending'>
|
||||
<% @list.topics.each_with_index do |t,i| %>
|
||||
<div itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
||||
<meta itemprop='url' content='<%= t.url %>'>
|
||||
<a href='<%= t.relative_url %>' itemprop='item'>
|
||||
<span itemprop='name'><%= t.title %></span>
|
||||
</a>
|
||||
<% if !@category && t.category %>
|
||||
[<a href="<%= t.category.url%>"><%= t.category.name %></a>]
|
||||
<span>[<a href='<%= t.category.url %>'><%= t.category.name %></a>]</span>
|
||||
<% end %>
|
||||
<span title='<%= t 'posts' %>'>(<%= t.posts_count %>)</span>
|
||||
</div>
|
||||
<% end %>
|
||||
<span title='<%= t 'posts' %>'>(<%= t.posts_count %>)</span><br/>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
<% if @list.topics.length > 0 && @list.more_topics_url %>
|
||||
<p>
|
||||
<div role='navigation' itemscope itemtype='http://schema.org/SiteNavigationElement'>
|
||||
<% if params[:page].to_i > 0 %>
|
||||
<a href="<%= @list.prev_topics_url.sub('.json?','?') %>" rel="prev"><%= t 'prev_page'%></a>
|
||||
<span itemprop='url'><a href='<%= @list.prev_topics_url %>' rel='prev' itemprop='name'><%= t 'prev_page' %></a> </span>
|
||||
<% end %>
|
||||
<b><a href="<%= @list.more_topics_url.sub('.json?','?') %>" rel="next"><%= t 'next_page'%></a></b>
|
||||
</p>
|
||||
<span itemprop='url'><b><a href='<%= @list.more_topics_url %>' rel='next' itemprop='name'><%= t 'next_page' %></a></b></span>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @rss %>
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
<ul class="nav-pills">
|
||||
<li class="nav-item-about"><%= link_to t('about'), '/about' %></a></li>
|
||||
<div itemscope itemtype='http://schema.org/WebPage'>
|
||||
<meta itemprop='lastReviewed' content='<%= @topic.first_post.updated_at.to_date.to_formatted_s(:iso_8601) %>'>
|
||||
<ul class='nav-pills' role='navigation' itemscope itemtype='http://schema.org/SiteNavigationElement'>
|
||||
<% if @faq_overriden %>
|
||||
<li class="nav-item-guidelines"><a class="<%= @page == 'faq' ? 'active' : '' %>" href="<%=guidelines_path%>"><%=t "guidelines" %></a></li>
|
||||
<li class="nav-item-faq"><a href="<%=faq_path%>"><%=t "js.faq" %></a></li>
|
||||
<li class='nav-item-guidelines'><a class='<%= @page == 'faq' ? 'active' : '' %>' href='<%= guidelines_path %>'><%= t 'guidelines' %></a></li>
|
||||
<li class='nav-item-faq'><a href='<%= faq_path %>'><%= t 'js.faq' %></a></li>
|
||||
<% else %>
|
||||
<li class="nav-item-faq"><a class="<%= @page == 'faq' ? 'active' : '' %>" href="<%=faq_path%>"><%=t "js.faq" %></a></li>
|
||||
<li class='nav-item-faq'><a class='<%= @page == 'faq' ? 'active' : '' %>' href='<%=faq_path%>'><%= t 'js.faq' %></a></li>
|
||||
<% end %>
|
||||
<li class="nav-item-tos"><a href="<%=tos_path%>" class="<%= @page == 'tos' ? 'active' : '' %>"><%=t "terms_of_service.title" %></a></li>
|
||||
<li class="nav-item-privacy"><a href="<%=privacy_path%>" class="<%= @page == 'privacy' ? 'active' : '' %>"><%=t "privacy" %></a></li>
|
||||
</ul>
|
||||
<li class='nav-item-tos'><a href='<%= tos_path %>' class='<%= @page == 'tos' ? 'active' : '' %>'><%= t 'terms_of_service.title' %></a></li>
|
||||
<li class='nav-item-privacy'><a href='<%= privacy_path %>' class='<%= @page == 'privacy' ? 'active' : '' %>'><%= t 'privacy' %></a></li>
|
||||
</ul>
|
||||
|
||||
<% if staff? %>
|
||||
<p><a href="<%= @topic.url %>"><i class="fa fa-pencil"></i> <%=t "edit_this_page" -%></a></p>
|
||||
<% end %>
|
||||
<% if staff? %>
|
||||
<p><a href='<%= @topic.url %>'><i class='fa fa-pencil'></i> <%= t 'edit_this_page' %></a></p>
|
||||
<% end %>
|
||||
|
||||
<%= @body.html_safe %>
|
||||
<div itemprop='mainContentOfPage'>
|
||||
<%= @body.html_safe %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if @title %>
|
||||
<% content_for :title do %><%= @title %><% end %>
|
||||
|
|
|
@ -1,40 +1,52 @@
|
|||
<h2>
|
||||
<%= render_topic_title(@topic_view.topic) %>
|
||||
</h2>
|
||||
<% if c = @topic_view.topic.category %>
|
||||
<%= link_to c.name, c.url %>
|
||||
<% end %>
|
||||
<hr/>
|
||||
|
||||
<div itemscope itemtype='http://schema.org/BreadcrumbList'>
|
||||
<% categories_breadcrumb(@topic_view.topic).each_with_index do |c,i| %>
|
||||
<span itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
||||
<%= link_to c[:url], itemprop: 'item' do %>
|
||||
<span itemprop='name'><%= c[:name] %></span>
|
||||
<% end %>
|
||||
</span>
|
||||
<meta itemprop='position' content='<%= i + 1 %>'>
|
||||
<% end %>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
<% @topic_view.posts.each do |post| %>
|
||||
<% if post.user %>
|
||||
<div itemscope itemtype='http://schema.org/Article'>
|
||||
<% if (u = post.user) %>
|
||||
<div class='creator'>
|
||||
<b><%= post.user.username %></b>
|
||||
<%= "(#{post.user.name})" if (SiteSetting.display_name_on_posts && SiteSetting.enable_names?) %> —
|
||||
<%= post.created_at.to_formatted_s(:iso8601) %> —
|
||||
#<%= post.post_number %>
|
||||
<span>
|
||||
<a href='/users/<%= u.username %>'><b itemprop='author'><%= u.username %></b></a>
|
||||
<%= "(#{u.name})" if (SiteSetting.display_name_on_posts && SiteSetting.enable_names? && !u.name.blank?) %>
|
||||
<time datetime='<%= post.created_at.to_formatted_s(:iso8601) %>' itemprop='datePublished'>
|
||||
<%= post.created_at %>
|
||||
</time>
|
||||
</span>
|
||||
<span itemprop='position'>#<%= post.post_number %></span>
|
||||
</div>
|
||||
<div class='post'>
|
||||
<% if post.hidden %>
|
||||
<%= t('flagging.user_must_edit').html_safe %>
|
||||
<% else %>
|
||||
<%= post.cooked.html_safe %>
|
||||
<div class='post' itemprop='articleBody'>
|
||||
<%= post.hidden ? t('flagging.user_must_edit').html_safe : post.cooked.html_safe %>
|
||||
</div>
|
||||
<meta itemprop='interactionCount' content='UserLikes:<%= post.like_count %>'>
|
||||
<meta itemprop='interactionCount' content='UserComments:<%= post.reply_count %>'>
|
||||
<hr>
|
||||
<% end %>
|
||||
</div>
|
||||
<hr/>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<p>
|
||||
<% if @topic_view.prev_page || @topic_view.next_page %>
|
||||
<div role='navigation' itemscope itemtype='http://schema.org/SiteNavigationElement'>
|
||||
<% if @topic_view.prev_page %>
|
||||
<%= link_to t(:prev_page), @topic_view.prev_page_path, rel: 'prev' %>
|
||||
<span itemprop='url'><%= link_to t(:prev_page), @topic_view.prev_page_path, rel: 'prev', itemprop: 'name' %></span>
|
||||
<% end %>
|
||||
<% if @topic_view.next_page %>
|
||||
<b><%= link_to t(:next_page), @topic_view.next_page_path, rel: 'next' %></b>
|
||||
<span itemprop='url'><b><%= link_to t(:next_page), @topic_view.next_page_path, rel: 'next', itemprop: 'name' %></b></span>
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% content_for :head do %>
|
||||
<%= auto_discovery_link_tag(@topic_view, {action: :feed, slug: @topic_view.topic.slug, topic_id: @topic_view.topic.id}, title: t('rss_posts_in_topic', topic: @topic_view.title), type: 'application/rss+xml') %>
|
||||
|
|
|
@ -160,6 +160,7 @@ en:
|
|||
next_page: "next page →"
|
||||
prev_page: "← previous page"
|
||||
page_num: "Page %{num}"
|
||||
home_title: "Home"
|
||||
topics_in_category: "Topics in the '%{category}' category"
|
||||
rss_posts_in_topic: "RSS feed of '%{topic}'"
|
||||
rss_topics_in_category: "RSS feed of topics in the '%{category}' category"
|
||||
|
|
|
@ -224,9 +224,9 @@ Discourse::Application.routes.draw do
|
|||
get "login" => "static#show", id: "login"
|
||||
get "password-reset" => "static#show", id: "password_reset"
|
||||
get "faq" => "static#show", id: "faq"
|
||||
get "guidelines" => "static#show", id: "guidelines"
|
||||
get "tos" => "static#show", id: "tos"
|
||||
get "privacy" => "static#show", id: "privacy"
|
||||
get "guidelines" => "static#show", id: "guidelines", as: 'guidelines'
|
||||
get "tos" => "static#show", id: "tos", as: 'tos'
|
||||
get "privacy" => "static#show", id: "privacy", as: 'privacy'
|
||||
get "signup" => "list#latest"
|
||||
|
||||
post "users/read-faq" => "users#read_faq"
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module CrawlerDetection
|
||||
# added 'ia_archiver' based on https://meta.discourse.org/t/unable-to-archive-discourse-pages-with-the-internet-archive/21232
|
||||
# added 'Wayback Save Page' based on https://meta.discourse.org/t/unable-to-archive-discourse-with-the-internet-archive-save-page-now-button/22875
|
||||
|
||||
def self.crawler?(user_agent)
|
||||
!/Googlebot|Mediapartners|AdsBot|curl|Twitterbot|facebookexternalhit|bingbot|Baiduspider|ia_archiver|Wayback Save Page/.match(user_agent).nil?
|
||||
!/Googlebot|Mediapartners|AdsBot|curl|Twitterbot|facebookexternalhit|bingbot|Baiduspider|ia_archiver|Wayback Save Page|360Spider/.match(user_agent).nil?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue