Euler has design of a homepage and there is a link back to the overview for each solution.

This commit is contained in:
2018-06-14 20:11:26 -04:00
parent 894160d1a0
commit c34ebd6181
48 changed files with 1134 additions and 2394 deletions

View File

@@ -7,6 +7,7 @@ import shutil
from operator import itemgetter
from collections import namedtuple
from os.path import getmtime
from bs4 import BeautifulSoup
import json
@@ -56,6 +57,28 @@ def convert_solutions_to_html(solutions):
if not os.path.isfile(html) or getmtime(html) < getmtime(s.ipynb):
args = ["jupyter-nbconvert", s.ipynb, "--output-dir=html"]
subprocess.call(args)
post_process(html)
def post_process(html):
def tag(t, string="", children=[], **attrs):
t = BeautifulSoup("", 'html.parser').new_tag(t, **attrs)
if string:
t.string = string
for c in children:
t.append(c)
return t
with open(html, 'r') as f:
soup = BeautifulSoup(f.read(), 'html.parser')
soup_h1 = soup.find("h1")
soup_p = tag("p", children=[tag("a", href="/euler", string="Back to overview.")])
soup_h1.insert_after(soup_p)
with open(html, 'w') as f:
f.write(str(soup))
def ship_to_failx():