aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2018-01-11 20:55:47 +0800
committerGitHub <[email protected]>2018-01-11 20:55:47 +0800
commit869c9a1699ed11cfe064013f7089a7dd7c499671 (patch)
tree7c8a37f83f755c7badd982d1bb2f950c40556393
parent3237e400631bcc71fa970557edfde40a658819c5 (diff)
parent866436c73338c2d0caa0cb35dff4949048943fee (diff)
downloadblog.jinwei.me-869c9a1699ed11cfe064013f7089a7dd7c499671.tar.gz
Merge pull request #1 from clarkzjw/feed
Support generate rss.xml
-rw-r--r--Dockerfile2
-rw-r--r--Makefile5
-rw-r--r--_posts/2017/12/movies.rst (renamed from _posts/2017/movies.rst)4
-rw-r--r--all.rss.xml18
-rw-r--r--blog.iml9
-rw-r--r--rss.py64
-rw-r--r--rss.xml94
7 files changed, 184 insertions, 12 deletions
diff --git a/Dockerfile b/Dockerfile
index be6aae8..9560268 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -14,7 +14,7 @@ ADD . /app
14 14
15WORKDIR /app 15WORKDIR /app
16 16
17RUN /bin/bash -c "source /app/.venv/bin/activate && make html" 17RUN /bin/bash -c "source /app/.venv/bin/activate && make html && make rss"
18 18
19 19
20FROM alpine:latest 20FROM alpine:latest
diff --git a/Makefile b/Makefile
index 6a109aa..223cadf 100644
--- a/Makefile
+++ b/Makefile
@@ -12,9 +12,12 @@ BUILDDIR = _build
12help: 12help:
13 @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14 14
15rss:
16 python rss.py > rss.xml
17
15.PHONY: help Makefile 18.PHONY: help Makefile
16 19
17# Catch-all target: route all unknown targets to Sphinx using the new 20# Catch-all target: route all unknown targets to Sphinx using the new
18# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 21# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19%: Makefile 22%: Makefile
20 @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file 23 @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/_posts/2017/movies.rst b/_posts/2017/12/movies.rst
index 10fcbc3..6be761d 100644
--- a/_posts/2017/movies.rst
+++ b/_posts/2017/12/movies.rst
@@ -2,9 +2,11 @@
2 2
3.. _2017movie: 3.. _2017movie:
4 4
5
52017观影记录 62017观影记录
6=================== 7===================
7 8
9:Publish Date: 2017-12-30
8 10
92017年马上就结束了。掐指一算,2017年看了好多电影。包括线上和线下电影院的。 112017年马上就结束了。掐指一算,2017年看了好多电影。包括线上和线下电影院的。
10 12
@@ -67,7 +69,7 @@
67 69
68简单分析了一下,线下观影的统计 70简单分析了一下,线下观影的统计
69 71
70.. image:: ../../_static/img/2017movie.png 72.. image:: ../../../_static/img/2017movie.png
71 :alt: 2017movie 73 :alt: 2017movie
72 :align: center 74 :align: center
73 75
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..fdf4b53
--- /dev/null
+++ b/rss.py
@@ -0,0 +1,64 @@
1import os
2import jinja2
3
4import glob
5from bs4 import BeautifulSoup
6
7
8class FilePathLoader(jinja2.BaseLoader):
9 def __init__(self, cwd):
10 self.cwd = cwd
11
12 def get_source(self, environment, template):
13 filename = os.path.join(self.cwd, template)
14
15 try:
16 with open(filename, 'r') as f:
17 contents = f.read()
18 except IOError:
19 raise jinja2.TemplateNotFound(filename)
20
21 return contents, filename, lambda: False
22
23
24def render_template(cwd, template_path, context):
25 env = jinja2.Environment(loader=FilePathLoader(cwd))
26 return env.get_template(template_path).render(context)
27
28
29def main():
30
31 filenames = glob.glob("./_build/html/_posts/*/*/*.html")
32 print(filenames)
33
34 posts = []
35
36 for p in filenames:
37 soup = BeautifulSoup(open(p), "html5lib")
38 body = soup.find_all("div", class_="body")[0].text
39
40 posts.append({
41 "title": soup.title.string,
42 "body": body,
43 "date_rss": body[body.find("Publish Date:")+13:body.find("Publish Date:")+23],
44 "permalink": "/".join(p.split("/")[3:])
45 })
46
47 context = {
48 "site": {
49 "name": "Hello World",
50 "url": "https://blog.jinwei.me",
51 "tagline": "Freedom is my birth right and I shall have it."
52 },
53 "posts": posts
54 }
55
56 return render_template(
57 ".",
58 "all.rss.xml",
59 context
60 )
61
62
63if __name__ == '__main__':
64 print(main())
diff --git a/rss.xml b/rss.xml
new file mode 100644
index 0000000..6e8bbcd
--- /dev/null
+++ b/rss.xml
@@ -0,0 +1,94 @@
1['./_build/html/_posts/2017/12/movies.html']
2<?xml version="1.0" encoding="UTF-8"?>
3<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
4 <channel>
5 <title>Hello World</title>
6 <link>https://blog.jinwei.me</link>
7 <description>Freedom is my birth right and I shall have it.</description>
8 <atom:link href="https://blog.jinwei.me/rss" rel="self" type="application/rss+xml" />
9
10 <item>
11 <title>2017观影记录 — Hello World</title>
12 <description>
13
14
152017观影记录¶
16
17
18
19
20Publish Date:2010-01-01
21
22
23
242017年马上就结束了。掐指一算,2017年看了好多电影。包括线上和线下电影院的。
25线下电影院观影记录(按时间顺序,以中国大陆上映时的片名为准):
26
27星球大战外传:侠盗一号 (Rogue One: A Star Wars Story)
28太空旅客 (Passengers)
29降临 (Arrival)
30极限特工:终极回归 (xXx: The Return of Xander Cage)
31生化危机6:终章 (Resident Evil: The Final Chapter)
32金刚狼3:殊死一战 (Logan)
33攻壳机动队 (Ghost in the Shell)
34速度与激情8 (The Fate of the Furious)
35拆弹专家
36大护法
37战狼2
38星际特工:千星之城 (Valérian et la Cité des mille planètes)
39看不见的客人 (Contratiempo)
40英伦对决 (The Foreigner)
41天才枪手 (ฉลาดเกมส์โกง)
42王牌特工2:黄金圈 (Kingsman: The Golden Circle)
43全球风暴 (Geostorm)
44东方快车谋杀案 (Murder on the Orient Express)
45雷神3:诸神黄昏 (Thor: Ragnarok)
46追捕
47至暗时刻 (Darkest Hour)
48寻梦环游记 (Coco)
49至爱梵高·星空之谜 (Loving Vincent)
50芳华
51
52线上观影记录(包括BT下载以及Netflix,包括电影/纪录片/部分美剧,不完全):
53
54Blade Runner (1982)
55Blade Runner 2049
56Love Actually
57World War Z
58Dunkirk
59Everst
60霸王别姬
61Titanic
62隧道 (터널)
63London Has Fallen
64出租车司机 (택시운전사)
65Ocean’s Eleven
66Ocean’s Twelve
67Shooter
68Knight Day
692001: A Space Odyssey
70Minority Report
71Deep Impact
72Area 51
73San Andreas
74I, Origin
75Particle Fever
76City 40
77Stranger Things
78House Of Cards, Season 1
79
80现在回忆一下,很多电影的质量其实很一般,属于看完之后走出电影院差不多就能忘记剧情的那种。这种电影很多都是所谓的「商业大片」,追求特效和画面,完全不考虑剧情的质量和观众的观影感受。
81简单分析了一下,线下观影的统计
82
836月居然一部都没看,是因为工作太饱和了还是因为没有好看的电影呢?
84
85
86
87 </description>
88 <pubDate>2010-01-01</pubDate>
89 <link>https://blog.jinwei.me/_posts/2017/12/movies.html</link>
90 <guid isPermaLink="true">https://blog.jinwei.me/_posts/2017/12/movies.html</guid>
91 </item>
92
93 </channel>
94</rss>
Powered by cgit v1.2.3 (git 2.41.0)