add additional meta tags for seo

This commit is contained in:
r888888888
2018-10-20 17:15:29 -07:00
parent c301c316bf
commit 192ac128cd
7 changed files with 121 additions and 30 deletions

View File

@@ -22,6 +22,8 @@ module Downloads
end
def is_cloudflare?
return false if ENV["SKIP_CLOUDFLARE_CHECK"]
Cache.get("is_cloudflare:#{file_url.origin}", 4.hours) do
res = HTTParty.head(file_url, httparty_options)
raise Error.new("HTTP error code: #{res.code} #{res.message}") unless res.success?

View File

@@ -36,6 +36,10 @@ module PostSets
false
end
def best_post
nil
end
def presenter
raise NotImplementedError
end

View File

@@ -26,7 +26,7 @@ module PostSets
end
def has_wiki?
is_single_tag? && ::WikiPage.titled(tag_string).exists? && wiki_page.visible?
is_single_tag? && ::WikiPage.titled(tag_string).exists? && wiki_page.visible? && wiki_page.body.present?
end
def has_blank_wiki?
@@ -184,5 +184,10 @@ module PostSets
def presenter
@presenter ||= ::PostSetPresenters::Post.new(self)
end
def best_post
# be smarter about this in the future
posts[0]
end
end
end

View File

@@ -65,22 +65,12 @@
<% end %>
<%= content_for(:html_header) do %>
<link href="<%= posts_path(:format => 'atom', :tags => params[:tags]) %>" rel="alternate" title="ATOM" type="application/atom+xml" />
<%#= tag.link rel: "prefetch", href: next_page_url, as: "html", crossorigin: "use-credentials" %>
<%= tag.link href: posts_path(format: "atom", tags: params[:tags]), rel: "alternate", title: "ATOM", type: "application/atom+xml" %>
<%= tag.link rel: "prefetch", href: next_page_url, as: "html", crossorigin: "use-credentials" %>
<%= tag.link rel: "next", href: next_page_url %>
<% if prev_page_url %>
<%= tag.link rel: "prev", href: prev_page_url %>
<% end %>
<% if @post_set.has_wiki? %>
<meta name="description" content="<%= strip_dtext(@post_set.wiki_page.presenter.excerpt) %>">
<% else %>
<meta name="description" content="<%= Danbooru.config.description %>">
<% end %>
<%= missed_post_search_count_js %>
<% if @post_set.hide_from_crawler? %>
<meta name="robots" content="nofollow,noindex">
<% end %>
<% if @post_set.has_explicit? %>
<meta name="rating" content="adult">
<% end %>
<%= render "posts/partials/index/seo_meta_tags" %>
<% end %>

View File

@@ -0,0 +1,49 @@
<% if @post_set.has_wiki? %>
<% strip_dtext(@post_set.wiki_page.presenter.excerpt).tap do |title| %>
<%= tag.meta name: "og:title", content: title %>
<%= tag.meta name: "twitter:title", content: title %>
<% end %>
<% elsif @post_set.tag_string.present? %>
<% "#{@post_set.humanized_tag_string} - #{Danbooru.config.app_name}".tap do |title| %>
<%= tag.meta name: "og:title", content: title %>
<%= tag.meta name: "twitter:title", content: title %>
<% end %>
<% else %>
<% Danbooru.config.description.tap do |title| %>
<%= tag.meta name: "og:title", content: title %>
<%= tag.meta name: "twitter:title", content: title %>
<% end %>
<% end %>
<% if @post_set.hide_from_crawler? %>
<meta name="robots" content="nofollow,noindex">
<% end %>
<% if @post_set.has_explicit? %>
<meta name="rating" content="adult">
<% end %>
<%= tag.meta name: "canonical", content: posts_url(tags: params[:tags], host: Danbooru.config.domain) %>
<% if params[:tags].present? %>
<% "Find the best art of #{params[:tags].tr('_', ' ').titleize} on #{Danbooru.config.app_name}".tap do |desc| %>
<%= tag.meta name: "description", content: desc %>
<%= tag.meta name: "og:description", content: desc %>
<%= tag.meta name: "twitter:description", content: desc %>
<% end %>
<% else %>
<% Danbooru.config.description.tap do |desc| %>
<%= tag.meta name: "description", content: desc %>
<%= tag.meta name: "og:description", content: desc %>
<%= tag.meta name: "twitter:description", content: desc %>
<% end %>
<% end %>
<%= tag.meta name: "og:type", content: "website" %>
<%= tag.meta name: "og:site", content: Danbooru.config.app_name %>
<% if @post_set.best_post.present? %>
<%= tag.meta name: "twitter:image", content: @post_set.best_post.file_url %>
<%= tag.meta name: "og:image", content: @post_set.best_post.file_url %>
<%= tag.meta name: "twitter:card", content: "summary_large_image" %>
<% end %>