import markdown import glob def generate_template(): content_file = open('src/template.html', 'r') content = content_file.read() content_file.close() about_file = open('src/about.md', 'r') about = about_file.read() about_file.close() games_file = open('src/games.md', 'r') games = games_file.read() games_file.close() blog_file = open('src/blog.md', 'r') blog = blog_file.read() blog_file.close() content = content.replace("$about_content$", markdown.markdown(about, output_format="html5")) content = content.replace("$games_content$", markdown.markdown(games, output_format="html5")) content = content.replace("$blog_content$", markdown.markdown(blog, output_format="html5")) return content def generate_page(template, page): content = template.replace("$page$", page); rel_about = "/" rel_games = "/games" rel_blog = "/blog" about_hidden = 'class="hiddenarea"' games_hidden = 'class="hiddenarea"' blog_hidden = 'class="hiddenarea"' blogtext_hidden = 'class="hiddenarea"' if (page == "about"): rel_about = "#" about_hidden = "" elif (page == "games"): rel_games = "#" games_hidden = "" elif (page == "blog"): rel_blog = "#" blog_hidden = "" elif (page == "blogtext"): rel_blogtext = "#" blogtext_hidden = "" content = content.replace("$relative_about$", rel_about); content = content.replace("$relative_games$", rel_games); content = content.replace("$relative_blog$", rel_blog); content = content.replace("$about_is_hidden$", about_hidden); content = content.replace("$games_is_hidden$", games_hidden); content = content.replace("$blog_is_hidden$", blog_hidden); content = content.replace("$blogtext_is_hidden$", blogtext_hidden); return content; def build_blogposts(): blogposts = glob.glob("blogposts-md/*.md") for path in blogposts: with open(path, "r") as f: with open(path.replace("blogposts-md", "blogposts").replace(".md", ".html"), "w+") as f2: f2.write(markdown.markdown(f.read(), output_format="html5")) with open("blogposts-md/blogposts.json", "r") as f: with open("blogposts/blogposts.json", "w+") as f2: f2.write("window.blogpostDataStr = '" + f.read().replace("\n", "") + "';") def generate(): #md = markdown.markdown("hi **this is** a test markdown _right?_ `wait, let's test _the *code* block_`", output_format="html5") print("Building blogposts..") build_blogposts() print("Done!\n") print("Generating template..") template = generate_template() print("Done!\n") print("Generating pages..") with open('index.html', 'w+') as f: f.write(generate_page(template, "about")) print("About (index.html) done!") with open('games/index.html', 'w+') as f: f.write(generate_page(template, "games")) print("Games done!") with open('blog/index.html', 'w+') as f: f.write(generate_page(template, "blog")) print("Blog done!") with open('blogtext/index.html', 'w+') as f: f.write(generate_page(template, "blogtext")) print("Blogtext done!") print("Done!\n") generate()