diff options
-rw-r--r-- | generatesite.py | 59 | ||||
-rw-r--r-- | settings.cfg | 8 | ||||
-rw-r--r-- | template.txt | 11 | ||||
-rw-r--r-- | template_original.txt | 36 |
4 files changed, 110 insertions, 4 deletions
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 + "<hr>"; + 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 = <h1>Blog</h1> Rambles about myself and programming <br> <br> dir = blog srcdir = content/blog # number of posts per page +perpage = 7 +[shows] +title = viewings +header = <h1>Shows I have watched</h1> +# 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 @@ <meta name="description" content="Personal blog/portfolio/site for Daniel Jones"> <meta name="author" content="Daniel Jones"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> +<meta http-equiv="Cache-control" content="public"> <link rel="icon" type="image/png" href="https://danieljon.es/favicon.png"> <title>{TITLE}</title> <style type="text/css"> -body{background-color:#222; color: #eee;} +/*body{background-color:#222; color: #eee; margin-right: 20px; margin-left: 20px;} +div{background-color: #202020 !important;} a:link{color: #3F51B5;} a:visited{#3F51B5;} -img{max-width: 100%; max-height: 100%; overflow: hidden;} +img{max-width: 100%; max-height: 100%; overflow: hidden;} */ .middle{text-align: center;} -#gentag{text-align: center; font-size: 75%;} +/*#gentag{text-align: center; font-size: 75%;} +h1,h2,h3,h4 {background-color: black !important; color: #e02020 !important;} */ </style> </head> <body> <div class="middle"> -<h1>danieljon.es</h1> + <h1>danieljon.es</h1>free of native javascript, made with terminals in mind.<br><br> <a href="https://danieljon.es">index</a> <a href="https://danieljon.es/blog">blog</a> <a href="https://danieljon.es/portfolio.html">portfolio</a> <br> <br> <a href="https://reddit.com/u/daniel_j-">reddit</a> <a href="https://steamcommunity.com/id/imnotstraightatall/">steam</a> 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 @@ +<!DOCTYPE html> +<html lang="en"> +<head> +<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> +<meta name="keywords" content="Programming, C++, C, Blog"> +<meta name="description" content="Personal blog/portfolio/site for Daniel Jones"> +<meta name="author" content="Daniel Jones"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<meta http-equiv="Cache-control" content="public"> +<link rel="icon" type="image/png" href="https://danieljon.es/favicon.png"> +<title>{TITLE}</title> +<style type="text/css"> +body{background-color:#222; color: #eee; margin-right: 20px; margin-left: 20px;} +div{background-color: #202020 !important;} +a:link{color: #3F51B5;} +a:visited{#3F51B5;} +img{max-width: 100%; max-height: 100%; overflow: hidden;} +.middle{text-align: center;} +#gentag{text-align: center; font-size: 75%;} +h1,h2,h3,h4 {background-color: black !important; color: #e02020 !important;} +</style> +</head> + +<body> +<div class="middle"> + <h1>danieljon.es</h1>free of native javascript, made with terminals in mind.<br><br> +<a href="https://danieljon.es">index</a> <a href="https://danieljon.es/blog">blog</a> <a href="https://danieljon.es/portfolio.html">portfolio</a> <br> <br> +<a href="https://reddit.com/u/daniel_j-">reddit</a> +<a href="https://steamcommunity.com/id/imnotstraightatall/">steam</a> +<a href="https://github.com/daniel-Jones">github</a> +{INFO} +</div> +{CONTENT} +<br> <br> <div id="gentag">page generated on {TIME} using <a href="https://github.com/daniel-Jones/sitegenerator">sitegenerator</a></div> +</body> +</html> |