aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--all.rss.xml18
-rw-r--r--blog.iml9
-rw-r--r--rss.py68
3 files changed, 86 insertions, 9 deletions
diff --git a/all.rss.xml b/all.rss.xml
new file mode 100644
index 0000000..cafc7fd
--- /dev/null
+++ b/all.rss.xml
@@ -0,0 +1,18 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
3 <channel>
4 <title>{{ site.name }}</title>
5 <link>{{ site.url }}</link>
6 <description>{{ site.tagline }}</description>
7 <atom:link href="{{ site.url }}/rss" rel="self" type="application/rss+xml" />
8 {% for post in posts[:20] %}
9 <item>
10 <title>{{ post.title | e }}</title>
11 <description>{{ post.body | e }}</description>
12 <pubDate>{{ post.date_rss }}</pubDate>
13 <link>{{ site.url }}/{{ post.permalink }}</link>
14 <guid isPermaLink="true">{{ site.url }}/{{ post.permalink }}</guid>
15 </item>
16 {% endfor %}
17 </channel>
18</rss>
diff --git a/blog.iml b/blog.iml
deleted file mode 100644
index ad3c0a3..0000000
--- a/blog.iml
+++ /dev/null
@@ -1,9 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<module type="PYTHON_MODULE" version="4">
3 <component name="NewModuleRootManager" inherit-compiler-output="true">
4 <exclude-output />
5 <content url="file://$MODULE_DIR$" />
6 <orderEntry type="inheritedJdk" />
7 <orderEntry type="sourceFolder" forTests="false" />
8 </component>
9</module> \ No newline at end of file
diff --git a/rss.py b/rss.py
new file mode 100644
index 0000000..fbf70d1
--- /dev/null
+++ b/rss.py
@@ -0,0 +1,68 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Created by [email protected] at 2015-07-30
4
5import os
6import argparse
7import yaml
8
9import jinja2
10
11
12class FilePathLoader(jinja2.BaseLoader):
13 """ Custom Jinja2 template loader which just loads a single template file """
14
15 def __init__(self, cwd):
16 self.cwd = cwd
17
18 def get_source(self, environment, template):
19 # Path
20 filename = os.path.join(self.cwd, template)
21
22 # Read
23 try:
24 with open(filename, 'r') as f:
25 contents = f.read()
26 except IOError:
27 raise jinja2.TemplateNotFound(filename)
28
29 # Finish
30 uptodate = lambda: False
31 return contents, filename, uptodate
32
33
34def render_template(cwd, template_path, context):
35 env = jinja2.Environment(loader=FilePathLoader(cwd))
36
37 return env \
38 .get_template(template_path) \
39 .render(context)
40
41
42def main():
43 parser = argparse.ArgumentParser()
44
45 parser.add_argument('--dir', default='.', help='Template directory')
46 parser.add_argument('--data', nargs='*', help='One or more YAML data file')
47 parser.add_argument('--template', help='Template file to process')
48 parser.add_argument('--body', help='Body content')
49 args = parser.parse_args()
50
51 context = dict()
52 for data_f in args.data if args.data else []:
53 key, filename = data_f.split(':')
54 if filename:
55 context[key] = yaml.load(open(filename).read())
56 else:
57 context[key] = {'_': True}
58 if args.body:
59 context['body'] = open(args.body).read()
60
61 return render_template(
62 args.dir,
63 args.template,
64 context
65 )
66
67if __name__ == '__main__':
68 print(main())
Powered by cgit v1.2.3 (git 2.41.0)