File: google-sitemaps.rb

package info (click to toggle)
hiki 0.8.6-1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 1,772 kB
  • ctags: 1,746
  • sloc: ruby: 20,067; lisp: 926; sh: 269; makefile: 10
file content (45 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
44
45
# $Id: google-sitemaps.rb,v 1.1 2005/06/09 13:17:40 yanagita Exp $
# Copyright (C) 2003-2004 TAKEUCHI Hitoshi <hitoshi@namaraii.com>
# Copyright (C) 2005 Kazuhiko <kazuhiko@fdiary.net>
# Copyright (C) 2005 Kouhei Yanagita <sugi@dream.big.or.jp>

def google_sitemaps_body
  sitemaps = %Q!<?xml version="1.0" encoding="UTF-8"?>\n!
  sitemaps << %Q!<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">\n!
  site_last_modified = nil
  @db.page_info.each do |page|
    name = page.keys[0]
    lastmod = page.values[0][:last_modified]
    if site_last_modified.nil? or site_last_modified < lastmod
      site_last_modified = lastmod
    end
    sitemaps << <<_E
  <url>
    <loc>#{@conf.index_url}?#{name.escape}</loc>
    <lastmod>#{lastmod.utc.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</lastmod>
  </url>
_E
  end

  sitemaps << '</urlset>'
  [sitemaps, site_last_modified]
end

def google_sitemaps
  body, last_modified = google_sitemaps_body
  header = Hash::new
  header['Last-Modified'] = CGI::rfc1123_date(last_modified)
  header['type']          = 'text/xml'
  header['charset']       =  'UTF-8'
  header['Content-Language'] = @conf.lang
  header['Pragma']           = 'no-cache'
  header['Cache-Control']    = 'no-cache'
  print @cgi.header(header)
  puts body

  nil # Don't move to the 'FrontPage'
end

add_body_enter_proc(Proc.new do
  add_plugin_command('google_sitemaps', nil)
end)