From c955907f605f8cdbcb6dbd1a5c376d226870fb0d Mon Sep 17 00:00:00 2001 From: Erick Guan Date: Fri, 13 Feb 2015 19:34:22 +0800 Subject: [PATCH] FEATURE: add microdata prop and more links for crawler - add microdata based on schema.org - add breadcrumb on the top of topic - add navigations link on the bottom of every pages - add category description on the category list --- app/controllers/list_controller.rb | 26 ++++----- app/helpers/topics_helper.rb | 14 +++++ app/views/categories/index.html.erb | 34 ++++++++---- app/views/layouts/application.html.erb | 10 ++++ app/views/layouts/crawler.html.erb | 7 +++ app/views/list/list.erb | 33 +++++++----- app/views/static/show.html.erb | 34 ++++++------ app/views/topics/show.html.erb | 74 +++++++++++++++----------- config/locales/server.en.yml | 1 + config/routes.rb | 6 +-- 10 files changed, 152 insertions(+), 87 deletions(-) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index 55bdac73f..2345e6f2e 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -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 @@ -121,8 +121,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 @@ -166,8 +166,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") @@ -279,14 +279,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" - 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 = if action == :prev + public_send(method, opts.merge(prev_page_params(opts))) + else # :next + public_send(method, opts.merge(next_page_params(opts))) + end + url.sub('.json?','?') end def generate_top_lists(options) diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb index 8ad809ef6..cb330dcf2 100644 --- a/app/helpers/topics_helper.rb +++ b/app/helpers/topics_helper.rb @@ -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 diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index 2b189514a..3ffbc4c59 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -1,14 +1,26 @@ -<% @list.categories.each do |c| %> -
-

"><%= c.name %>

-
- <%- if c.displayable_topics.present? %> - <% c.displayable_topics.each do |t| %> - <%= t.title %> '>(<%= t.posts_count %>)
- <% end %> - <%- end %> +
+ + <% @list.categories.each do |c| %> +
+ +

+ <%= c.name %> +

+ <%= c.description %> +
+ <%- if c.displayable_topics.present? %> + <% c.displayable_topics.each do |t| %> +
+ + + <%= t.title %> + '>(<%= t.posts_count %>) +
+ <% end %> + <%- end %> +
-
-<% end %> + <% end %> +
<% content_for :title do %><%= I18n.t('js.filters.categories.title') %><% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index baf1f7cbd..058891187 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -42,7 +42,17 @@ <%= yield %> +
+ +
+ diff --git a/app/views/layouts/crawler.html.erb b/app/views/layouts/crawler.html.erb index c4d7dc14d..3a448be19 100644 --- a/app/views/layouts/crawler.html.erb +++ b/app/views/layouts/crawler.html.erb @@ -25,6 +25,13 @@ <%= yield %> <%= render_google_analytics_code %> diff --git a/app/views/list/list.erb b/app/views/list/list.erb index 966c863f5..c6ff86bb0 100644 --- a/app/views/list/list.erb +++ b/app/views/list/list.erb @@ -1,21 +1,26 @@ -
-<% @list.topics.each do |t| %> - <%= t.title %> - <% if !@category && t.category %> - [<%= t.category.name %>] +
+ + <% @list.topics.each_with_index do |t,i| %> +
+ + + <%= t.title %> + + <% if !@category && t.category %> + [<%= t.category.name %>] + <% end %> + '>(<%= t.posts_count %>) +
<% end %> - '>(<%= t.posts_count %>)
-<% end %>
- <% if @list.topics.length > 0 && @list.more_topics_url %> -

- <% if params[:page].to_i > 0 %> -   - <% end %> - -

+
+ <% if params[:page].to_i > 0 %> + + <% end %> + +
<% end %> <% if @rss %> diff --git a/app/views/static/show.html.erb b/app/views/static/show.html.erb index e6aa2892e..2f73233a0 100644 --- a/app/views/static/show.html.erb +++ b/app/views/static/show.html.erb @@ -1,20 +1,24 @@ - -<% if staff? %> -

<%=t "edit_this_page" -%>

-<% end %> - -<%= @body.html_safe %> +
+ <%= @body.html_safe %> +
+
<% if @title %> <% content_for :title do %><%= @title %><% end %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index 846bdc38c..11b16051f 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -1,40 +1,52 @@

- <%= render_topic_title(@topic_view.topic) %> + <%= render_topic_title(@topic_view.topic) %>

-<% if c = @topic_view.topic.category %> - <%= link_to c.name, c.url %> -<% end %> -
+ +
+ <% categories_breadcrumb(@topic_view.topic).each_with_index do |c,i| %> + + <%= link_to c[:url], itemprop: 'item' do %> + <%= c[:name] %> + <% end %> + + + <% end %> +
+
<% @topic_view.posts.each do |post| %> - <% if post.user %> -
- <%= post.user.username %> - <%= "(#{post.user.name})" if (SiteSetting.display_name_on_posts && SiteSetting.enable_names?) %> — - <%= post.created_at.to_formatted_s(:iso8601) %> — - #<%= post.post_number %> -
-
- <% if post.hidden %> - <%= t('flagging.user_must_edit').html_safe %> - <% else %> - <%= post.cooked.html_safe %> - <% end %> -
-
- <% end %> +
+ <% if (u = post.user) %> +
+ + + <%= "(#{u.name})" if (SiteSetting.display_name_on_posts && SiteSetting.enable_names? && !u.name.blank?) %> + + + #<%= post.post_number %> +
+
+ <%= post.hidden ? t('flagging.user_must_edit').html_safe : post.cooked.html_safe %> +
+ + +
+ <% end %> +
<% end %> - -

- <% if @topic_view.prev_page %> - <%= link_to t(:prev_page), @topic_view.prev_page_path, rel: 'prev' %> - <% end %> - <% if @topic_view.next_page %> - <%= link_to t(:next_page), @topic_view.next_page_path, rel: 'next' %> - <% end %> -

- +<% if @topic_view.prev_page || @topic_view.next_page %> +
+ <% if @topic_view.prev_page %> + + <% end %> + <% if @topic_view.next_page %> + + <% end %> +
+<% 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') %> diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 4dae96ad8..43ef4207d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -159,6 +159,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" diff --git a/config/routes.rb b/config/routes.rb index 427a31960..512935553 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -221,9 +221,9 @@ Discourse::Application.routes.draw do post "login" => "static#enter" get "login" => "static#show", id: "login" 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"