From cbdbf2e32ea9c2e93fd7eb0115dce2d98aec0823 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 7 Feb 2012 13:30:08 +0530 Subject: [PATCH] added sitemap, rss feeds --- py/webnotes/cms/__init__.py | 0 py/webnotes/cms/feed.py | 54 +++++++++++++++++++++++++++++++++++++ py/webnotes/cms/sitemap.py | 34 +++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 py/webnotes/cms/__init__.py create mode 100644 py/webnotes/cms/feed.py create mode 100644 py/webnotes/cms/sitemap.py diff --git a/py/webnotes/cms/__init__.py b/py/webnotes/cms/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/py/webnotes/cms/feed.py b/py/webnotes/cms/feed.py new file mode 100644 index 0000000000..31afb5bfee --- /dev/null +++ b/py/webnotes/cms/feed.py @@ -0,0 +1,54 @@ +""" +Generate RSS feed for blog +""" + +rss = """ + + + %(title)s + %(description)s + %(link)s + %(modified)s + %(modified)s + 1800 + %(items)s + +""" + +rss_item = """ + + %(title)s + %(content_html)s + %(link)s + %(name)s + %(modified)s +""" + +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('>', '>') \ No newline at end of file diff --git a/py/webnotes/cms/sitemap.py b/py/webnotes/cms/sitemap.py new file mode 100644 index 0000000000..0831ed1e83 --- /dev/null +++ b/py/webnotes/cms/sitemap.py @@ -0,0 +1,34 @@ +# to generate sitemaps + +frame_xml = """ +%s +""" + +link_xml = """\n%s%s""" + +# 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