seo: update JSON-LD site metadata.

* Add the Danbooru logo and social media links to the Organization data.
  This is to make Danbooru eligible for Google's knowledge panel ([1], [2]).
* Only include this metadata on the frontpage as per Google's recommendations ([3]).

[1]: https://support.google.com/knowledgepanel/answer/9163198
[2], https://developers.google.com/search/docs/data-types/logo
[3]: https://developers.google.com/search/docs/data-types/sitelinks-searchbox
This commit is contained in:
evazion
2020-07-03 16:04:13 -05:00
parent a0ee4c67a8
commit b6b0218e1d
5 changed files with 67 additions and 36 deletions

56
app/helpers/seo_helper.rb Normal file
View File

@@ -0,0 +1,56 @@
# https://yoast.com/structured-data-schema-ultimate-guide/
# https://technicalseo.com/tools/schema-markup-generator/
# https://developers.google.com/search/docs/data-types/sitelinks-searchbox
# https://developers.google.com/search/docs/data-types/logo
# https://search.google.com/structured-data/testing-tool/u/0/
# https://search.google.com/test/rich-results
# https://schema.org/Organization
# https://schema.org/WebSite
module SeoHelper
def site_description
"#{Danbooru.config.canonical_app_name} is the original anime image booru. Search millions of anime pictures categorized by thousands of tags."
end
def json_ld_website_data
urls = [
Danbooru.config.twitter_url,
Danbooru.config.discord_server_url,
Danbooru.config.source_code_url,
"https://en.wikipedia.org/wiki/Danbooru"
].compact
json_ld_tag({
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": root_url(anchor: "organization", host: Danbooru.config.hostname),
url: root_url(host: Danbooru.config.hostname),
name: Danbooru.config.app_name,
logo: "#{root_url(host: Danbooru.config.hostname)}images/danbooru-logo-500x500.png",
sameAs: urls
},
{
"@type": "WebSite",
"@id": root_url(anchor: "website", host: Danbooru.config.hostname),
"url": root_url(host: Danbooru.config.hostname),
"name": Danbooru.config.app_name,
"description": site_description,
"publisher": {
"@id": root_url(anchor: "organization", host: Danbooru.config.hostname),
},
"potentialAction": [{
"@type": "SearchAction",
"target": "#{posts_url(host: Danbooru.config.hostname)}?tags={search_term_string}",
"query-input": "required name=search_term_string"
}]
}
]
})
end
def json_ld_tag(data)
tag.script(data.to_json.html_safe, type: "application/ld+json")
end
end

View File

@@ -19,42 +19,12 @@
<% if CurrentUser.user.custom_style.present? && params.fetch(:css, "true").truthy? %>
<%= stylesheet_link_tag custom_style_users_path(md5: Digest::MD5.hexdigest(CurrentUser.user.custom_style)), media: "screen" %>
<% end %>
<% if Danbooru.config.twitter_username.present? %>
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Organization",
"name" : "<%= Danbooru.config.app_name %>",
"url" : "<%= root_url %>",
"sameAs" : [
"https://twitter.com/<%= Danbooru.config.twitter_username %>"
]
}
</script>
<% end %>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"url" : "<%= root_url %>",
"potentialAction": [{
"@type": "SearchAction",
"target": "<%= posts_url %>?tags={search_term_string}",
"query-input": "required name=search_term_string"
}]
}
</script>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "<%= Danbooru.config.app_name %>",
"alternateName": "Anime Image Board",
"url" : "<%= root_url %>"
}
</script>
<%= tag.meta name: "description", content: meta_description %>
<% if current_page?(root_url) %>
<%= json_ld_website_data %>
<% end %>
<%= tag.meta name: "description", content: meta_description %>
<%= tag.meta property: "og:type", content: "website" %>
<%= tag.meta property: "og:site_name", content: Danbooru.config.app_name %>
<%= tag.meta property: "og:title", content: page_title %>

View File

@@ -1,6 +1,6 @@
<% if @post_set.query.is_empty_search? %>
<% page_title("#{Danbooru.config.app_name}: Anime Image Board", suffix: nil) %>
<% meta_description("#{Danbooru.config.canonical_app_name} is the original anime image 'booru. Find over 3.75 million anime pictures categorized by over 100 million tags.") %>
<% meta_description site_description %>
<% atom_feed_tag "Posts", posts_url(format: :atom) %>
<% else %>

View File

@@ -355,6 +355,11 @@ module Danbooru
nil
end
def twitter_url
return nil unless Danbooru.config.twitter_username.present?
"https://twitter.com/#{Danbooru.config.twitter_username}"
end
# include essential tags in image urls (requires nginx/apache rewrites)
def enable_seo_post_urls
false

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB