From 746b166704068d2be7762a9c2885f08dae18a891 Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Sun, 10 Dec 2017 16:13:09 +1030 Subject: added direct blog link to posts --- generatesite.py | 22 ++++++++++++++++------ settings.cfg | 2 ++ setup.sh | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/generatesite.py b/generatesite.py index 38e2cbc..6e827e5 100644 --- a/generatesite.py +++ b/generatesite.py @@ -71,10 +71,12 @@ def generateblog(): template = cfg.get("output", "template"); outdir = cfg.get("output", "dir"); blogdir = cfg.get("blog", "dir"); + directdir = cfg.get("blog", "direct"); blogsrc = cfg.get("blog", "srcdir"); perpage = cfg.get("blog", "perpage"); print("generating {}/{}/ from directory /{}/final".format(outdir, blogdir, blogsrc)); os.makedirs(outdir + "/" + blogdir, exist_ok=True); + os.makedirs(outdir + "/" + blogdir + "/" + directdir, exist_ok=True); os.makedirs(blogsrc + "/final", exist_ok=True); # number of blog posts postcount = len(glob.glob1(blogsrc, "*.txt")); @@ -114,7 +116,7 @@ def generateblog(): if count < postcount + 1: with open(blogsrc + "/final/" + str(x) + ".txt") as contentfile: content = contentfile.read(); - page += "
#" + str(total_count) + "" + content + "

"; + page += "
direct link" + content + "

"; count += 1; total_count -= 1; if cpage <= pagecount: @@ -123,11 +125,19 @@ def generateblog(): replace(outdir + "/" + blogdir + "/" + str(cpage) + ".html", "{CONTENT}", page); page = ""; cpage += 1; - ''' - for x in range(1, postcount + 1): - with open(blogsrc + "/" + str(x) + ".txt", "r") as t: - print(t.read()); - ''' + # generate /direct/ pages + for x in range(1, int(postcount) + 1): + copyfile(template, outdir + "/" + blogdir + "/" + directdir + "/" + str(x) + ".html"); + replace(outdir + "/" + blogdir + "/" + directdir + "/" + str(x) + ".html", "{TITLE}", cfg.get("blog", "title")); + replace(outdir + "/" + blogdir + "/" + directdir + "/" + str(x) + ".html", "{INFO}", cfg.get("blog", "header")); + replace(outdir + "/" + blogdir + "/" + directdir + "/" + str(x) + ".html", "{TIME}", strftime("%Y-%m-%d %H:%M:%S", gmtime())); + with open(blogsrc + "/" + str(x) + ".txt") as contentfile: + content = contentfile.read(); + replace(outdir + "/" + blogdir + "/" + directdir + "/" + str(x) + ".html", "{CONTENT}", content); + replace(outdir + "/" + blogdir + "/" + directdir + "/" + str(x) + ".html", "media/", "../media/"); + + + def generateanime(): template = cfg.get("output", "template"); diff --git a/settings.cfg b/settings.cfg index 79a0388..78e207c 100644 --- a/settings.cfg +++ b/settings.cfg @@ -14,6 +14,8 @@ title = daniel's blog header =

Blog

Rambles about myself and programming

Comments welcome - comments@danieljon.es

# blog directory dir = blog +# direct link directory +direct = direct srcdir = content/blog # number of posts per page perpage = 7 diff --git a/setup.sh b/setup.sh index 06d464f..f74555b 100755 --- a/setup.sh +++ b/setup.sh @@ -1,6 +1,7 @@ # directories mkdir output/ mkdir output/blog/ +mkdir output/blog/direct mkdir output/viewings/ mkdir output/waifus/ mkdir content/ -- cgit v1.2.3