diff options
author | clarkzjw <[email protected]> | 2018-01-18 13:43:19 +0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2018-01-18 13:43:19 +0800 |
commit | e12cf1463848faa973d7c2ec174892655d131c22 (patch) | |
tree | 74e0313a2029dfcdac57c9eaf431223305533c1c | |
parent | 50def653ece79940e270f741942c99b5a223cc15 (diff) | |
download | blog.jinwei.me-e12cf1463848faa973d7c2ec174892655d131c22.tar.gz |
+ fix
-rw-r--r-- | _posts/2018/01/new-blog.rst | 32 | ||||
-rwxr-xr-x | bootstrap.py | 2 | ||||
-rw-r--r-- | rss.py | 12 |
3 files changed, 11 insertions, 35 deletions
diff --git a/_posts/2018/01/new-blog.rst b/_posts/2018/01/new-blog.rst index 7e656e3..a638797 100644 --- a/_posts/2018/01/new-blog.rst +++ b/_posts/2018/01/new-blog.rst | |||
@@ -36,35 +36,11 @@ Dockerfile中生成静态html网页,然后在构建的过程中将静态网页 | |||
36 | 构建的镜像已经上百MB了。有了multi stage build之后,这个问题便非常好地被解决了。看了下面的Dockerfile之后,整体思路就非常清晰了。目前我 | 36 | 构建的镜像已经上百MB了。有了multi stage build之后,这个问题便非常好地被解决了。看了下面的Dockerfile之后,整体思路就非常清晰了。目前我 |
37 | 在本地写完rst文本,然后git push之后,CircleCI会自动进行Dockerfile的构建,然后将编译生成的静态html推送到gh-pages分支。 | 37 | 在本地写完rst文本,然后git push之后,CircleCI会自动进行Dockerfile的构建,然后将编译生成的静态html推送到gh-pages分支。 |
38 | 38 | ||
39 | .. code-block:: bash | 39 | .. raw:: html |
40 | |||
41 | FROM python:3.6.0 as builder | ||
42 | LABEL maintainer=clarkzjw<[email protected]> | ||
43 | RUN pip install virtualenv | ||
44 | COPY requirements.txt /app/requirements.txt | ||
45 | COPY bootstrap.py /app/bootstrap.py | ||
46 | RUN /app/bootstrap.py | ||
47 | ADD . /app | ||
48 | WORKDIR /app | ||
49 | RUN /bin/bash -c "source /app/.venv/bin/activate && make html && make rss && cp rss.xml _build/html" | ||
50 | |||
51 | |||
52 | FROM alpine:latest | ||
53 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories | ||
54 | RUN apk add --update git openssh-client && rm -rf /var/cache/apk/* | ||
55 | WORKDIR /html | ||
56 | ENV COMMIT_USER="clarkzjw" | ||
57 | ENV COMMIT_EMAIL="[email protected]" | ||
58 | ARG GIT_TOKEN="" | ||
59 | RUN git config --global user.email $COMMIT_EMAIL && git config --global user.name $COMMIT_USER | ||
60 | RUN git clone https://clarkzjw:[email protected]/clarkzjw/blog.jinwei.me.git /html && git checkout gh-pages | ||
61 | COPY --from=builder /app/_build/html /html | ||
62 | RUN echo "`date`" > /html/.lastmodify && git add -A && git commit -m "`date`" && git push origin gh-pages | ||
63 | |||
64 | |||
65 | FROM nginx:alpine | ||
66 | COPY --from=builder /app/_build/html /usr/share/nginx/html | ||
67 | 40 | ||
41 | <embed> | ||
42 | <script src="https://gist.github.com/clarkzjw/0cb4e15794a5a132b12df9741e0cc1e0.js"></script> | ||
43 | </embed> | ||
68 | 44 | ||
69 | 另外一个问题是博客的RSS。由于Sphinx最初的设计是作为一个文档生成工具,目前市面上有的和Sphinx结合的RSS生成工具大致有: | 45 | 另外一个问题是博客的RSS。由于Sphinx最初的设计是作为一个文档生成工具,目前市面上有的和Sphinx结合的RSS生成工具大致有: |
70 | 46 | ||
diff --git a/bootstrap.py b/bootstrap.py index 0c07b9d..a688154 100755 --- a/bootstrap.py +++ b/bootstrap.py | |||
@@ -1,6 +1,4 @@ | |||
1 | #!/usr/bin/env python3 | 1 | #!/usr/bin/env python3 |
2 | from __future__ import absolute_import, print_function, unicode_literals | ||
3 | |||
4 | import os | 2 | import os |
5 | import subprocess | 3 | import subprocess |
6 | import sys | 4 | import sys |
@@ -1,7 +1,7 @@ | |||
1 | import glob | ||
1 | import os | 2 | import os |
2 | import jinja2 | ||
3 | 3 | ||
4 | import glob | 4 | import jinja2 |
5 | from bs4 import BeautifulSoup | 5 | from bs4 import BeautifulSoup |
6 | 6 | ||
7 | 7 | ||
@@ -31,16 +31,18 @@ def main(): | |||
31 | filenames = glob.glob("./_build/html/_posts/*/*/*.html") | 31 | filenames = glob.glob("./_build/html/_posts/*/*/*.html") |
32 | posts = [] | 32 | posts = [] |
33 | 33 | ||
34 | for p in filenames: | 34 | for file in filenames: |
35 | soup = BeautifulSoup(open(p), "html5lib") | 35 | soup = BeautifulSoup(open(file), "html5lib") |
36 | body = soup.find_all("div", class_="body")[0].text | 36 | body = soup.find_all("div", class_="body")[0].text |
37 | 37 | ||
38 | posts.append({ | 38 | posts.append({ |
39 | "title": soup.title.string, | 39 | "title": soup.title.string, |
40 | "body": body, | 40 | "body": body, |
41 | "date_rss": body[body.find("Publish Date:")+13:body.find("Publish Date:")+23], | 41 | "date_rss": body[body.find("Publish Date:")+13:body.find("Publish Date:")+23], |
42 | "permalink": "/".join(p.split("/")[3:]) | 42 | "permalink": "/".join(file.split("/")[3:]) |
43 | }) | 43 | }) |
44 | with open(file, "w") as file: | ||
45 | file.write(str(BeautifulSoup(str(soup).replace("\n", "").replace("\r", ""), "html5lib").prettify())) | ||
44 | 46 | ||
45 | context = { | 47 | context = { |
46 | "site": { | 48 | "site": { |