forked from e621ng/e621ng
add dynamic sitemap.xml
This commit is contained in:
parent
1a4949368c
commit
6ca9b65716
@ -17,5 +17,11 @@ class StaticController < ApplicationController
|
||||
|
||||
def site_map
|
||||
end
|
||||
|
||||
|
||||
def sitemap
|
||||
@popular_search_service = PopularSearchService.new(Date.today)
|
||||
@post_set = PostSets::Popular.new(Date.today.to_s, "week", limit: 100)
|
||||
@posts = @post_set.posts
|
||||
render layout: false
|
||||
end
|
||||
end
|
||||
|
@ -1,10 +1,11 @@
|
||||
module PostSets
|
||||
class Popular < PostSets::Base
|
||||
attr_reader :date, :scale
|
||||
attr_reader :date, :scale, :limit
|
||||
|
||||
def initialize(date, scale)
|
||||
def initialize(date, scale, limit: nil)
|
||||
@date = date.blank? ? Time.zone.now : Time.zone.parse(date)
|
||||
@scale = scale
|
||||
@limit = limit || CurrentUser.per_page
|
||||
end
|
||||
|
||||
def posts
|
||||
@ -15,10 +16,6 @@ module PostSets
|
||||
end
|
||||
end
|
||||
|
||||
def limit
|
||||
CurrentUser.user.per_page
|
||||
end
|
||||
|
||||
def min_date
|
||||
case scale
|
||||
when "week"
|
||||
|
41
app/views/static/sitemap.xml.erb
Normal file
41
app/views/static/sitemap.xml.erb
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
||||
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
|
||||
<url>
|
||||
<loc><%= posts_url %></loc>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc><%= wiki_pages_url %></loc>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc><%= pools_url %></loc>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<%# cache("sitemap", :expires_in => 24.hours) do %>
|
||||
<% @popular_search_service.each_search do |tags, count| %>
|
||||
<url>
|
||||
<loc><%= posts_url(tags: tags) %></loc>
|
||||
<lastmod><%= Date.today %></lastmod>
|
||||
</url>
|
||||
<% end %>
|
||||
|
||||
<% @posts.each do |post| %>
|
||||
<url>
|
||||
<loc><%= post_url(post) %></loc>
|
||||
<image:image>
|
||||
<image:loc>
|
||||
<%= post.file_url %>
|
||||
</image:loc>
|
||||
<image:caption>
|
||||
<%= post.presenter.humanized_essential_tag_string %>
|
||||
</image:caption>
|
||||
</image:image>
|
||||
<lastmod><%= post.created_at.to_date %></lastmod>
|
||||
</url>
|
||||
<% end %>
|
||||
<%# end %>
|
||||
</urlset>
|
@ -421,6 +421,7 @@ Rails.application.routes.draw do
|
||||
get "/wiki/recent_changes" => redirect {|params, req| "/wiki_page_versions?search[updater_id]=#{req.params[:user_id]}"}
|
||||
get "/wiki/history/:title" => redirect("/wiki_page_versions?title=%{title}")
|
||||
|
||||
get "/sitemap" => "static#sitemap"
|
||||
get "/static/keyboard_shortcuts" => "static#keyboard_shortcuts", :as => "keyboard_shortcuts"
|
||||
get "/static/bookmarklet" => "static#bookmarklet", :as => "bookmarklet"
|
||||
get "/static/site_map" => "static#site_map", :as => "site_map"
|
||||
|
@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>http://danbooru.donmai.us/posts</loc>
|
||||
<changefreq>hourly</changefreq>
|
||||
<priority>1.0</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://danbooru.donmai.us/posts?tags=kantai_collection</loc>
|
||||
<changefreq>hourly</changefreq>
|
||||
<priority>0.7</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://danbooru.donmai.us/posts?tags=touhou</loc>
|
||||
<changefreq>hourly</changefreq>
|
||||
<priority>0.7</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://danbooru.donmai.us/posts?tags=kemono_friends</loc>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>0.3</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://danbooru.donmai.us/posts?tags=fate%2fgrand_order</loc>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>0.3</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://danbooru.donmai.us/posts?tags=pokemon</loc>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>0.3</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://danbooru.donmai.us/posts?tags=overwatch</loc>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>0.3</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://danbooru.donmai.us/wiki_pages</loc>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>0.3</priority>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://danbooru.donmai.us/pools</loc>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>0.5</priority>
|
||||
</url>
|
||||
</urlset>
|
Loading…
Reference in New Issue
Block a user