Class: SeoController
- Inherits:
-
Eksa::Controller
- Object
- Eksa::Controller
- SeoController
- Defined in:
- app/controllers/seo_controller.rb
Instance Attribute Summary
Attributes inherited from Eksa::Controller
#flash, #redirect_url, #request, #status
Instance Method Summary collapse
Methods inherited from Eksa::Controller
#asset_path, #current_user, #initialize, #javascript_tag, #params, #redirect_to, #render, #render_internal, #require_auth, #session, #stylesheet_tag
Constructor Details
This class inherits a constructor from Eksa::Controller
Instance Method Details
#robots ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/seo_controller.rb', line 2 def robots scheme = request.env['rack.url_scheme'] || 'https' content = <<~TEXT User-agent: * Allow: / Disallow: /hapus Disallow: /edit Sitemap: #{scheme}://#{request.host}/sitemap.xml TEXT [200, { "Content-Type" => "text/plain" }, [content]] end |
#sitemap ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/seo_controller.rb', line 15 def sitemap scheme = request.env['rack.url_scheme'] || 'https' base_url = "#{scheme}://#{request.host}" lastmod = Time.now.strftime("%Y-%m-%d") xml = '<?xml version="1.0" encoding="UTF-8"?>' xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' # Base Pages ["/", "/about", "/docs", "/kontak", "/posts"].each do |path| xml += "<url>" xml += "<loc>#{base_url}#{path}</loc>" xml += "<lastmod>#{lastmod}</lastmod>" xml += "<priority>#{path == '/' ? '1.0' : '0.8'}</priority>" xml += "</url>" end # Blog Posts Eksa::MarkdownPost.all.each do |post| xml += "<url>" xml += "<loc>#{base_url}/posts/#{post.slug}</loc>" xml += "<lastmod>#{post.date.is_a?(Time) ? post.date.strftime("%Y-%m-%d") : lastmod}</lastmod>" xml += "<priority>0.6</priority>" xml += "</url>" end xml += '</urlset>' [200, { "Content-Type" => "application/xml" }, [xml]] end |