Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.action.sitemap Namespace Reference

Functions

def now
def make_url_xml
def sitemap_url
def execute

Variables

string datetime_fmt = "%Y-%m-%dT%H:%M:%S+00:00"

Function Documentation

def MoinMoin.action.sitemap.execute (   pagename,
  request 
)

Definition at line 63 of file sitemap.py.

00063 
00064 def execute(pagename, request):
00065     _ = request.getText
00066     request.user.datetime_fmt = datetime_fmt
00067 
00068     request.mimetype = 'text/xml'
00069 
00070     # we emit a piece of data so other side doesn't get bored:
00071     request.write("""<?xml version="1.0" encoding="UTF-8"?>\r\n""")
00072 
00073     result = []
00074     result.append("""<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">\n""")
00075 
00076     # we include the root url as an important and often changed URL
00077     rooturl = request.script_root + '/'
00078     result.append(make_url_xml(request, {
00079         'url': rooturl,
00080         'lastmod': now(), # fake
00081         'changefreq': 'hourly',
00082         'priority': '1.0',
00083     }))
00084 
00085     # Get page dict readable by current user
00086     try:
00087         underlay = int(request.values.get('underlay', 1))
00088     except ValueError:
00089         underlay = 1
00090     pages = request.rootpage.getPageDict(include_underlay=underlay)
00091     pagelist = pages.keys()
00092     pagelist.sort()
00093     for name in pagelist:
00094         result.append(sitemap_url(request, pages[name]))
00095 
00096     result.append("""</urlset>\n""")
00097 
00098     result = "".join(result)
00099     result = result.replace("\n", "\r\n") # text/* requires CR/LF
00100 
00101     # emit all real data
00102     request.write(result)
00103 

Here is the call graph for this function:

def MoinMoin.action.sitemap.make_url_xml (   request,
  vars 
)
assemble a single <url> xml fragment 

Definition at line 18 of file sitemap.py.

00018 
00019 def make_url_xml(request, vars):
00020     """ assemble a single <url> xml fragment """
00021     # add protocol:server - url must be complete path starting with/from /
00022     vars['url'] = request.getQualifiedURL(vars['url'])
00023     return """\
00024 <url>
00025   <loc>%(url)s</loc>
00026   <lastmod>%(lastmod)s</lastmod>
00027   <changefreq>%(changefreq)s</changefreq>
00028   <priority>%(priority)s</priority>
00029 </url>
00030 """ % vars

Here is the caller graph for this function:

Definition at line 15 of file sitemap.py.

00015 
00016 def now():
00017     return time.strftime(datetime_fmt, time.gmtime())

Here is the caller graph for this function:

def MoinMoin.action.sitemap.sitemap_url (   request,
  page 
)
return a sitemap <url>..</url> fragment for page object <page> 

Definition at line 31 of file sitemap.py.

00031 
00032 def sitemap_url(request, page):
00033     """ return a sitemap <url>..</url> fragment for page object <page> """
00034     url = page.url(request)
00035     pagename = page.page_name
00036     lastmod = page.mtime_printable(request)
00037     if lastmod == "0": # can happen in case of errors
00038         lastmod = now()
00039 
00040     # page's changefreq, priority and lastmod depends on page type / name
00041     if pagename in [u"RecentChanges", u"TitleIndex", ]:
00042         # important dynamic pages with macros
00043         changefreq = "hourly"
00044         priority = "0.9"
00045         lastmod = now() # the page text mtime never changes, but the macro output DOES
00046 
00047     elif pagename in [request.cfg.page_front_page, ]:
00048         # important user edited pages
00049         changefreq = "hourly"
00050         priority = "1.0"
00051 
00052     elif wikiutil.isSystemPage(request, pagename):
00053         # other system pages are rather boring
00054         changefreq = "yearly"
00055         priority = "0.1"
00056 
00057     else:
00058         # these are the content pages:
00059         changefreq = "daily"
00060         priority = "0.5"
00061 
00062     return make_url_xml(request, locals())

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

string MoinMoin.action.sitemap.datetime_fmt = "%Y-%m-%dT%H:%M:%S+00:00"

Definition at line 13 of file sitemap.py.