toto icon indicating copy to clipboard operation
toto copied to clipboard

Sitemap?

Open doxavore opened this issue 14 years ago • 12 comments

Is anyone working on a sitemap implementation for Toto? If not, any pointers on extensibility points one might leverage?

doxavore avatar Sep 08 '10 03:09 doxavore

For anyone else that may be confused by this, adding a templates/sitemap.builder file isn't enough - you also need to add a templates/pages/sitemap.rhtml. Once you have BOTH, you can access /sitemap (for HTML version) and /sitemap.xml.

This could probably be documented somewhere if it's intended behavior.

doxavore avatar Sep 08 '10 04:09 doxavore

This is not intended behaviour. I've made a fix, you can pull it from http://github.com/cloudhead/toto/pull/58

ariejan avatar Sep 17 '10 07:09 ariejan

http://artemk.name/2011/06/01/sitemap-in-toto/

artemk avatar Jun 06 '11 10:06 artemk

I believe it's better to have this feature (I like the code of artemk) in Rakefile of dorothy.

ixti avatar Aug 08 '11 13:08 ixti

i think this is not supported any more. If you need sitemap, just add this by hands.

artemk avatar Aug 08 '11 16:08 artemk

I tried manually adding a sitemap.xml in the public folder; but toto returns a 404. How can I have this page accessible?

benjamincharity avatar Oct 31 '11 22:10 benjamincharity

@benjamincharity add it to the list of files served by Rack::Static. Replace this block in your config.ru file:

# Rack config
use Rack::Static, {
  :urls => %w{/css /js /i /favicon.ico /fonts /robots.txt /humans.txt},
  :root => 'public'
}

with

# Rack config
use Rack::Static, {
  :urls => %w{/css /js /i /favicon.ico /fonts /robots.txt /humans.txt /sitemap.xml},
  :root => 'public'
}

ixti avatar Oct 31 '11 22:10 ixti

Oh my gosh. I can't believe I forgot that.

Definitely time to get some sleep.

Thanks!

benjamincharity avatar Oct 31 '11 22:10 benjamincharity

Sitemap generation for toto is in fact as easy as simple Rake task:

BLOG_URL = "http://blog.ixti.net/"

desc "Rebuild sitemap"
task :sitemap do
  xml = Builder::XmlMarkup.new(:indent => 2)
  xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do
    xml.url do
      xml.loc BLOG_URL
      xml.lastmod "2005-01-01"
      xml.changefreq "weekly"
      xml.priority 0.8
    end

    archived = Time.new - (365 * 24 * 60 * 60)

    Toto::Site.new(Toto::Config::Defaults).archives.delete(:archives).each do |article|
      d, m, y = article.date.split "/"
      xml.url do
        xml.loc "#{BLOG_URL}#{article.path.slice(1..-1)}"
        xml.lastmod "#{y}-#{m}-#{d}"
        xml.changefreq (Time.new(y, m, d) < archived) ? "never" : "monthly"
      end
    end
  end

  File.open "sitemap.xml", "w+" do |f|
    f.puts xml.target!
  end
end

Here's live example: https://github.com/ixti/blog/blob/master/Rakefile

ixti avatar Dec 12 '11 20:12 ixti

Hmm I run that and it only returns the index page:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://benjamincharity.com/</loc>
    <lastmod>2005-01-01</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>

The sitemap portion of my rakefile looks like this:

BLOG_URL = "http://benjamincharity.com/"

desc "Rebuild sitemap"
task :sitemap do
  xml = Builder::XmlMarkup.new(:indent => 2)
  xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do
    xml.url do
      xml.loc BLOG_URL
      xml.lastmod "2005-01-01"
      xml.changefreq "weekly"
      xml.priority 0.8
    end

    archived = Time.new - (365 * 24 * 60 * 60)

    Toto::Site.new(Toto::Config::Defaults).archives.delete(:archives).each do |article|
      d, m, y = article.date.split "/"
      xml.url do
        xml.loc "#{BLOG_URL}#{article.path.slice(1..-1)}"
        xml.lastmod "#{y}-#{m}-#{d}"
        xml.changefreq (Time.new(y, m, d) < archived) ? "never" : "monthly"
      end
    end
  end

  File.open "public/sitemap.xml", "w+" do |f|
    f.puts xml.target!
  end
end

benjamincharity avatar Dec 14 '11 15:12 benjamincharity

Hm... Probably my branch of toto works with archives a little bit different way. Will recheck and let you know possible fi for your blog.

ixti avatar Dec 14 '11 16:12 ixti

First of all i have a small typos in my Rakefile :)) So you can resync with latest version of it :)) But the problem was not with rake task. You have custom extension of files markdown, so in order to make it work work you need something like this:

config = Toto::Config::Defaults
config[:ext] = 'markdown'

Toto::Site.new(config).archives.delete(:archives).each do |article|
  # ...
end

Or, if you'll reuse my latest version, just alter something right over 6th line:

$config = Toto::Config::Defaults
$config[:ext] = 'markdown'
$editor = ENV['EDITOR'] || ""

ixti avatar Dec 15 '11 00:12 ixti