2016-11-03 10:54:57 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-11-03 00:24:27 +01:00
|
|
|
import markdown
|
|
|
|
import glob
|
2016-11-03 19:10:38 +01:00
|
|
|
import re
|
2016-11-03 00:24:27 +01:00
|
|
|
|
|
|
|
def generate_template():
|
|
|
|
|
2016-11-03 10:54:57 +01:00
|
|
|
content_file = open('src/template.html', 'r', encoding="utf-8")
|
2016-11-03 00:24:27 +01:00
|
|
|
content = content_file.read()
|
|
|
|
content_file.close()
|
|
|
|
|
2016-11-08 10:28:59 +01:00
|
|
|
md_list = glob.glob("src/*.md")
|
2016-11-03 00:24:27 +01:00
|
|
|
|
2016-11-08 10:28:59 +01:00
|
|
|
for md in md_list:
|
|
|
|
f = open(md, 'r', encoding="utf-8")
|
|
|
|
file_content = f.read()
|
|
|
|
f.close()
|
2016-11-03 00:24:27 +01:00
|
|
|
|
2016-11-08 10:28:59 +01:00
|
|
|
name = md[4:][:len(md)-7]
|
|
|
|
content = content.replace("$" + name + "_content$", markdown.markdown(file_content, output_format="html5"))
|
2016-11-03 00:24:27 +01:00
|
|
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
def generate_page(template, page):
|
|
|
|
content = template.replace("$page$", page);
|
|
|
|
|
2016-11-08 10:28:59 +01:00
|
|
|
rel = {
|
|
|
|
"about": "/",
|
|
|
|
"games": "/games",
|
|
|
|
"blog": "/blog",
|
|
|
|
"saltosion": "/saltosion",
|
|
|
|
"blogtext": "/"
|
|
|
|
}
|
|
|
|
|
|
|
|
md_list = glob.glob("src/*.md")
|
|
|
|
md_list.append("blogtext")
|
|
|
|
|
|
|
|
for md in md_list:
|
|
|
|
name = md.split("src/")[-1].split(".md")[0]
|
|
|
|
if page != name:
|
|
|
|
content = content.replace("$relative_" + name + "$", rel[name])
|
|
|
|
content = content.replace("$" + name + "_class$", 'class="hiddenarea"')
|
|
|
|
content = content.replace("$" + name + "_btn_class$", '')
|
|
|
|
else:
|
|
|
|
content = content.replace("$relative_" + name + "$", "#")
|
|
|
|
content = content.replace("$" + name + "_class$", "")
|
|
|
|
content = content.replace("$" + name + "_btn_class$", 'class="active"')
|
|
|
|
|
2016-11-03 00:24:27 +01:00
|
|
|
return content;
|
|
|
|
|
|
|
|
def build_blogposts():
|
2016-11-08 10:28:59 +01:00
|
|
|
blogposts = glob.glob("src/blogposts/*.md")
|
2016-11-03 00:24:27 +01:00
|
|
|
for path in blogposts:
|
2016-11-03 10:54:57 +01:00
|
|
|
with open(path, "r", encoding="utf-8") as f:
|
2016-11-08 10:28:59 +01:00
|
|
|
with open(path.replace("src/blogposts", "blogposts").replace(".md", ".html"), "w+", encoding="utf-8") as f2:
|
2016-11-03 00:24:27 +01:00
|
|
|
f2.write(markdown.markdown(f.read(), output_format="html5"))
|
|
|
|
|
2016-11-08 10:28:59 +01:00
|
|
|
with open("src/blogposts/blogposts.json", "r", encoding="utf-8") as f:
|
2016-11-03 10:54:57 +01:00
|
|
|
with open("blogposts/blogposts.json", "w+", encoding="utf-8") as f2:
|
2016-11-03 00:24:27 +01:00
|
|
|
f2.write("window.blogpostDataStr = '" + f.read().replace("\n", "") + "';")
|
|
|
|
|
2016-11-03 19:10:38 +01:00
|
|
|
def apply_custom_markdown(markdown):
|
2016-11-04 11:51:52 +01:00
|
|
|
itch_embed_template = '<iframe class="itch-embedded" frameborder="0" src="https://itch.io/embed/$id$?linkback=true&bg_color=222&fg_color=fff&link_color=ff0091&border_color=303030" width="552" height="167"></iframe>'
|
2016-11-03 19:10:38 +01:00
|
|
|
|
2016-11-04 15:29:32 +01:00
|
|
|
regex = re.compile(r"\[itch\$[0-9]*\]")
|
2016-11-03 19:10:38 +01:00
|
|
|
|
|
|
|
while regex.search(markdown) is not None:
|
|
|
|
search = regex.search(markdown)
|
2016-11-04 15:29:32 +01:00
|
|
|
split = [markdown[:search.start()], markdown[search.end():]]
|
2016-11-03 19:10:38 +01:00
|
|
|
|
|
|
|
curr_id = int(markdown[(search.start() + 6):][:(search.end() - search.start() - 7)])
|
|
|
|
|
|
|
|
markdown = split[0] + itch_embed_template.replace("$id$", str(curr_id)) + split[1]
|
|
|
|
|
2016-11-04 15:29:32 +01:00
|
|
|
link_template = '<a class="js-link" href="$link$">$text$</a>'
|
|
|
|
|
|
|
|
regex = re.compile(r"\[[ -ö]*\]\$\([A-z0-9,./]*\)")
|
|
|
|
|
|
|
|
while regex.search(markdown, re.IGNORECASE) is not None:
|
|
|
|
search = regex.search(markdown)
|
|
|
|
split = [markdown[:search.start()], markdown[search.end():]]
|
|
|
|
|
|
|
|
parts = markdown[(search.start() + 1):][:(search.end() - search.start() - 2)].split("]$(")
|
|
|
|
|
|
|
|
markdown = split[0] + link_template.replace("$text$", parts[0]).replace("$link$", parts[1]) + split[1]
|
|
|
|
|
2016-11-03 19:10:38 +01:00
|
|
|
return markdown
|
|
|
|
|
2016-11-03 00:24:27 +01:00
|
|
|
def generate():
|
|
|
|
print("Building blogposts..")
|
|
|
|
build_blogposts()
|
|
|
|
print("Done!\n")
|
|
|
|
|
|
|
|
print("Generating template..")
|
|
|
|
template = generate_template()
|
|
|
|
print("Done!\n")
|
|
|
|
|
2016-11-03 19:10:38 +01:00
|
|
|
print("Applying custom markdown..")
|
|
|
|
|
|
|
|
template = apply_custom_markdown(template)
|
|
|
|
|
2016-11-04 15:29:32 +01:00
|
|
|
print("Done!\n")
|
2016-11-03 19:10:38 +01:00
|
|
|
|
2016-11-03 00:24:27 +01:00
|
|
|
print("Generating pages..")
|
2016-11-03 10:54:57 +01:00
|
|
|
with open('index.html', 'w+', encoding="utf-8") as f:
|
2016-11-03 00:24:27 +01:00
|
|
|
f.write(generate_page(template, "about"))
|
2016-11-08 10:28:59 +01:00
|
|
|
print(" About (index.html) done!")
|
2016-11-03 10:54:57 +01:00
|
|
|
with open('games/index.html', 'w+', encoding="utf-8") as f:
|
2016-11-03 00:24:27 +01:00
|
|
|
f.write(generate_page(template, "games"))
|
2016-11-08 10:28:59 +01:00
|
|
|
print(" Games done!")
|
2016-11-03 10:54:57 +01:00
|
|
|
with open('blog/index.html', 'w+', encoding="utf-8") as f:
|
2016-11-03 00:24:27 +01:00
|
|
|
f.write(generate_page(template, "blog"))
|
2016-11-08 10:28:59 +01:00
|
|
|
print(" Blog done!")
|
2016-11-03 10:54:57 +01:00
|
|
|
with open('blogtext/index.html', 'w+', encoding="utf-8") as f:
|
2016-11-03 00:24:27 +01:00
|
|
|
f.write(generate_page(template, "blogtext"))
|
2016-11-08 10:28:59 +01:00
|
|
|
print(" Blogtext done!")
|
|
|
|
with open('saltosion/index.html', 'w+', encoding="utf-8") as f:
|
|
|
|
f.write(generate_page(template, "saltosion"))
|
|
|
|
print(" Saltosion done!")
|
2016-11-03 00:24:27 +01:00
|
|
|
|
|
|
|
print("Done!\n")
|
|
|
|
|
|
|
|
generate()
|