diff --git a/.gitignore b/.gitignore index 650692f..b951b27 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *.db *.html +config.toml + templates/* diff --git a/blahblah/__pycache__/main.cpython-314.pyc b/blahblah/__pycache__/main.cpython-314.pyc index afbc2cf..174b272 100644 Binary files a/blahblah/__pycache__/main.cpython-314.pyc and b/blahblah/__pycache__/main.cpython-314.pyc differ diff --git a/blahblah/__pycache__/render.cpython-314.pyc b/blahblah/__pycache__/render.cpython-314.pyc new file mode 100644 index 0000000..06e906a Binary files /dev/null and b/blahblah/__pycache__/render.cpython-314.pyc differ diff --git a/blahblah/main.py b/blahblah/main.py index 442f31e..ef806a6 100644 --- a/blahblah/main.py +++ b/blahblah/main.py @@ -1,4 +1,4 @@ -from blahblah import bbdb +from blahblah import bbdb, render import tempfile import subprocess import os @@ -167,6 +167,8 @@ if __name__ == "__main__": confirmDelete(db) elif choice == 'l' or choice == 'L' or choice == "4": listPosts(db) + elif choice == 'g' or choice == 'G' or choice == "5": + render.generateBodies(db) db.close() diff --git a/blahblah/render.py b/blahblah/render.py index 74d0bc7..5daa8b9 100644 --- a/blahblah/render.py +++ b/blahblah/render.py @@ -1,3 +1,62 @@ import markdown +import toml +from jinja2 import Environment, PackageLoader +from blahblah import bbdb +from datetime import datetime + +env = Environment( loader = PackageLoader("blahblah") ) + +rollTemplate = env.get_template("roll_template.html.jinja") +postTemplate = env.get_template("post_template.html.jinja") + +with open('config.toml', 'r') as f: + config = toml.load(f) +def generateBodies(db): + postCount = 0 + blogRoll = [] + blobStack = "" + for p in bbdb.getAllPosts(db): + if p["title"] != None: + newPost = '
' + newPost = newPost + "

" + p["title"] + "


" + else: + newPost = '
' + + bodyText = p["body"] + + if len(bodyText) > 512: + formattedBody = bodyText[0:512] + # formattedBody = markdown.markdown(formattedBody) + # bodyText = markdown.markdown(bodyText) + else: + formattedBody = bodyText + + formattedBody = markdown.markdown(formattedBody) + bodyText = markdown.markdown(bodyText) + + #newPost = newPost + formattedBody + + #newPost = newPost + "
" + + with open("./blog/posts/" + str(p["id"]) + ".html", "w") as f: + singlePost = newPost + bodyText + singlePost = singlePost + '
' + f.write(postTemplate.render(webRoot=config['server']['document_root'], blogContent=singlePost, siteCopyright=config['server']['copyright_holder'])) + + ts = p["timestamp"] / 1000 + newPost = newPost + formattedBody + newPost = newPost + '

' + datetime.fromtimestamp(ts).strftime('%B %-d, %Y ') + newPost = newPost + '' + newPost = newPost + 'permalink

' + blogRoll.append(newPost) + + postCount += 1 + + if postCount < config['formatting']['post_per_page']: + for p in blogRoll: + blobStack = blobStack + p + + with open("./blog/index.html", "w") as f: + f.write(rollTemplate.render(webRoot=config['server']['document_root'], blogContent=blobStack, siteCopyright=config['server']['copyright_holder'])) diff --git a/blahblah/templates/post_template.html.jinja b/blahblah/templates/post_template.html.jinja new file mode 100644 index 0000000..175c32f --- /dev/null +++ b/blahblah/templates/post_template.html.jinja @@ -0,0 +1,36 @@ + + + + + {{ siteCopyright }} + + + + +
+
+

{{ siteCopyright }} dot com

+
+ +
+
+ {{ blogContent }} + +
+ +
+
+

Copyright 2026 {{ siteCopyright }}

+
+
+ + diff --git a/blahblah/templates/roll_template.html.jinja b/blahblah/templates/roll_template.html.jinja new file mode 100644 index 0000000..780529b --- /dev/null +++ b/blahblah/templates/roll_template.html.jinja @@ -0,0 +1,33 @@ + + + + + {{ siteCopyright }}'s Blog + + + + +
+
+

{{ siteCopyright }} dot com

+
+ +
+
+ {{ blogContent }} +
+ +
+
+

Copyright 2026 {{ siteCopyright }}

+
+
+ + diff --git a/blog. b/blog. deleted file mode 100644 index e69de29..0000000 diff --git a/example.toml b/example.toml new file mode 100644 index 0000000..509cbf8 --- /dev/null +++ b/example.toml @@ -0,0 +1,10 @@ +#Change the name of this file to config.toml! + +title = " blahblah config example -- rename me 'config.toml' " + +[server] +document_root = "https://mysite.com" +copyright_holder = "Suzy Greenberg" + +[formatting] +post_per_page = 25