aboutsummaryrefslogtreecommitdiff
path: root/pyblog
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2018-07-29 20:37:34 +0200
committerneodarz <neodarz@neodarz.net>2018-07-29 20:37:34 +0200
commitaa0ec4755f5bb44271182f29bbbc77c70320dbc9 (patch)
tree2fc8ef004fafd535537c874dbea669c80075ae8b /pyblog
parent90e53d5d574442b9c8dc8a19841171eb8694b932 (diff)
downloadmy_new_personal_website-aa0ec4755f5bb44271182f29bbbc77c70320dbc9.tar.xz
my_new_personal_website-aa0ec4755f5bb44271182f29bbbc77c70320dbc9.zip
Add blog configurations in a config file
Diffstat (limited to '')
-rwxr-xr-xpyblog74
1 files changed, 39 insertions, 35 deletions
diff --git a/pyblog b/pyblog
index 49919b69..a9abd8da 100755
--- a/pyblog
+++ b/pyblog
@@ -2,7 +2,6 @@
"""A simple blog generator with Pandoc as backend."""
-# TODO: put blog configurations in a config file
# TODO: auto retouch: prompt for git commit amend after touching
# (display commit message to avoid amending the wrong commit)
@@ -41,42 +40,47 @@ from bs4 import UnicodeDammit
from pprint import pprint
import requests
-############################# BLOG CONFIGURATIONS ##############################
-# Safe to customize
-BLOG_HOME = "http://neodarz.net/"
-CUSTOM_DOMAIN = "neodarz.net" # GitHub Pages custom domain (could be None)
-BLOG_TITLE = "Why is there always a cat on whatever you're editing?"
-BLOG_DESCRIPTION = "Just my stupid personal website"
-LANGUAGE = "en-us"
-AUTHOR = "neodarz"
-AUTHOR_EMAIL = "neodarz@neodarz.net"
-ATOM_ICON_PATH = "img/icon-400.png" # set to None to leave it out
-RSS_ICON_PATH = "img/icon-100.png" # set to None to leave it out
-RSS_ICON_WIDTH = 100
-RSS_ICON_HEIGHT = 100
-########################## END OF BLOG CONFIGURATIONS ##########################
-
-
-########################### GENERATOR CONFIGURATIONS ###########################
-# Do not touch unless you know what you are doing.
-GENERATOR_NAME = "pyblog"
-GENERATOR_HOME_PAGE = "https://github.com/zmwangx/zmwangx.github.io"
+import toml
ROOTDIR = os.path.dirname(os.path.realpath(__file__))
-SOURCEDIR = os.path.join(ROOTDIR, "source")
-POSTSDIR = os.path.join(SOURCEDIR, "blog")
-INDEXMD = os.path.join(SOURCEDIR, "index.md")
-GENERATORSOURCE = os.path.join(ROOTDIR, "pyblog")
-HTMLTEMPLATE = os.path.join(SOURCEDIR, "template.html")
-BUILDDIR = os.path.join(ROOTDIR, "build")
-ATOM = os.path.join(BUILDDIR, "atom.xml")
-RSS = os.path.join(BUILDDIR, "rss.xml")
-INDEXHTML = os.path.join(BUILDDIR, "index.html")
-EXCLUDELIST = os.path.join(SOURCEDIR, ".exclude")
-
-FEED_MAX_ENTRIES = 20
-CODE_LINE_HEIGHT = 18
-####################### END OF GENERATOR CONFIGURATIONS ########################
+
+
+config_blog = toml.load(os.path.join(ROOTDIR, "config/blog.toml"))
+config_generator = toml.load(os.path.join(ROOTDIR, "config/generator.toml"))
+
+
+config = {**config_blog, **config_generator}
+
+# Blog configuration
+BLOG_HOME = config["blog"]["BLOG_HOME"]
+CUSTOM_DOMAIN = config["blog"]["CUSTOM_DOMAIN"]
+BLOG_TITLE = config["blog"]["BLOG_TITLE"]
+BLOG_DESCRIPTION = config["blog"]["BLOG_DESCRIPTION"]
+LANGUAGE = config["blog"]["LANGUAGE"]
+AUTHOR = config["blog"]["AUTHOR"]
+AUTHOR_EMAIL = config["blog"]["AUTHOR_EMAIL"]
+ATOM_ICON_PATH = config["blog"]["ATOM_ICON_PATH"]
+RSS_ICON_PATH = config["blog"]["RSS_ICON_PATH"]
+RSS_ICON_WIDTH = config["blog"]["RSS_ICON_WIDTH"]
+RSS_ICON_HEIGHT = config["blog"]["RSS_ICON_HEIGHT"]
+
+#generator configurations
+GENERATOR_NAME = config["generator"]["GENERATOR_NAME"]
+GENERATOR_HOME_PAGE = config["generator"]["GENERATOR_HOME_PAGE"]
+
+SOURCEDIR = os.path.join(ROOTDIR, config["generator"]["SOURCEDIR"])
+POSTSDIR = os.path.join(SOURCEDIR, config["generator"]["POSTSDIR"])
+INDEXMD = os.path.join(SOURCEDIR, config["generator"]["INDEXMD"])
+GENERATORSOURCE = os.path.join(ROOTDIR, config["generator"]["GENERATORSOURCE"])
+HTMLTEMPLATE = os.path.join(SOURCEDIR, config["generator"]["HTMLTEMPLATE"])
+BUILDDIR = os.path.join(ROOTDIR, config["generator"]["BUILDDIR"])
+ATOM = os.path.join(BUILDDIR, config["generator"]["ATOM"])
+RSS = os.path.join(BUILDDIR, config["generator"]["RSS"])
+INDEXHTML = os.path.join(BUILDDIR, config["generator"]["INDEXHTML"])
+EXCLUDELIST = os.path.join(SOURCEDIR, config["generator"]["EXCLUDELIST"])
+
+FEED_MAX_ENTRIES = config["generator"]["FEED_MAX_ENTRIES"]
+CODE_LINE_HEIGHT = config["generator"]["CODE_LINE_HEIGHT"]
# declare the global foreground ANSI codes