summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md29
-rw-r--r--generatesite.py168
-rwxr-xr-xlive.sh3
-rw-r--r--settings.cfg30
-rwxr-xr-xsetup.sh25
-rw-r--r--template.txt35
-rw-r--r--template_original.txt36
7 files changed, 326 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5b2aaaf
--- /dev/null
+++ b/README.md
@@ -0,0 +1,29 @@
+# sitegenerator
+static site generator for my website/blog/portfolio at https://danieljon.es
+# why?
+My website previously relied heavily on php/databases and didn't render correctly inside my terminal web browser so I decided to take the static, html only route and created a static website generator.
+# how do I use it?
+I've created the setup.sh script, it will generate everything you need to get a minimal website up with a few example blog posts, anime recommendation of k-on, nico as your waifu and two sample projects in your portfolio.
+```
+Run ./setup.sh once.
+then everytime you update the site run:
+python3 generatesite.py && cp -r output/* /var/www #or where ever your root dir is
+```
+Once ./setup.sh has been run once the directory named 'content' hosts all the website data. In it you'll find a directory for the blog in which each post is a .txt file counting up (1.txt is the first post). It's pretty self explanatory.
+
+# settings.cfg?
+This file contains various settings you can change including the number of blog posts per page, titles, content locations, blog directory etc. Play with these if you want.
+
+# .htaccess for blog?
+I use the following as my .htaccees for /blog, it makes /blog go to blog/1, /1 translates to 1.html etc:
+
+```
+Options +SymLinksIfOwnerMatch
+Order Allow,Deny
+Allow from all
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule ^([A-Za-z0-9-]+)/?$ $1.html [NC,QSA]
+DirectoryIndex 1.html
+```
diff --git a/generatesite.py b/generatesite.py
new file mode 100644
index 0000000..38e2cbc
--- /dev/null
+++ b/generatesite.py
@@ -0,0 +1,168 @@
+#!/usr/bin/env python3
+
+'''
+script to auto-generate my static website/blog/portfolio @ https://danieljon.es
+'''
+
+import configparser;
+import errno;
+import os;
+import glob;
+from shutil import copyfile;
+from tempfile import mkstemp;
+from shutil import move;
+from os import fdopen, remove;
+from time import gmtime, strftime;
+
+def replace(file_path, pattern, subst):
+ fh, abs_path = mkstemp();
+ with fdopen(fh, "w") as new_file:
+ with open(file_path) as old_file:
+ for line in old_file:
+ new_file.write(line.replace(pattern, subst));
+ remove(file_path);
+ move(abs_path, file_path);
+
+def generateindex():
+ template = cfg.get("output", "template");
+ outdir = cfg.get("output", "dir");
+ indexsrc = cfg.get("index", "src");
+ print("generating {}/index.html from {}".format(outdir, indexsrc));
+ copyfile(template, outdir + "/index.html");
+ with open(indexsrc, "r") as contentfile:
+ content = contentfile.read();
+ replace(outdir + "/index.html", "{TITLE}", cfg.get("index", "title"));
+ replace(outdir + "/index.html", "{INFO}", cfg.get("index", "header"));
+ replace(outdir + "/index.html", "{CONTENT}", content);
+ replace(outdir + "/index.html", "{TIME}", strftime("%Y-%m-%d %H:%M:%S", gmtime()));
+
+def generatepagebar(currentpage, pagecount):
+ print("generating page bar for {} total {}".format(currentpage, pagecount));
+ pages = "<div class='middle'> <a href='" + str(pagecount if int(currentpage) == 1 else int(currentpage)-1) + "'>prev</a> ";
+ for x in range(1, int(pagecount)+1):
+ if x == int(currentpage):
+ pages += "<strong><i><a href=" + str(x) + ">" + str(x) + "</a></i></strong> ";
+ else:
+ pages += "<a href=" + str(x) + ">" + str(x) + "</a> ";
+ pages += "<a href='" + str(1 if currentpage == pagecount else int(currentpage)+1) + "'>next</a></div>";
+ return pages;
+
+def generateportfolio():
+ template = cfg.get("output", "template");
+ outdir = cfg.get("output", "dir");
+ portfoliosrc = cfg.get("portfolio", "src");
+ print("generating {}/portfolio.html from {}".format(outdir, portfoliosrc));
+ copyfile(template, outdir + "/portfolio.html");
+ with open(portfoliosrc, "r") as contentfile:
+ content = contentfile.read();
+ replace(outdir + "/portfolio.html", "{TITLE}", cfg.get("portfolio", "title"));
+ replace(outdir + "/portfolio.html", "{INFO}", cfg.get("portfolio", "header"));
+ replace(outdir + "/portfolio.html", "{CONTENT}", content);
+ replace(outdir + "/portfolio.html", "{TIME}", strftime("%Y-%m-%d %H:%M:%S", gmtime()));
+
+def deletefiles(ddir):
+ # delete all blog files
+ for the_file in os.listdir(ddir):
+ file_path = os.path.join(ddir, the_file)
+ if os.path.isfile(file_path):
+ os.unlink(file_path);
+
+def generateblog():
+ template = cfg.get("output", "template");
+ outdir = cfg.get("output", "dir");
+ blogdir = cfg.get("blog", "dir");
+ 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(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}", cfg.get("blog", "header"));
+ 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 += "<div id='" + str(total_count) + "'> <a href='" + str(cpage) + ".html#" + str(total_count) + "'>#" + str(total_count) + "</a>" + content + "</div><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;
+ '''
+ for x in range(1, postcount + 1):
+ with open(blogsrc + "/" + str(x) + ".txt", "r") as t:
+ print(t.read());
+ '''
+
+def generateanime():
+ template = cfg.get("output", "template");
+ outdir = cfg.get("output", "dir");
+ animesrc = cfg.get("anime", "src");
+ animedir = cfg.get("anime", "dir");
+ print("generating {}/{}/index.html from {}".format(outdir, animedir, animesrc));
+ copyfile(template, outdir + "/" + animedir + "/index.html");
+ with open(animesrc, "r") as contentfile:
+ content = contentfile.read();
+ replace(outdir + "/" + animedir + "/index.html", "{TITLE}", cfg.get("anime", "title"));
+ replace(outdir + "/" + animedir + "/index.html", "{INFO}", cfg.get("anime", "header"));
+ replace(outdir + "/" + animedir + "/index.html", "{CONTENT}", content);
+ replace(outdir + "/" + animedir + "/index.html", "{TIME}", strftime("%Y-%m-%d %H:%M:%S", gmtime()));
+
+def generatewaifus():
+ template = cfg.get("output", "template");
+ outdir = cfg.get("output", "dir");
+ waifussrc = cfg.get("waifus", "src");
+ waifusdir = cfg.get("waifus", "dir");
+ print("generating {}/{}/index.html from {}".format(outdir, waifusdir, waifussrc));
+ copyfile(template, outdir + "/" + waifusdir + "/index.html");
+ with open(waifussrc, "r") as contentfile:
+ content = contentfile.read();
+ replace(outdir + "/" + waifusdir + "/index.html", "{TITLE}", cfg.get("waifus", "title"));
+ replace(outdir + "/" + waifusdir + "/index.html", "{INFO}", cfg.get("waifus", "header"));
+ replace(outdir + "/" + waifusdir + "/index.html", "{CONTENT}", content);
+ replace(outdir + "/" + waifusdir + "/index.html", "{TIME}", strftime("%Y-%m-%d %H:%M:%S", gmtime()));
+
+if __name__ == "__main__":
+ cfg = configparser.ConfigParser();
+ cfg.read("settings.cfg");
+ os.makedirs(cfg.get("output", "dir"), exist_ok=True);
+ generateindex(); # index
+ generateblog(); # blog with individual pages
+ generateportfolio(); # portfolio
+ generateanime(); # anime recommendations
+ generatewaifus(); # my waifus
diff --git a/live.sh b/live.sh
new file mode 100755
index 0000000..f1ffecb
--- /dev/null
+++ b/live.sh
@@ -0,0 +1,3 @@
+python3 generatesite.py
+
+cp -r output/* /var/www
diff --git a/settings.cfg b/settings.cfg
new file mode 100644
index 0000000..79a0388
--- /dev/null
+++ b/settings.cfg
@@ -0,0 +1,30 @@
+[output]
+template = template.txt
+dir = output
+[index]
+title = index
+header = <h1>Index</h1>
+src = content/index.txt
+[portfolio]
+title = daniel's portfolio
+header = <h1>Portfolio</h1>
+src = content/portfolio.txt
+[blog]
+title = daniel's blog
+header = <h1>Blog</h1> Rambles about myself and programming <br><br> Comments welcome - comments@danieljon.es<br><br>
+# blog directory
+dir = blog
+srcdir = content/blog
+# number of posts per page
+perpage = 7
+[anime]
+title = anime
+header = <h1>Anime I recommend</h1>This list is forever incomplete, I have watched and recommend a lot more.
+dir = viewings
+src = content/viewings/index.txt
+[waifus]
+title = waifus
+header = <h1>My waifus, not yours</h1>All other waifus are literal trash
+dir = waifus
+src = content/waifus/index.txt
+
diff --git a/setup.sh b/setup.sh
new file mode 100755
index 0000000..06d464f
--- /dev/null
+++ b/setup.sh
@@ -0,0 +1,25 @@
+# directories
+mkdir output/
+mkdir output/blog/
+mkdir output/viewings/
+mkdir output/waifus/
+mkdir content/
+mkdir content/blog/
+mkdir content/blog/final/
+mkdir content/viewings/
+mkdir content/waifus/
+
+# files
+# make content/index.txt
+echo "This is your index file!<br><br>Do whatever here." > content/index.txt
+#make content/portfolio.txt
+echo "This is my first project, find the link <a href=''>here</a>.<br><br><hr>This is my second project, find the link <a href=''>here</a>."> content/portfolio.txt
+#make content/blog/1.txt
+echo "<h1>First blog post title</h1> <h3>11/22/3333</h3> <p> blog content here!" > content/blog/1.txt
+#make content/blog/2.txt
+echo "<h1>Second blog post title</h1> <h3>11/23/3333</h3> <p> blog content here!" > content/blog/2.txt
+#make content/waifu/index.txt
+echo "<div class='cover'><img src='https://danieljon.es/waifus/media/nico.png' alt='Nico Yazawa'></div><div class='viewing'><h3>Nico Yazawa</h3>Nico's better-than-you nature and <a href='https://danieljon.es/nico'>awesome idol skill</a> makes her the perfect number one waifu. Seriously, she has it all, great looks, <a href='https://www.youtube.com/watch?v=xX050NcDNAU'>flat-as-a-pancake</a> physique and <a href='https://www.youtube.com/watch?v=T4iC52d-fVY'>the bestest catchphrase</a> ever." > content/waifus/index.txt
+#make content/viewings/index.txt
+echo "<div class='middiv'><div class='cover'><img src='https://danieljon.es/viewings/media/kon1_cover.jpg' alt='k-on! cover'></div><div class='viewing'><h3>K-On!</h3>K-On I believe was the first anime I had ever watched while not a little kid (those were cartoons, but some technically anime) and definitely was a big part in introducing me to the 'cute girls doing cute things' genre, which to this day is my most viewed and enjoyed. <br><br>The story revolves around four (later five) girls entering highschool and selecting to join the 'light music' club, that members of that club had all graduated the prior year, so they were entirely on their own. They were to eventually form a band, write and create songs that they performed at various venues. However, really it's all about the girls eating snacks and having whacky fun. <br><br>The <a href='https://www.youtube.com/watch?v=TIpA_B5khZc'>OP of K-On!</a> is one I think I will never skip, it's so energetic and fun, definitely worth a watch if you haven't seen it. The ED wasn't anything spectacular music wise, but the art was great.</div></div>" > content/viewings/index.txt
+
diff --git a/template.txt b/template.txt
new file mode 100644
index 0000000..26bf722
--- /dev/null
+++ b/template.txt
@@ -0,0 +1,35 @@
+<!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{margin-right: 20px; margin-left: 20px; font-family: Verdana}
+img{max-width: 100%; max-height: 100%; overflow: hidden;}
+.middle{text-align: center;}
+.middiv{margin: auto; width: 80%;}
+#gentag{text-align: center; font-size: 75%;}
+h1,h2,h3,h4{padding-left: 5px; !important;}
+div.viewing{max-width: 70%; width: 100%; display: inline-block; margin: 10px;}
+div.cover{display:inline-block; vertical-align: top; padding-top: 28px; padding-left: 15px; padding-bottom: 20px;}
+</style>
+</head>
+<body>
+<div class="middle">
+<h1>danieljon.es</h1>free of Javascript, minimal CSS.<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 {TIME} using <a href="https://github.com/daniel-Jones/sitegenerator">sitegenerator</a></div>
+</body>
+</html>
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>