From 947a09583b25140ee386229f11c82a0984be2451 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 23 Dec 2015 13:55:15 -0500 Subject: Add Open Graph meta tags --- app/views/layouts/_head.html.haml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index 74174a72f5a..be88ad9e2a6 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -1,10 +1,14 @@ - page_title "GitLab" -%head +%head{prefix: "og: http://ogp.me/ns#"} %meta{charset: "utf-8"} %meta{'http-equiv' => 'X-UA-Compatible', content: 'IE=edge'} %meta{content: "GitLab Community Edition", name: "description"} %meta{name: 'referrer', content: 'origin-when-cross-origin'} + -# Open Graph - http://ogp.me/ + %meta{property: 'og:title', content: page_title} + %meta{property: 'og:url', content: url_for(only_path: false)} + %title= page_title = favicon_link_tag 'favicon.ico' -- cgit v1.2.1 From 3f452f539b909d1a379a4f3c5d48307246a14fff Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 23 Dec 2015 16:45:37 -0500 Subject: Add gitlab_logo.png, remove brand_logo.png --- app/assets/images/brand_logo.png | Bin 27059 -> 0 bytes app/assets/images/gitlab_logo.png | Bin 0 -> 5189 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/assets/images/brand_logo.png create mode 100644 app/assets/images/gitlab_logo.png (limited to 'app') diff --git a/app/assets/images/brand_logo.png b/app/assets/images/brand_logo.png deleted file mode 100644 index 9c564bb6141..00000000000 Binary files a/app/assets/images/brand_logo.png and /dev/null differ diff --git a/app/assets/images/gitlab_logo.png b/app/assets/images/gitlab_logo.png new file mode 100644 index 00000000000..0c157546b9c Binary files /dev/null and b/app/assets/images/gitlab_logo.png differ -- cgit v1.2.1 From b26eb782f5536d8c383aebe3d65571fb16a20bcd Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 23 Dec 2015 16:56:27 -0500 Subject: Add page descriptions and images A limited number of pages have defined their own descriptions, but otherwise we default to the Project's description (if `@project` is set), or the old `brand_title` fallback. The image will either be the uploaded project icon (never a generated one), the user's uploaded icon or Gravatar, or, finally, the GitLab logo. --- app/helpers/page_layout_helper.rb | 50 +++++++++++++++++++++++ app/views/layouts/_head.html.haml | 12 ++++-- app/views/projects/issues/show.html.haml | 4 +- app/views/projects/merge_requests/_show.html.haml | 4 +- app/views/projects/milestones/show.html.haml | 4 +- app/views/users/show.html.haml | 5 ++- 6 files changed, 70 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb index 9bf750124b2..6b16528dde6 100644 --- a/app/helpers/page_layout_helper.rb +++ b/app/helpers/page_layout_helper.rb @@ -8,6 +8,56 @@ module PageLayoutHelper @page_title.join(" \u00b7 ") end + # Define or get a description for the current page + # + # description - String (default: nil) + # + # If this helper is called multiple times with an argument, only the last + # description will be returned when called without an argument. Descriptions + # have newlines replaced with spaces and all HTML tags are sanitized. + # + # Examples: + # + # page_description # => "GitLab Community Edition" + # page_description("Foo") + # page_description # => "Foo" + # + # page_description("Bar\nBaz") + # page_description # => "Bar Baz" + # + # Returns an HTML-safe String. + def page_description(description = nil) + @page_description ||= page_description_default + + if description.present? + @page_description = description + else + sanitize(@page_description.squish, tags: []) + end + end + + # Default value for page_description when one hasn't been defined manually by + # a view + def page_description_default + if @project + @project.description + else + brand_title + end + end + + def page_image + default = image_url('gitlab_logo.png') + + if @project + @project.avatar_url || default + elsif @user + avatar_icon(@user) + else + default + end + end + def header_title(title = nil, title_url = nil) if title @header_title = title diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index be88ad9e2a6..ad1dacac1c8 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -1,13 +1,17 @@ - page_title "GitLab" + %head{prefix: "og: http://ogp.me/ns#"} %meta{charset: "utf-8"} %meta{'http-equiv' => 'X-UA-Compatible', content: 'IE=edge'} - %meta{content: "GitLab Community Edition", name: "description"} - %meta{name: 'referrer', content: 'origin-when-cross-origin'} + + %meta{name: "description", content: page_description} + %meta{name: 'referrer', content: 'origin-when-cross-origin'} -# Open Graph - http://ogp.me/ - %meta{property: 'og:title', content: page_title} - %meta{property: 'og:url', content: url_for(only_path: false)} + %meta{property: 'og:title', content: page_title} + %meta{property: 'og:description', content: page_description} + %meta{property: 'og:image', content: page_image} + %meta{property: 'og:url', content: url_for(only_path: false)} %title= page_title diff --git a/app/views/projects/issues/show.html.haml b/app/views/projects/issues/show.html.haml index b6efa05a1ae..f2a261ab426 100644 --- a/app/views/projects/issues/show.html.haml +++ b/app/views/projects/issues/show.html.haml @@ -1,4 +1,6 @@ -- page_title "#{@issue.title} (##{@issue.iid})", "Issues" +- page_title "#{@issue.title} (##{@issue.iid})", "Issues" +- page_description @issue.description + = render "header_title" .issue diff --git a/app/views/projects/merge_requests/_show.html.haml b/app/views/projects/merge_requests/_show.html.haml index e9ffbd06be2..75f44557964 100644 --- a/app/views/projects/merge_requests/_show.html.haml +++ b/app/views/projects/merge_requests/_show.html.haml @@ -1,4 +1,6 @@ -- page_title "#{@merge_request.title} (##{@merge_request.iid})", "Merge Requests" +- page_title "#{@merge_request.title} (##{@merge_request.iid})", "Merge Requests" +- page_description @merge_request.description + = render "header_title" - if params[:view] == 'parallel' diff --git a/app/views/projects/milestones/show.html.haml b/app/views/projects/milestones/show.html.haml index 7e73ae274e9..1670ea8741a 100644 --- a/app/views/projects/milestones/show.html.haml +++ b/app/views/projects/milestones/show.html.haml @@ -1,4 +1,6 @@ -- page_title @milestone.title, "Milestones" +- page_title @milestone.title, "Milestones" +- page_description @milestone.description + = render "header_title" .detail-page-header diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index b7a7eb4e6f7..0bca8177e14 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,5 +1,6 @@ -- page_title @user.name -- header_title @user.name, user_path(@user) +- page_title @user.name +- page_description @user.bio +- header_title @user.name, user_path(@user) = content_for :meta_tags do = auto_discovery_link_tag(:atom, user_url(@user, format: :atom), title: "#{@user.name} activity") -- cgit v1.2.1 From 5a3b9c97e34ee69312ef9bcf575894a106c5a271 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 23 Dec 2015 17:14:18 -0500 Subject: Account for `@project.description` being nil --- app/helpers/page_layout_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb index 6b16528dde6..c4eb09bea2b 100644 --- a/app/helpers/page_layout_helper.rb +++ b/app/helpers/page_layout_helper.rb @@ -40,7 +40,7 @@ module PageLayoutHelper # a view def page_description_default if @project - @project.description + @project.description || brand_title else brand_title end -- cgit v1.2.1 From c6d25083626c9a97a0ae442298b59c2ff9351f3a Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 24 Dec 2015 16:26:52 -0500 Subject: Truncate page_description to 30 words --- app/helpers/page_layout_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb index c4eb09bea2b..4f1276f93ec 100644 --- a/app/helpers/page_layout_helper.rb +++ b/app/helpers/page_layout_helper.rb @@ -30,9 +30,9 @@ module PageLayoutHelper @page_description ||= page_description_default if description.present? - @page_description = description + @page_description = description.squish else - sanitize(@page_description.squish, tags: []) + sanitize(@page_description, tags: []).truncate_words(30) end end -- cgit v1.2.1 From 99dc1fce5ed84fb78bd993423db9c470021ea3a2 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 24 Dec 2015 16:53:35 -0500 Subject: Use `request.fullpath` for `og:url` tag --- app/views/layouts/_head.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index ad1dacac1c8..d1cb07eaa66 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -11,7 +11,7 @@ %meta{property: 'og:title', content: page_title} %meta{property: 'og:description', content: page_description} %meta{property: 'og:image', content: page_image} - %meta{property: 'og:url', content: url_for(only_path: false)} + %meta{property: 'og:url', content: request.base_url + request.fullpath} %title= page_title -- cgit v1.2.1 From ab3d855c0e1869fd1986c3bcdf7519f6b1cf1fa8 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 24 Dec 2015 17:03:54 -0500 Subject: Add support for `twitter:label` meta tags --- app/helpers/page_layout_helper.rb | 24 +++++++++++++++++++++++ app/models/concerns/issuable.rb | 8 ++++++++ app/views/layouts/_head.html.haml | 1 + app/views/projects/issues/show.html.haml | 5 +++-- app/views/projects/merge_requests/_show.html.haml | 5 +++-- 5 files changed, 39 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb index 4f1276f93ec..791cb9e50bd 100644 --- a/app/helpers/page_layout_helper.rb +++ b/app/helpers/page_layout_helper.rb @@ -58,6 +58,30 @@ module PageLayoutHelper end end + # Define or get attributes to be used as Twitter card metadata + # + # map - Hash of label => data pairs. Keys become labels, values become data + # + # Raises ArgumentError if given more than two attributes + def page_card_attributes(map = {}) + raise ArgumentError, 'cannot provide more than two attributes' if map.length > 2 + + @page_card_attributes ||= {} + @page_card_attributes = map.reject { |_,v| v.blank? } if map.present? + @page_card_attributes + end + + def page_card_meta_tags + tags = '' + + page_card_attributes.each_with_index do |pair, i| + tags << tag(:meta, property: "twitter:label#{i + 1}", content: pair[0]) + tags << tag(:meta, property: "twitter:data#{i + 1}", content: pair[1]) + end + + tags.html_safe + end + def header_title(title = nil, title_url = nil) if title @header_title = title diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index f56fd3e02d4..919833f6df5 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -161,6 +161,14 @@ module Issuable self.class.to_s.underscore end + # Returns a Hash of attributes to be used for Twitter card metadata + def card_attributes + { + 'Author' => author.try(:name), + 'Assignee' => assignee.try(:name) + } + end + def notes_with_associations notes.includes(:author, :project) end diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index d1cb07eaa66..434605e59ae 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -12,6 +12,7 @@ %meta{property: 'og:description', content: page_description} %meta{property: 'og:image', content: page_image} %meta{property: 'og:url', content: request.base_url + request.fullpath} + = page_card_meta_tags %title= page_title diff --git a/app/views/projects/issues/show.html.haml b/app/views/projects/issues/show.html.haml index f2a261ab426..f548383008d 100644 --- a/app/views/projects/issues/show.html.haml +++ b/app/views/projects/issues/show.html.haml @@ -1,5 +1,6 @@ -- page_title "#{@issue.title} (##{@issue.iid})", "Issues" -- page_description @issue.description +- page_title "#{@issue.title} (##{@issue.iid})", "Issues" +- page_description @issue.description +- page_card_attributes @issue.card_attributes = render "header_title" diff --git a/app/views/projects/merge_requests/_show.html.haml b/app/views/projects/merge_requests/_show.html.haml index 75f44557964..ba7c2c01e93 100644 --- a/app/views/projects/merge_requests/_show.html.haml +++ b/app/views/projects/merge_requests/_show.html.haml @@ -1,5 +1,6 @@ -- page_title "#{@merge_request.title} (##{@merge_request.iid})", "Merge Requests" -- page_description @merge_request.description +- page_title "#{@merge_request.title} (##{@merge_request.iid})", "Merge Requests" +- page_description @merge_request.description +- page_card_attributes @merge_request.card_attributes = render "header_title" -- cgit v1.2.1 From 4a2514ff0e1cf88786dcaf168b50af540568e79d Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 25 Dec 2015 13:27:43 +0100 Subject: Add og:site_name --- app/views/layouts/_head.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index 434605e59ae..2002f66af0e 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -1,5 +1,3 @@ -- page_title "GitLab" - %head{prefix: "og: http://ogp.me/ns#"} %meta{charset: "utf-8"} %meta{'http-equiv' => 'X-UA-Compatible', content: 'IE=edge'} @@ -8,12 +6,14 @@ %meta{name: 'referrer', content: 'origin-when-cross-origin'} -# Open Graph - http://ogp.me/ + %meta{property: 'og:site_name', content: "GitLab"} %meta{property: 'og:title', content: page_title} %meta{property: 'og:description', content: page_description} %meta{property: 'og:image', content: page_image} %meta{property: 'og:url', content: request.base_url + request.fullpath} = page_card_meta_tags + - page_title "GitLab" %title= page_title = favicon_link_tag 'favicon.ico' -- cgit v1.2.1 From 0980dda6cdab6dc35cfa9a8b7b7b67fcd73ea699 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 25 Dec 2015 13:35:57 +0100 Subject: Add more twitter metatags. --- app/views/layouts/_head.html.haml | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app') diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index 2002f66af0e..0be00da0b9e 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -6,11 +6,17 @@ %meta{name: 'referrer', content: 'origin-when-cross-origin'} -# Open Graph - http://ogp.me/ + %meta{property: 'og:type', content: "object"} %meta{property: 'og:site_name', content: "GitLab"} %meta{property: 'og:title', content: page_title} %meta{property: 'og:description', content: page_description} %meta{property: 'og:image', content: page_image} %meta{property: 'og:url', content: request.base_url + request.fullpath} + + %meta{property: 'twitter:card', content: "summary"} + %meta{property: 'twitter:title', content: page_title} + %meta{property: 'twitter:description', content: page_description} + %meta{property: 'twitter:image', content: page_image} = page_card_meta_tags - page_title "GitLab" -- cgit v1.2.1 From 6d385e3365ffa68a3e4ddb7bf332522cceaccaff Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 25 Dec 2015 13:38:54 +0100 Subject: Add link to twitter docs --- app/views/layouts/_head.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index 0be00da0b9e..2e0bd2007a3 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -1,9 +1,9 @@ %head{prefix: "og: http://ogp.me/ns#"} %meta{charset: "utf-8"} %meta{'http-equiv' => 'X-UA-Compatible', content: 'IE=edge'} + %meta{name: 'referrer', content: 'origin-when-cross-origin'} %meta{name: "description", content: page_description} - %meta{name: 'referrer', content: 'origin-when-cross-origin'} -# Open Graph - http://ogp.me/ %meta{property: 'og:type', content: "object"} @@ -13,6 +13,7 @@ %meta{property: 'og:image', content: page_image} %meta{property: 'og:url', content: request.base_url + request.fullpath} + -# Twitter Card - https://dev.twitter.com/cards/types/summary %meta{property: 'twitter:card', content: "summary"} %meta{property: 'twitter:title', content: page_title} %meta{property: 'twitter:description', content: page_description} -- cgit v1.2.1