96 lines
8.9 KiB
Python
96 lines
8.9 KiB
Python
import secrets
|
||
import orgparse,os,re
|
||
from datetime import datetime
|
||
|
||
thisyear = datetime.now().strftime("%Y")
|
||
|
||
year = 1993
|
||
|
||
concernedfiles = []
|
||
|
||
while year < int(thisyear) + 1:
|
||
month = 0
|
||
while month < 13:
|
||
if month < 10:
|
||
strmonth = "0" + str(month)
|
||
else:
|
||
strmonth = str(month)
|
||
recdir = str(year) + "/" + strmonth + "/"
|
||
fullpath = secrets.orgpath + recdir
|
||
if os.path.exists(fullpath):
|
||
for file in sorted(os.listdir(fullpath)):
|
||
filename = fullpath + str(file)
|
||
if filename.endswith(".org"):
|
||
concernedfiles.append(filename)
|
||
month = month + 1
|
||
year = year + 1
|
||
|
||
posts = []
|
||
|
||
for file in concernedfiles:
|
||
filedate = file[-14:-4]
|
||
parsefile = orgparse.load(file)
|
||
try:
|
||
for node in parsefile.children:
|
||
if node.heading == "site":
|
||
for post in node.children:
|
||
if "post" in post.tags:
|
||
writefile = open(filedate + ".org","w")
|
||
writefile.write("#+TITLE: " + post.heading + "\n#+REALTITLE: " + post.properties["realtitle"] + "\n#+OGDESC: " + post.properties["ogdesc"]+ "\n#+CATEGORY: " + post.properties["category"] + "\n#+COMMENTS: " + post.properties["comments"] + "\n" + post.get_body(format="raw") + "\n")
|
||
try:
|
||
for child in post.children:
|
||
if "noexport" not in child.tags:
|
||
if child.heading == "yes":
|
||
writefile.write("\n")
|
||
else:
|
||
writefile.write("* " + child.heading + "\n")
|
||
writefile.write(child.get_body(format="raw") + "\n")
|
||
except:
|
||
pass
|
||
writefile.close()
|
||
thedict = {}
|
||
thedict["real"] = post.properties["realtitle"]
|
||
thedict["date"] = filedate
|
||
if post.properties["category"] == "reminding myself how to do stuff":
|
||
thedict["category"] = "techbro"
|
||
elif post.properties["category"] == "writing notes":
|
||
thedict["category"] = "writing"
|
||
elif post.properties["category"] == "journal memes":
|
||
thedict["category"] = "meme"
|
||
elif post.properties["category"] == "revues":
|
||
thedict["category"] = "revue"
|
||
else:
|
||
thedict["category"] = post.properties["category"]
|
||
try:
|
||
thedict["media"] = post.properties["type"]
|
||
except:
|
||
pass
|
||
posts.append(thedict)
|
||
except:
|
||
pass
|
||
|
||
posts = sorted(posts,key=lambda d: d["date"],reverse=True)
|
||
|
||
writeindex = open("build/index.html","w")
|
||
|
||
writeindex.write("<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<title>praze • Notes</title>\n<meta property=\"og:title\" content=\"praze • Notes\">\n<meta property=\"og:type\" content=\"website\">\n<meta property=\"og:image\" content=\"https://tre.praze.net/ab.png\">\n<meta property=\"og:url\" content=\"https://tre.praze.net/notes\">\n<meta name=\"description\" property=\"og:description\" content=\"Index of notes.\">\n<meta property=\"og:locale\" content=\"en_GB\">\n<meta property=\"og:site_name\" content=\"tre.praze.net\">\n<meta name=\"fediverse:creator\" content=\"@tre@praze.net\">\n<link rel=\"stylesheet\" href=\"/new.css\">\n<link rel=\"me\" href=\"https://kes.praze.net/@tre\">\n<link rel=\"alternate\" type=\"application/rss+xml\" title=\"tre.praze.net\" href=\"/feed.xml\">\n<meta name=\"theme-color\" content=\"#f2f2f2\" />\n<style>\nli:has(a[href=\"\"]) {\ndisplay: none;\n}\n\n[value=\"meme\"]:checked ~ ul#noteslist li[data-category=\"meme\"],\n[value=\"month\"]:checked ~ ul#noteslist li[data-category=\"month\"],\n[value=\"techbro\"]:checked ~ ul#noteslist li[data-category=\"techbro\"],\n[value=\"revue\"]:checked ~ ul#noteslist li[data-category=\"revue\"],\n[value=\"writing\"]:checked ~ ul#noteslist li[data-category=\"writing\"]\n{\ndisplay:list-item;\n}\n\n[value=\"meme\"]:not(:checked) ~ ul#noteslist li[data-category=\"meme\"],\n[value=\"month\"]:not(:checked) ~ ul#noteslist li[data-category=\"month\"],\n[value=\"techbro\"]:not(:checked) ~ ul#noteslist li[data-category=\"techbro\"],\n[value=\"revue\"]:not(:checked) ~ ul#noteslist li[data-category=\"revue\"],\n[value=\"writing\"]:not(:checked) ~ ul#noteslist li[data-category=\"writing\"]\n{\ndisplay: none;\n}\n\nul#noteslist li:first-of-type a:before {\ncontent: \"✨ \";\n}\n\nmain label:after {\ncontent: \"\A\";\nwhite-space: pre;\n}\n</style>\n</head>\n<body>\n<nav>\n<input type=\"checkbox\" id=\"toggle\" name=\"toggle\">\n<label class=\"toggle-btn\" for=\"toggle\">Menu</label>\n<ul>\n<li>Fundamentals\n<ul>\n<li><a href=\"/\">Home</a></li>\n<li><a href=\"/about\">About + listings</a></li>\n<li><a href=\"/follow\">Follow</a></li>\n<li><a href=\"/feed.xml\">Changelog</a> <a href=\"/feed.xml\"><span class=\"rss\"></span></a></li>\n<li><a href=\"/sitemap.xml\">Sitemap</a></li>\n<li><a href=\"/siteroll\">Siteroll</a></li>\n</ul>\n</li>\n<li>Projects\n<ul>\n<li><a href=\"/fic\">Fanfiction</a> <a href=\"/fic/feed.xml\"><span class=\"rss\"></span></a></li>\n<li><a href=\"/music\">Music</a></li>\n<li>Journal</li>\n<li><a href=\"/trackers\">Trackers</a></li>\n<li><a href=\"https://git.praze.net/tre\" target=\"_blank\">Code</a> <a href=\"https://git.praze.net/tre.rss\"><span class=\"rss\"></span></a></li>\n<li><a href=\"https://img.praze.net\" target=\"_blank\">Photos</a> <a href=\"https://img.praze.net/feed.php\"><span class=\"rss\"></span></a></li>\n</ul>\n</li>\n<li>Fan content\n<ul>\n<li><a href=\"/ffx\">FFX</a></li>\n<li><a href=\"/xvi\">FF16</a></li>\n<li><a href=\"https://morgan.praze.net\" target=\"_blank\">Dermot Morgan</a> <a href=\"https://morgan.praze.net/feed.xml\"><span class=\"rss\"></span></a></li>\n</ul>\n</li>\n<li>Misc.\n<ul>\n<li><a href=\"https://tcg.praze.net\" target=\"_blank\">TCG</a></li>\n<li><a href=\"https://links.praze.net\" target=\"_blank\">Bookmarks</a> <a href=\"https://links.praze.net/feed/rss\"><span class=\"rss\"></span></a></li>\n<li><a href=\"https://kes.praze.net/@tre\" target=\"_blank\">Fediverse</a> <a href=\"https://kes.praze.net/@tre/feed.rss\"><span class=\"rss\"></span></a></li>\n</ul>\n</li>\n</ul>\n</nav>\n<div>\n<main>\n<section>\n<h1>Notes</h1>\n<p>This is the part of the site where I post long-ish-form writing I seem to have the embarrassing need to share … I guess you’d call it a blog.</p>\n<p>Posts are listed in reverse chronological order. Please be aware of posting dates – my opinions are constantly changing and evolving, and the longer ago something was written, the more likely it is that I’ll have since come to disagree with it completely … or in the case of more technical stuff, details may simply be out of date.</p>\n<p>Some of these posts were originally made on a now-deleted Dreamwidth account. Toggle the boxes to show/hide posts in the relevant category.</p>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"meme\" value=\"meme\" checked>\n<label for=\"meme\">Journal memes</label>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"month\" value=\"month\" checked>\n<label for=\"month\">Monthly roundup</label>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"techbro\" value=\"techbro\" checked>\n<label for=\"techbro\">Reminding myself how to do stuff</label>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"revue\" value=\"revue\" checked>\n<label for=\"revue\">Revues</label>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"writing\" value=\"writing\" checked>\n<label for=\"writing\">Writing notes</label>\n<ul id=\"noteslist\">\n")
|
||
|
||
for post in posts:
|
||
poststring = "<li data-category=\"" + post["category"] + "\"><code>" + post["date"] + "</code> <a href=\"/notes/" + post["date"].replace("-","") + "\">"
|
||
try:
|
||
if post["media"] == "book":
|
||
poststring += "📚 "
|
||
elif post["media"] == "game":
|
||
poststring += "🎮 "
|
||
elif post["media"] == "music":
|
||
poststring += "🎵 "
|
||
elif post["media"] == "sight":
|
||
poststring += "🔭 "
|
||
except:
|
||
pass
|
||
poststring += post["real"] + "</a></li>\n"
|
||
writeindex.write(poststring)
|
||
|
||
writeindex.write("</ul>\n</section>\n</main>\n<footer>\n<ul>\n<li><a href=\"/\">home</a></li>\n</ul>\n</footer>\n</div>\n<a href=\"/\"><img src=\"/a.png\" style=\"position:fixed;bottom:2px;right:2px;\" title=\"home\"></a>\n</body>\n</html>\n")
|
||
|
||
writeindex.close()
|