added sitemap, rss feeds
This commit is contained in:
parent
cbdb0b9f76
commit
cbdbf2e32e
3 changed files with 88 additions and 0 deletions
0
py/webnotes/cms/__init__.py
Normal file
0
py/webnotes/cms/__init__.py
Normal file
54
py/webnotes/cms/feed.py
Normal file
54
py/webnotes/cms/feed.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
"""
|
||||
Generate RSS feed for blog
|
||||
"""
|
||||
|
||||
rss = """<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>%(title)s</title>
|
||||
<description>%(description)s</description>
|
||||
<link>%(link)s</link>
|
||||
<lastBuildDate>%(modified)s</lastBuildDate>
|
||||
<pubDate>%(modified)s</pubDate>
|
||||
<ttl>1800</ttl>
|
||||
%(items)s
|
||||
</channel>
|
||||
</rss>"""
|
||||
|
||||
rss_item = """
|
||||
<item>
|
||||
<title>%(title)s</title>
|
||||
<description>%(content_html)s</description>
|
||||
<link>%(link)s</link>
|
||||
<guid>%(name)s</guid>
|
||||
<pubDate>%(modified)s</pubDate>
|
||||
</item>"""
|
||||
|
||||
def generate():
|
||||
"""generate rss feed"""
|
||||
import webnotes, os
|
||||
from webnotes.model.doc import Document
|
||||
|
||||
host = (os.environ.get('HTTPS') and 'https://' or 'http://') + os.environ.get('HTTP_HOST')
|
||||
|
||||
items = ''
|
||||
modified = None
|
||||
for blog in webnotes.conn.sql("""select name, title, content_html, modified from tabBlog
|
||||
where ifnull(published,0)=1 order by modified desc limit 100""", as_dict=1):
|
||||
blog['link'] = host + '/#!' + blog['name']
|
||||
blog['content_html'] = scrub(blog['content_html'] or '')
|
||||
if not modified:
|
||||
modified = blog['modified']
|
||||
items += rss_item % blog
|
||||
|
||||
ws = Document('Website Settings', 'Website Settings')
|
||||
return rss % {
|
||||
'title': ws.title_prefix,
|
||||
'description': ws.description or (ws.title_prefix + ' Blog'),
|
||||
'modified': modified,
|
||||
'items': items,
|
||||
'link': host + '/#!blog'
|
||||
}
|
||||
|
||||
def scrub(txt):
|
||||
return txt.replace('<', '<').replace('>', '>')
|
||||
34
py/webnotes/cms/sitemap.py
Normal file
34
py/webnotes/cms/sitemap.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# to generate sitemaps
|
||||
|
||||
frame_xml = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">%s
|
||||
</urlset>"""
|
||||
|
||||
link_xml = """\n<url><loc>%s</loc><lastmod>%s</lastmod></url>"""
|
||||
|
||||
# generate the sitemap XML
|
||||
def generate(domain):
|
||||
global frame_xml, link_xml
|
||||
import urllib
|
||||
import webnotes
|
||||
|
||||
# settings
|
||||
max_doctypes = 10
|
||||
max_items = 1000
|
||||
|
||||
site_map = ''
|
||||
page_list = []
|
||||
|
||||
if domain:
|
||||
# list of all Guest pages (static content)
|
||||
for r in webnotes.conn.sql("""SELECT distinct t1.name, t1.modified
|
||||
FROM tabPage t1, `tabPage Role` t2
|
||||
WHERE t1.name = t2.parent
|
||||
and t2.role = 'Guest'
|
||||
ORDER BY modified DESC"""):
|
||||
|
||||
page_url = domain + '#!' + urllib.quote(r[0])
|
||||
site_map += link_xml % (page_url, r[1].strftime('%Y-%m-%d'))
|
||||
|
||||
|
||||
return frame_xml % site_map
|
||||
Loading…
Add table
Reference in a new issue