]> git.donarmstrong.com Git - neurodebian.git/commitdiff
Pimp the feed extension.
authorMichael Hanke <michael.hanke@gmail.com>
Fri, 18 Mar 2011 20:37:53 +0000 (16:37 -0400)
committerMichael Hanke <michael.hanke@gmail.com>
Fri, 18 Mar 2011 20:37:53 +0000 (16:37 -0400)
sphinx/conf.py
sphinx/sphinxext/feed/__init__.py

index 5ec8c0f0f1ba417cc749f3d43361aca9c3b0c8a6..745c8b88599bfe2126f0da686fffb7ace434b112 100644 (file)
@@ -77,7 +77,7 @@ release = ''
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
-#language = None
+language = 'en'
 
 # There are two options for replacing |today|: either, you set today to some
 # non-false value, then it is used:
@@ -214,5 +214,11 @@ latex_documents = [
 # RSS feed
 # --------
 feed_base_url = 'http://neuro.debian.net/blog'
+feed_title = "Debian for neuroscience and neuroscience in Debian"
 feed_description = "Debian for neuroscience and neuroscience in Debian"
-feed_filename = 'rss.xml'
+feed_variants = {'planetdebian': {'filename': 'debian-planet.xml',
+                                  'tag': 'debian'},
+                 'all': {'filename': 'all.xml', 'tag': None}}
+feed_categories = ['debian', 'neuroscience']
+feed_author_name = 'NeuroDebian team'
+feed_author_email = 'team@neuro.debian.net'
index 11a6004a099d992c8a796d8e1ae0f01eb1aea4d6..ddccc1c0478d7143e5218dde22ec77b08a48a9ba 100644 (file)
@@ -18,8 +18,14 @@ def setup(app):
     if not isinstance(app, Sphinx): return
     app.add_config_value('feed_base_url', '', 'html')
     app.add_config_value('feed_description', '', 'html')
-    app.add_config_value('feed_filename', 'rss.xml', 'html')
-    
+    app.add_config_value('feed_title', '', 'html')
+    app.add_config_value('feed_subtitle', '', 'html')
+    app.add_config_value('feed_author_name', '', 'html')
+    app.add_config_value('feed_author_email', '', 'html')
+    app.add_config_value('feed_categories', [], 'html')
+    app.add_config_value('feed_variants',
+                         {'all': {'filename': 'rss.xml', 'categories': None}},
+                         'html')
     app.connect('html-page-context', create_feed_item)
     app.connect('html-page-context', inject_feed_url)
     app.connect('build-finished', emit_feed)
@@ -35,9 +41,8 @@ def create_feed_container(app):
     global feed_entries
     rss_fragment_path = os.path.realpath(os.path.join(app.outdir, '..', 'rss_entry_fragments'))
     feed_entries = FSDict(work_dir=rss_fragment_path)
-    app.builder.env.feed_url = app.config.feed_base_url + '/' + \
-        app.config.feed_filename
-    
+    app.builder.env.feed_url = app.config.feed_base_url + '/' + 'feed_container'
+
 def inject_feed_url(app, pagename, templatename, ctx, doctree):
     #We like to provide our templates with a way to link to the rss output file
     ctx['rss_link'] = app.builder.env.feed_url #app.config.feed_base_url + '/' + app.config.feed_filename
@@ -72,10 +77,19 @@ def create_feed_item(app, pagename, templatename, ctx, doctree):
       'link': link,
       'unique_id': link,
       'description': absolutify(ctx.get('body'), link),
-      'pubdate': pub_date
+      'pubdate': pub_date,
+      'categories': ()
     }
+    if 'tags' in metadata:
+        item['categories'] = metadata['tags'].split(",")
     if 'author' in metadata:
-        item['author'] = metadata['author']
+        item['author_name'] = metadata['author']
+    else:
+        item['author_name'] = app.config.feed_author_name
+    if 'author_email' in metadata:
+        item['author_email'] = metadata['author_email']
+    else:
+        item['author_email'] = app.config.feed_author_email
     feed_entries[nice_name(pagename, pub_date)] = item    
 
 def remove_dead_feed_item(app, env, docname):
@@ -94,26 +108,37 @@ def emit_feed(app, exc):
     import os.path
     
     feed_dict = {
-      'title': app.config.project,
+      'title': app.config.feed_title,
+      'subtitle': app.config.feed_subtitle,
       'link': app.config.feed_base_url,
       'feed_url': app.config.feed_base_url,
-      'description': app.config.feed_description
+      'description': app.config.feed_description,
+      'categories': app.config.feed_categories,
+      'author_name': app.config.feed_author_name,
+      'author_email': app.config.feed_author_email
     }
     if app.config.language:
         feed_dict['language'] = app.config.language
     if app.config.copyright:
         feed_dict['feed_copyright'] = app.config.copyright
-    feed = feedgenerator.Rss201rev2Feed(**feed_dict)
-    app.builder.env.feed_feed = feed
-    ordered_keys = feed_entries.keys()
-    ordered_keys.sort(reverse=True)
-    for key in ordered_keys:
-        feed.add_item(**feed_entries[key])     
-    outfilename = os.path.join(app.builder.outdir,
-      app.config.feed_filename)
-    fp = open(outfilename, 'w')
-    feed.write(fp, 'utf-8')
-    fp.close()
+    # loop over all feed variants
+    for feedvar in app.config.feed_variants:
+        feedvar_settings = app.config.feed_variants[feedvar]
+        feed = feedgenerator.Rss201rev2Feed(**feed_dict)
+        app.builder.env.feed_feed = feed
+        ordered_keys = feed_entries.keys()
+        ordered_keys.sort(reverse=True)
+        for key in ordered_keys:
+            item = feed_entries[key]
+            # only take the ones that should be in this feed
+            if feedvar_settings['tag'] is None \
+                    or feedvar_settings['tag'] in item['categories']:
+                feed.add_item(**feed_entries[key])
+        outfilename = os.path.join(app.builder.outdir,
+          feedvar_settings['filename'])
+        fp = open(outfilename, 'w')
+        feed.write(fp, 'utf-8')
+        fp.close()
 
 def nice_name(docname, date):
     """