4 ms·
I use Python for that. It's just a few lines of code template.html: <header><h3>%(header)s</h3></header> <div>%(content)s</div> <footer>%(footer)s</foot
by fatih-erikli 5y ago
I use Python for that. It's just a few lines of code
template.html:
<header><h3>%(header)s</h3></header>
<div>%(content)s</div>
<footer>%(footer)s</footer>
generate.py:
content = """# This is a markdown content"""
from markdown import markdown
with open('output.html', 'w') as f:
f.write(open('template.html').read() % {
'header': 'welcome',
'content': markdown.markdown(content),
'footer': 'amazing company inc'
})
for serving it:
python3 -m http.server
it will be running on 127.0.0.1:8000
- enriquto 5y agoPython is severe overkill here. You only need "cat" and maybe "sed" for that.
- fatih-erikli 5y agoSurely it is possible to do it with sed, but can you show me, how?
- fatih-erikli 5y agoSomething like that might work I guess cat template.html | sed s/content/$(markdowncompiler content.md)/
- malkosta 5y agoI wanted to be able to create new layouts without touching the precompiler. To rely only on HTML/CSS/Markdown to code the frontend. You can't code partials within the HTML file with your solution.
- fatih-erikli 5y agoActually it's possible too class partial(dict): ... def __getitem__(self, k): ... return open(k).read() So we will render the template like this template.html: <header><h3>%(header)s</h3></header> <div>%(content)s</div> <footer>%(footer.html)s</footer> generate.py content = """# This is a markdown content""" with open('output.html', 'w') as f: f.write(open('template.html').read() % partial({ title: 'Velkommen', content: markdown.markdown('markdown content') }))