liquid_feedback_frontend

diff app/main/sitemap/show.lua @ 164:49b0da970463

started sitemap.xml for better search engine index
author Daniel Poelzleithner <poelzi@poelzi.org>
date Sat Oct 09 20:34:23 2010 +0200 (2010-10-09)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/app/main/sitemap/show.lua	Sat Oct 09 20:34:23 2010 +0200
     1.3 @@ -0,0 +1,80 @@
     1.4 +slot.set_layout("xml", "text/xml")
     1.5 +
     1.6 +slot.put_into("default", '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
     1.7 +
     1.8 +function url(args)
     1.9 +  return ui.tag{
    1.10 +    tag = "url",
    1.11 +    content = function()
    1.12 +      ui.tag{tag = "loc",
    1.13 +             content = encode.url{
    1.14 +                base = request.get_absolute_baseurl(),
    1.15 +                module = args.module,
    1.16 +                view = args.view,
    1.17 +                id = args.id
    1.18 +              }
    1.19 +             }
    1.20 +      if args.lastmod then
    1.21 +        ui.tag{tag = "lastmod",
    1.22 +               content = args.lastmod
    1.23 +               }
    1.24 +      end
    1.25 +      ui.tag{tag = "changefreq",
    1.26 +             content = args.changefreq or "daily",
    1.27 +             }
    1.28 +      if args.priority then
    1.29 +        ui.tag{tag = "priority",
    1.30 +               content = tostring(args.priority)
    1.31 +               }
    1.32 +      end
    1.33 +
    1.34 +    end
    1.35 +  }
    1.36 +end
    1.37 +
    1.38 +function max(...)
    1.39 +  trace.debug_table(arg)
    1.40 +  nargs = {}
    1.41 +  for i = 1,1,arg.n do
    1.42 +    if type(arg[i]) == "number" then
    1.43 +      nargs[#nargs] = arg[i]
    1.44 +    end
    1.45 +  end
    1.46 +  if #nargs > 0 then
    1.47 +    return math.max(unpack(nargs))
    1.48 +  end
    1.49 +  return nil
    1.50 +end
    1.51 +
    1.52 +
    1.53 +areas = Area:new_selector():add_where("active='y'")
    1.54 +
    1.55 +for i,area in ipairs(areas:exec()) do
    1.56 +  url{ module = "area", view = "show", id = area.id, priority = 0.9 }
    1.57 +end
    1.58 +
    1.59 +-- FIXME timezone should be added as ...HH24:MI:SS+TZ with NUMERIC like +09:00
    1.60 +
    1.61 +issues = Issue:new_selector()
    1.62 +issues:add_field("to_char(GREATEST(issue.created, issue.accepted, issue.half_frozen, issue.fully_frozen, issue.closed, issue.cleaned), 'YYYY-MM-DD\"T\"HH24:MI:SS')", "lastmod")
    1.63 +
    1.64 +for i,issue in ipairs(issues:exec()) do
    1.65 +  url{ module = "issue", view = "show", id = issue.id, priority = 0.8,
    1.66 +       lastmod = tostring(issue.lastmod)
    1.67 +       }
    1.68 +end
    1.69 +
    1.70 +initiatives = Initiative:new_selector()
    1.71 +initiatives:add_field("to_char(GREATEST(initiative.created, initiative.revoked, (select draft.created from draft where draft.initiative_id = initiative.id ORDER BY draft.created DESC LIMIT 1)), 'YYYY-MM-DD\"T\"HH24:MI:SS')", "lastmod")
    1.72 +
    1.73 +for i,initiative in ipairs(initiatives:exec()) do
    1.74 +  url{ module = "initiative", view = "show", id = initiative.id, priority = 0.5,
    1.75 +       lastmod = tostring(initiative.lastmod)
    1.76 +       }
    1.77 +end
    1.78 +
    1.79 +--trace.render()
    1.80 +
    1.81 +slot.put_into("default", '</urlset>')
    1.82 +
    1.83 +return
    1.84 \ No newline at end of file

Impressum / About Us