From 3ff092f1257952b910987d5c36deea3b15abf726 Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Thu, 9 Nov 2017 10:57:23 +1100 Subject: plenty of changes, new template. I don't really know what is here, it has been so long. --- generatesite.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ settings.cfg | 8 +++++++ template.txt | 11 ++++++---- template_original.txt | 36 +++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 template_original.txt diff --git a/generatesite.py b/generatesite.py index 1851658..e923851 100644 --- a/generatesite.py +++ b/generatesite.py @@ -132,6 +132,64 @@ def generateblog(): print(t.read()); ''' +def generateshows(): + cpage = 0; + template = cfg.get("output", "template"); + outdir = cfg.get("output", "dir"); + blogdir = cfg.get("shows", "dir"); + blogsrc = cfg.get("shows", "srcdir"); + perpage = cfg.get("shows", "perpage"); + print("generating {}/{}/ from directory /{}/final".format(outdir, blogdir, blogsrc)); + os.makedirs(outdir + "/" + blogdir, exist_ok=True); + os.makedirs(blogsrc + "/final", exist_ok=True); + # number of blog posts + postcount = len(glob.glob1(blogsrc, "*.txt")); + pagecount = postcount/int(perpage)+1; + print("{} posts, {} per page = {} pages".format(postcount, perpage, int(pagecount))); + folder = outdir + "/" + blogdir; + # delete generated blog files + deletefiles(outdir + "/" + blogdir); + # delete renamed blog files + deletefiles(blogsrc + "/final"); + ''' + copy our blog posts to blogsrc/final, rename them, 60 becomes 1, 59 becomes 2 etc + this is done because I am extremely lazy and had troubles doing it any other way. + sorry if you're reading this. + ''' + #integrate this with the loop below it? + count = 1; + for x in range(int(postcount), 0, -1): + copyfile(blogsrc + "/" + str(x) + ".txt", blogsrc + "/final/" + str(count) + ".txt"); + count += 1; + # generate pages + for x in range(1, int(pagecount) + 1): + copyfile(template, outdir + "/" + blogdir + "/" + str(x) + ".html"); + with open(outdir + "/" + blogdir + "/" + str(x) + ".html", "r") as contentfile: + content = contentfile.read().replace('\n', ''); + replace(outdir + "/" + blogdir + "/" + str(x) + ".html", "{TITLE}", cfg.get("blog", "title")); + replace(outdir + "/" + blogdir + "/" + str(x) + ".html", "{INFO}", "Blog"); + replace(outdir + "/" + blogdir + "/" + str(x) + ".html", "{TIME}", strftime("%Y-%m-%d %H:%M:%S", gmtime())); + # place blog posts into their pages + count = 1; + cpage = 1; + page = ""; + total_count = postcount; + # count from 1 - perpage, add perpage to count, count from count - count + perpage + while count < postcount + 1: + for x in range(count, count + int(perpage)): + if count < postcount + 1: + with open(blogsrc + "/final/" + str(x) + ".txt") as contentfile: + content = contentfile.read(); + page += "#" + str(total_count) + content + "
"; + count += 1; + total_count -= 1; + if cpage <= pagecount: + page += generatepagebar(str(cpage), str(int(pagecount))); + page = generatepagebar(str(cpage), str(int(pagecount))) + page; + replace(outdir + "/" + blogdir + "/" + str(cpage) + ".html", "{CONTENT}", page); + page = ""; + cpage += 1; + if __name__ == "__main__": cfg = configparser.ConfigParser(); cfg.read("settings.cfg"); @@ -139,3 +197,4 @@ if __name__ == "__main__": generateindex(); generateblog(); generateportfolio(); + #generateshows(); diff --git a/settings.cfg b/settings.cfg index f3446b5..e2e7ece 100644 --- a/settings.cfg +++ b/settings.cfg @@ -16,4 +16,12 @@ header =

Blog

Rambles about myself and programming

dir = blog srcdir = content/blog # number of posts per page +perpage = 7 +[shows] +title = viewings +header =

Shows I have watched

+# shows directory +dir = shows +srcdir = content/shows +# number of posts per page perpage = 5 diff --git a/template.txt b/template.txt index 8fd03a9..6099095 100644 --- a/template.txt +++ b/template.txt @@ -6,21 +6,24 @@ + {TITLE}
-

danieljon.es

+

danieljon.es

free of native javascript, made with terminals in mind.

index blog portfolio

reddit steam diff --git a/template_original.txt b/template_original.txt new file mode 100644 index 0000000..54e4f1e --- /dev/null +++ b/template_original.txt @@ -0,0 +1,36 @@ + + + + + + + + + + +{TITLE} + + + + +
+

danieljon.es

free of native javascript, made with terminals in mind.

+index blog portfolio

+reddit +steam +github +{INFO} +
+{CONTENT} +

page generated on {TIME} using sitegenerator
+ + -- cgit v1.2.3