From e12cf1463848faa973d7c2ec174892655d131c22 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Thu, 18 Jan 2018 13:43:19 +0800 Subject: + fix --- _posts/2018/01/new-blog.rst | 32 ++++---------------------------- bootstrap.py | 2 -- 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网页,然后在构建的过程中将静态网页 构建的镜像已经上百MB了。有了multi stage build之后,这个问题便非常好地被解决了。看了下面的Dockerfile之后,整体思路就非常清晰了。目前我 在本地写完rst文本,然后git push之后,CircleCI会自动进行Dockerfile的构建,然后将编译生成的静态html推送到gh-pages分支。 -.. code-block:: bash - - FROM python:3.6.0 as builder - LABEL maintainer=clarkzjw - RUN pip install virtualenv - COPY requirements.txt /app/requirements.txt - COPY bootstrap.py /app/bootstrap.py - RUN /app/bootstrap.py - ADD . /app - WORKDIR /app - RUN /bin/bash -c "source /app/.venv/bin/activate && make html && make rss && cp rss.xml _build/html" - - - FROM alpine:latest - RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories - RUN apk add --update git openssh-client && rm -rf /var/cache/apk/* - WORKDIR /html - ENV COMMIT_USER="clarkzjw" - ENV COMMIT_EMAIL="hello@jinwei.me" - ARG GIT_TOKEN="" - RUN git config --global user.email $COMMIT_EMAIL && git config --global user.name $COMMIT_USER - RUN git clone https://clarkzjw:$GIT_TOKEN@github.com/clarkzjw/blog.jinwei.me.git /html && git checkout gh-pages - COPY --from=builder /app/_build/html /html - RUN echo "`date`" > /html/.lastmodify && git add -A && git commit -m "`date`" && git push origin gh-pages - - - FROM nginx:alpine - COPY --from=builder /app/_build/html /usr/share/nginx/html +.. raw:: html + + + 另外一个问题是博客的RSS。由于Sphinx最初的设计是作为一个文档生成工具,目前市面上有的和Sphinx结合的RSS生成工具大致有: diff --git a/bootstrap.py b/bootstrap.py index 0c07b9d..a688154 100755 --- a/bootstrap.py +++ b/bootstrap.py @@ -1,6 +1,4 @@ #!/usr/bin/env python3 -from __future__ import absolute_import, print_function, unicode_literals - import os import subprocess import sys diff --git a/rss.py b/rss.py index 928bf34..af9f0ca 100644 --- a/rss.py +++ b/rss.py @@ -1,7 +1,7 @@ +import glob import os -import jinja2 -import glob +import jinja2 from bs4 import BeautifulSoup @@ -31,16 +31,18 @@ def main(): filenames = glob.glob("./_build/html/_posts/*/*/*.html") posts = [] - for p in filenames: - soup = BeautifulSoup(open(p), "html5lib") + for file in filenames: + soup = BeautifulSoup(open(file), "html5lib") body = soup.find_all("div", class_="body")[0].text posts.append({ "title": soup.title.string, "body": body, "date_rss": body[body.find("Publish Date:")+13:body.find("Publish Date:")+23], - "permalink": "/".join(p.split("/")[3:]) + "permalink": "/".join(file.split("/")[3:]) }) + with open(file, "w") as file: + file.write(str(BeautifulSoup(str(soup).replace("\n", "").replace("\r", ""), "html5lib").prettify())) context = { "site": { -- cgit v1.2.3