Inital commit
This commit is contained in:
commit
52c0143a9d
BIN
__pycache__/renderMD.cpython-39.pyc
Normal file
BIN
__pycache__/renderMD.cpython-39.pyc
Normal file
Binary file not shown.
BIN
__pycache__/renderSCSS.cpython-39.pyc
Normal file
BIN
__pycache__/renderSCSS.cpython-39.pyc
Normal file
Binary file not shown.
31
header.py
Normal file
31
header.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import yaml
|
||||||
|
|
||||||
|
from render import listPages
|
||||||
|
|
||||||
|
firstItem = True
|
||||||
|
|
||||||
|
def headerGen(item, root):
|
||||||
|
global firstItem
|
||||||
|
if(root and not firstItem):
|
||||||
|
separator = '<span class="menuSeparator">|</span>'
|
||||||
|
else:
|
||||||
|
separator = ''
|
||||||
|
firstItem = False
|
||||||
|
|
||||||
|
if(not ('klickable' in item and item['klickable'] is False)):
|
||||||
|
item['lable'] = '<a href="' + item["url"] + '">' + item["lable"] + '</a>'
|
||||||
|
|
||||||
|
if('sub' not in item):
|
||||||
|
return '<li>' + separator + '<span class="menuLable">' + item["lable"] + '</span></li>'
|
||||||
|
|
||||||
|
data = ''
|
||||||
|
subicon = ''
|
||||||
|
if(root):
|
||||||
|
subicon = ' <svg class="menuDropIcon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><path d="M1,3.7L5,8L9,3.7" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" fill="none" stroke="#eee"></path></svg>'
|
||||||
|
data += ' data-hassub="true"'
|
||||||
|
|
||||||
|
html = '<li' + data + '>' + separator + '<span class="menuLable sub">' + item["lable"] + subicon + '</span><ul class="submenu">'
|
||||||
|
html += listPages(item['sub'], item['url'], headerGen)
|
||||||
|
|
||||||
|
return html + '</ul></li>'
|
||||||
|
|
||||||
71
index.yml
Normal file
71
index.yml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
---
|
||||||
|
- lable: Home
|
||||||
|
url: /
|
||||||
|
# - lable: Niet vergeten
|
||||||
|
# url: /niet-vergeten.html
|
||||||
|
- lable: HR
|
||||||
|
sub:
|
||||||
|
- lable: Argief
|
||||||
|
klickable: False
|
||||||
|
sub:
|
||||||
|
- WIS10
|
||||||
|
- ELE10
|
||||||
|
- PEE10
|
||||||
|
- ELE20
|
||||||
|
|
||||||
|
- WIS20
|
||||||
|
- PEE20
|
||||||
|
- EPS10
|
||||||
|
- REG10
|
||||||
|
|
||||||
|
- ANE10
|
||||||
|
- EPS20
|
||||||
|
- lable: Fablab making
|
||||||
|
url: fablab-making.html
|
||||||
|
- lable: WIS20
|
||||||
|
sidebar:
|
||||||
|
- lable: Diffrencieren
|
||||||
|
url: diffrencieeren.html
|
||||||
|
- lable: Supsitutsie
|
||||||
|
url: supsitutsie.html
|
||||||
|
- lable: Breuksplitsen
|
||||||
|
url: breuksplitsen.html
|
||||||
|
- lable: Parsiele int.
|
||||||
|
url: parsiel.html
|
||||||
|
- lable: Fourier transform
|
||||||
|
url: fourier-transformatie.html
|
||||||
|
- lable: Divrenciaal vergeleiking
|
||||||
|
url: difrenciaal-vergeleiking.html
|
||||||
|
- lable: 2de Orde DV
|
||||||
|
url: 2de-orde-dv.html
|
||||||
|
- lable: REG10
|
||||||
|
url: REG10-2
|
||||||
|
sidebar:
|
||||||
|
- lable: Index
|
||||||
|
url: .
|
||||||
|
- lable: Laplace
|
||||||
|
url: laplace.html
|
||||||
|
- lable: Voorbeelden
|
||||||
|
url: voorbeelden.html
|
||||||
|
- lable: Eignenschappen
|
||||||
|
url: eignenschappen.html
|
||||||
|
- lable: P-Regelaar
|
||||||
|
url: pregelaar.html
|
||||||
|
- lable: polen en nulpunten
|
||||||
|
url: polen-en-nulpunten.html
|
||||||
|
|
||||||
|
# - lable: Projecten
|
||||||
|
# klickable: False
|
||||||
|
# url: projecten
|
||||||
|
# sub:
|
||||||
|
# - lable: MR Function Board
|
||||||
|
# url: mr-fn-board
|
||||||
|
# sidebar:
|
||||||
|
# - lable: blog
|
||||||
|
# url: blog.html
|
||||||
|
# - lable: Button layout
|
||||||
|
# url: button-layout.html
|
||||||
|
# - lable: PCB
|
||||||
|
# url: pcb.html
|
||||||
|
# - lable: Puzzel Game
|
||||||
|
# url: puzzel-game
|
||||||
178
render.py
Normal file
178
render.py
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
import os
|
||||||
|
import yaml
|
||||||
|
import shutil
|
||||||
|
from jinja2 import Template
|
||||||
|
|
||||||
|
# from header import headerGen
|
||||||
|
from renderMD import renderMD
|
||||||
|
from renderSCSS import renderSCSS
|
||||||
|
|
||||||
|
with open('template.html', 'r') as file:
|
||||||
|
template = Template(file.read())
|
||||||
|
|
||||||
|
srcDir = '../notes'
|
||||||
|
destDir = '../public'
|
||||||
|
|
||||||
|
firstItem = True
|
||||||
|
|
||||||
|
def headerGen(item, root):
|
||||||
|
global firstItem
|
||||||
|
if(root and not firstItem):
|
||||||
|
separator = '<span class="menuSeparator">|</span>'
|
||||||
|
else:
|
||||||
|
separator = ''
|
||||||
|
firstItem = False
|
||||||
|
|
||||||
|
lable = item['lable']
|
||||||
|
|
||||||
|
if(not ('klickable' in item and item['klickable'] is False)):
|
||||||
|
lable = '<a href="' + item["url"] + '">' + item["lable"] + '</a>'
|
||||||
|
|
||||||
|
if('sub' not in item):
|
||||||
|
return '<li>' + separator + '<span class="menuLable">' + lable + '</span></li>'
|
||||||
|
|
||||||
|
data = ''
|
||||||
|
subicon = ''
|
||||||
|
if(root):
|
||||||
|
subicon = ' <svg class="menuDropIcon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><path d="M1,3.7L5,8L9,3.7" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" fill="none" stroke="#eee"></path></svg>'
|
||||||
|
data += ' data-hassub="true"'
|
||||||
|
|
||||||
|
html = '<li' + data + '>' + separator + '<span class="menuLable sub">' + lable + subicon + '</span><ul class="submenu">'
|
||||||
|
html += listPages(item['sub'], item['url'], headerGen)
|
||||||
|
|
||||||
|
return html + '</ul></li>'
|
||||||
|
|
||||||
|
def sidebarGen(item, root):
|
||||||
|
if(not ('klickable' in item and item['klickable'] is False)):
|
||||||
|
item['lable'] = '<a href="' + item["url"] + '">' + item["lable"] + '</a>'
|
||||||
|
|
||||||
|
if('sub' not in item):
|
||||||
|
return '<li><span class="menuLable">' + item["lable"] + '</span></li>'
|
||||||
|
|
||||||
|
html = '<li><span class="menuLable sub">' + item["lable"] + '</span><ul class="submenu">'
|
||||||
|
html += listPages(item['sub'], item['url'], sidebarGen)
|
||||||
|
|
||||||
|
return html + '</ul></li>'
|
||||||
|
|
||||||
|
def listPages(items, parentUrl, cb):
|
||||||
|
root = False
|
||||||
|
if(firstItem):
|
||||||
|
root = True
|
||||||
|
html = ""
|
||||||
|
for item in items:
|
||||||
|
|
||||||
|
if(type(item) is dict):
|
||||||
|
if('url' not in item):
|
||||||
|
if('lable' not in item):
|
||||||
|
print('url or lable reqired')
|
||||||
|
continue
|
||||||
|
if('klickable' in item and item['klickable'] is False):
|
||||||
|
item["url"] = parentUrl
|
||||||
|
else:
|
||||||
|
item["url"] = parentUrl + '/' + item["lable"]
|
||||||
|
|
||||||
|
if(item['url'] == ''):
|
||||||
|
item['url'] = '/'
|
||||||
|
|
||||||
|
if(item["url"][0] != '/'):
|
||||||
|
item["url"] = parentUrl + '/' + item["url"]
|
||||||
|
|
||||||
|
#WARNING: XSS vanrable!
|
||||||
|
if('lable' not in item):
|
||||||
|
item["lable"] = item["url"].split('/')[-1]
|
||||||
|
|
||||||
|
# if(not ('klickable' in item and item['klickable'] is False)):
|
||||||
|
html += cb(item, root)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if(type(item) is str):
|
||||||
|
html += cb({"lable": item, "url": parentUrl + '/' + item}, root)
|
||||||
|
continue
|
||||||
|
|
||||||
|
return html
|
||||||
|
|
||||||
|
sidebar = ''
|
||||||
|
def renderPage(item, root):
|
||||||
|
global srcDir, destDir, header, template, sidebar
|
||||||
|
html = ''
|
||||||
|
|
||||||
|
srcFile = item['url']
|
||||||
|
if(os.path.isdir(srcDir + item['url'])):
|
||||||
|
if(item['url'][-1] == '/'):
|
||||||
|
srcFile = item['url'] + 'index.md'
|
||||||
|
else:
|
||||||
|
srcFile = item['url'] + '/index.md'
|
||||||
|
elif(len(item['url'].split('.')) > 1 and len(item['url'].split('.')[-1]) < 5):
|
||||||
|
srcFile = '.'.join(item['url'].split('.')[0:-1]) + '.md'
|
||||||
|
|
||||||
|
if(not os.path.isfile(srcDir + srcFile)):
|
||||||
|
print('faild to find path to page for ' + item['url'])
|
||||||
|
else:
|
||||||
|
print('md: ' + srcFile)
|
||||||
|
|
||||||
|
if(not os.path.isdir(destDir + '/'.join(srcFile.split('/')[0:-1]))):
|
||||||
|
os.mkdir(destDir + '/'.join(srcFile.split('/')[0:-1]))
|
||||||
|
|
||||||
|
if('sidebar' in item):
|
||||||
|
sidebar = '<aside><nav><ul id="sidemenu">'
|
||||||
|
sidebar += listPages(item['sidebar'], item['url'], sidebarGen)
|
||||||
|
sidebar += '</ul></nav></aside>'
|
||||||
|
|
||||||
|
target = open(destDir + '.'.join(srcFile.split('.')[0:-1]) + '.html', "w")
|
||||||
|
target.write(template.render(
|
||||||
|
header = header,
|
||||||
|
sidebar = sidebar,
|
||||||
|
body = renderMD(srcDir + srcFile)
|
||||||
|
))
|
||||||
|
target.close()
|
||||||
|
|
||||||
|
if('sidebar' in item):
|
||||||
|
listPages(item['sidebar'], item['url'], renderPage)
|
||||||
|
sidebar = ''
|
||||||
|
if('sub' in item):
|
||||||
|
listPages(item['sub'], item['url'], renderPage)
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def copyAssets(d):
|
||||||
|
global srcDir, destDir
|
||||||
|
for f in os.listdir(srcDir + d):
|
||||||
|
if(os.path.isdir(srcDir + d + f)):
|
||||||
|
if(not os.path.isdir(destDir + d + f)):
|
||||||
|
os.mkdir(destDir + d + f)
|
||||||
|
copyAssets(d + f + '/')
|
||||||
|
continue
|
||||||
|
ext = f.split('.')[-1]
|
||||||
|
|
||||||
|
|
||||||
|
if(ext == 'md'):
|
||||||
|
# print('md: ' + d + f)
|
||||||
|
# target = open(destDir + d + '.'.join(f.split('.')[0:-1]) + '.html', "w")
|
||||||
|
# target.write(template.render(
|
||||||
|
# header = header,
|
||||||
|
# body = renderMD(srcDir + d + f)
|
||||||
|
# ))
|
||||||
|
# target.close()
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
if(ext == 'scss'):
|
||||||
|
print('scss: ' + d + f)
|
||||||
|
target = open(destDir + d + '.'.join(f.split('.')[0:-1]) + '.css', "w")
|
||||||
|
target.write(renderSCSS(srcDir + d + f))
|
||||||
|
target.close()
|
||||||
|
continue
|
||||||
|
|
||||||
|
print("copy: " + d + f)
|
||||||
|
shutil.copyfile(srcDir + d + f, destDir + d + f)
|
||||||
|
|
||||||
|
if(__name__ == '__main__'):
|
||||||
|
with open('index.yml', 'r') as file:
|
||||||
|
index = yaml.safe_load(file)
|
||||||
|
|
||||||
|
header = '<header><nav><ul id="menu">'
|
||||||
|
header += listPages(index, '', headerGen)
|
||||||
|
header += '</ul></nav></header>'
|
||||||
|
|
||||||
|
copyAssets('/')
|
||||||
|
listPages(index, '', renderPage)
|
||||||
10
render.sh
Normal file
10
render.sh
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd $HOME/webTemplate
|
||||||
|
|
||||||
|
rm -r ../public/*
|
||||||
|
|
||||||
|
python3 render.py
|
||||||
|
|
||||||
|
# cd ../public/ && python3 -m http.server 8000
|
||||||
|
|
||||||
48
renderMD.py
Normal file
48
renderMD.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import html
|
||||||
|
from misaka import Markdown, HtmlRenderer
|
||||||
|
import latex2mathml.converter
|
||||||
|
import re
|
||||||
|
|
||||||
|
def renderLatex(code):
|
||||||
|
code = code.strip()
|
||||||
|
code = code.replace("=>", "\\Rightarrow")
|
||||||
|
code = code.replace("->", "\\rightarrow")
|
||||||
|
code = code.replace("*", "\\cdot")
|
||||||
|
|
||||||
|
a = re.search(r"{[^{}]*} */ *{[^{}]*}", code)
|
||||||
|
while a is not None:
|
||||||
|
print(a)
|
||||||
|
print(code[a.span()[0] : a.span()[1]])
|
||||||
|
newcode = code[:a.span()[0]]
|
||||||
|
newcode += "\\frac"
|
||||||
|
newcode += re.sub(r'}[ ]*/[ ]*{', '}{', code[a.span()[0] : a.span()[1]])
|
||||||
|
newcode += code[a.span()[1]:]
|
||||||
|
code = newcode
|
||||||
|
print(code)
|
||||||
|
a = re.search(r"{[^{}}]*} */ *{[^{}}]*}", code)
|
||||||
|
|
||||||
|
return latex2mathml.converter.convert(code)
|
||||||
|
|
||||||
|
class HighlighterRenderer(HtmlRenderer):
|
||||||
|
def codespan(self, code):
|
||||||
|
lang = code.split(' ')[0]
|
||||||
|
if(lang == 'tex'):
|
||||||
|
return '{}\n'.format(renderLatex(' '.join(code.split(' ')[1:]).strip()))
|
||||||
|
return '<code>{}</code>\n'.format(code.strip())
|
||||||
|
def blockcode(self, code, lang):
|
||||||
|
if(lang == 'latex/equetion'):
|
||||||
|
return '<p data-latex="{}">{}</p>\n'.format(code.strip(), renderLatex(code))
|
||||||
|
return '<pre><code class="{}">{}</code></pre>\n'.format(lang.replace('/', '-'), code)
|
||||||
|
|
||||||
|
renderer = HighlighterRenderer()
|
||||||
|
md = Markdown(renderer, extensions=('fenced-code','tables'))
|
||||||
|
|
||||||
|
# print(md(markdown_example))
|
||||||
|
|
||||||
|
def renderMD(src):
|
||||||
|
srcFile = open(src, 'r')
|
||||||
|
html = md(srcFile.read())
|
||||||
|
srcFile.close()
|
||||||
|
return html
|
||||||
|
|
||||||
|
# print(renderMD('../notes/HR/DIS10/week-2.md'))
|
||||||
13
renderSCSS.py
Normal file
13
renderSCSS.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
code = """li {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
import sass
|
||||||
|
|
||||||
|
def renderSCSS(src):
|
||||||
|
srcFile = open(src, 'r')
|
||||||
|
# print(src)
|
||||||
|
css = sass.compile(string=srcFile.read())
|
||||||
|
srcFile.close()
|
||||||
|
return css
|
||||||
50
sidemenu.py
Normal file
50
sidemenu.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import yaml
|
||||||
|
|
||||||
|
def parseHTML(item):
|
||||||
|
if(not ('klickable' in item and item['klickable'] is False)):
|
||||||
|
item['lable'] = '<a href="' + item["url"] + '">' + item["lable"] + '</a>'
|
||||||
|
|
||||||
|
if('sub' not in item):
|
||||||
|
return '<li><span class="menuLable">' + item["lable"] + '</span></li>'
|
||||||
|
|
||||||
|
html = '<li><span class="menuLable sub">' + item["lable"] + '</span><ul class="submenu">'
|
||||||
|
html += genHTML(item['sub'], item['url'])
|
||||||
|
|
||||||
|
return html + '</ul></li>'
|
||||||
|
|
||||||
|
def genHTML(items, parentUrl):
|
||||||
|
html = ""
|
||||||
|
for item in items:
|
||||||
|
|
||||||
|
if(type(item) is dict):
|
||||||
|
if('url' not in item):
|
||||||
|
if('lable' not in item):
|
||||||
|
print('url or lable reqired')
|
||||||
|
continue
|
||||||
|
if('klickable' in item and item['klickable'] is False):
|
||||||
|
item["url"] = parentUrl
|
||||||
|
else:
|
||||||
|
item["url"] = parentUrl + '/' + item["lable"]
|
||||||
|
|
||||||
|
if(item["url"][0] != '/'):
|
||||||
|
item["url"] = parentUrl + '/' + item["url"]
|
||||||
|
|
||||||
|
#WARNING: XSS vanrable!
|
||||||
|
if('lable' not in item):
|
||||||
|
item["lable"] = item["url"].split('/')[-1]
|
||||||
|
|
||||||
|
html += parseHTML(item)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
if(type(item) is str):
|
||||||
|
html += parseHTML({"lable": item, "url": parentUrl + '/' + item})
|
||||||
|
continue
|
||||||
|
|
||||||
|
return html
|
||||||
|
|
||||||
|
def getSidebar(items, parentUrl):
|
||||||
|
html = '<aside><nav><ul id="sidemenu">'
|
||||||
|
html += genHTML(items, parentUrl)
|
||||||
|
html += '</ul></nav></aside>'
|
||||||
|
return html
|
||||||
18
template.html
Normal file
18
template.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" href="/styles/main.css">
|
||||||
|
<title>Notes</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{{ header }}
|
||||||
|
{{ sidebar }}
|
||||||
|
<main>
|
||||||
|
{{ body }}
|
||||||
|
</main>
|
||||||
|
<script src="/scripts/app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user