import os import re import pypandoc import frontmatter import dateutil.parser import pandas as pd from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter print("clearing old dir...") os.system("rm -r ./static/") os.system("mkdir ./static/") os.system("cp *.csv ./static/") os.system("cp -r ./assets/ ./static/assets/") print("loadin header") with open("header.html", "r") as f: header = f.read() def write_md_to_html(md, dest): with open(dest, "w") as f: f.write("\n\n") f.write(header) ticks = [(m.start(), m.group(1)) for m in re.finditer(r"\n```(\w+)?\n", md)] replacements = [] for i in range(0,len(ticks),2): try: j1, j2 = ticks[i][0], ticks[i+1][0] lang = ticks[i][1] if lang == "lean4": lang = "lean" code = md[j1:j2] + "\n```\n" code_pretty = highlight(code[(len(lang)+5):-4], get_lexer_by_name(lang), HtmlFormatter()) replacements.append((code, code_pretty)) except: pass for (x,y) in replacements: md = md.replace(x, y) #print(tickspots) body = pypandoc.convert_text(md, "html", format="markdown", extra_args=['--mathjax']) # format any code #body = body.replace("
", "$$") #body = body.replace("
", "$$") #body = body.replace("$$$$", "$$") f.write("") f.write(body) f.write("") # make index print("making index") md = frontmatter.load("index.md").content write_md_to_html(md, "./static/index.html") # make cu os.system("cp ./ising.html ./static/ising.html") os.system("cp ./spatiotemporal.html ./static/spatiotemporal.html") md = frontmatter.load("games.md").content write_md_to_html(md, "./static/games.html") print("making music page") # make music page md = frontmatter.load("music.md").content md += "

" #with open('music.json', 'r') as file: # music_data = json.load(file) #music_data["albums"].sort(key=lambda item: -#item["year"]) albums = [] df = pd.read_csv("music.csv") df = df.sort_values(by=['year'], ascending=False) for i, album in df.iterrows(): #print(row["url"]) try: artist = album["artist"] + " - " except: artist = "" title = album["title"] title = title[0].upper() + title[1:].lower() year = album["year"] desc = album.get("desc", "") url = album.get("url", "") cover = album.get("cover", "./assets/nocover.png") md += f'''

{title} ({year}) {desc}
''' md += "

" write_md_to_html(md, "./static/music.html") print("makng library") # make library md = frontmatter.load("library.md").content df = pd.read_csv("library.csv") df = df.sort_values(by=['year'], ascending=False) df["category"] = df["category"].astype(str) categories = df["category"] categories = list(set(categories)) #\ncategories = [str(category).replace("nan", "unsorted") for category in categories] md += "\n\n" for category in categories: md += "### " + category + "\n\n" write_md_to_html(md, "./static/library.html") print("making posts") # need to sort by date? # Format posts # Iterate through the albums and format them as requested posts = os.listdir("./posts") md = frontmatter.load("posts.md").content # extract dates post_dict = {} for f in posts: f = f.replace(".md", "") post_dict[f] = {} post = frontmatter.load(f"./posts/{f}.md") post_dict[f]["text"] = post.content post_dict[f]["filename"] = f post_dict[f]["title"] = post["title"] post_dict[f]["date"] = dateutil.parser.parse(post["date"]).strftime("%A %B %-d %Y") post_dict[f]["sortable_date"] = dateutil.parser.parse(post["date"]).strftime("%Y %m %d") post_dict = dict(sorted(post_dict.items(), key=lambda x: x[1]["sortable_date"], reverse=True)) for (k,v) in post_dict.items(): filename, text, title, date = v["filename"], v["text"], v["title"], v["date"] md += f"\n\n## {title}\n\n*{date}.*\n\n{text}\n\n" write_md_to_html(f"[back](./posts.html)\n\n# {title}\n\nPosted {date}.\n\n" + text, f"./static/{filename}.html") write_md_to_html(md, "./static/posts.html") md = frontmatter.load("archive.md").content md += "" write_md_to_html(md, "./static/archive.html") md = frontmatter.load("gallery.md").content print("making gallery)") gallery = os.listdir("./assets/gallery/") #print(gallery) gallery.sort(reverse=True) from PIL import Image from PIL.ExifTags import TAGS for f in gallery: md += f"" write_md_to_html(md, "./static/gallery.html") os.system("cp ./make.py ./static/make.py") # does this work? lol os.system("cp ./mastodon.html ./static/mastodon.html") # does this work? lol os.system("cp ./insta.html ./static/insta.html") # does this work? lol print("done")