diff options
| author | yuzu-eva <stevenhu@web.de> | 2024-10-24 23:47:45 +0200 |
|---|---|---|
| committer | yuzu-eva <stevenhu@web.de> | 2024-10-24 23:47:45 +0200 |
| commit | bd24273d096399b96a88574a0033db03739a8d6c (patch) | |
| tree | 0485b0ebf32652b573ac091aa4525796b07fdeb2 | |
| parent | ddf900c6cc70bf88844f79753b7b412d1a31d3b4 (diff) | |
official initial commit
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | content/images/favicon-16x16.png (renamed from images/favicon-16x16.png) | bin | 281 -> 281 bytes | |||
| -rw-r--r-- | content/images/favicon-32x32.png (renamed from images/favicon-32x32.png) | bin | 561 -> 561 bytes | |||
| -rw-r--r-- | content/index.md | 11 | ||||
| -rw-r--r-- | content/styles/style.css (renamed from styles/style.css) | 14 | ||||
| -rw-r--r-- | content/thoughts/thought-1.md | 8 | ||||
| -rwxr-xr-x | generate.py | 134 | ||||
| -rw-r--r-- | index.html | 24 | ||||
| -rw-r--r-- | requirements.txt | 5 | ||||
| -rw-r--r-- | templates/index.html.j2 | 4 | ||||
| -rw-r--r-- | templates/template.html.j2 | 15 | ||||
| -rw-r--r-- | templates/thoughts.html.j2 | 5 |
12 files changed, 196 insertions, 26 deletions
@@ -1 +1,3 @@ .git +venv +static diff --git a/images/favicon-16x16.png b/content/images/favicon-16x16.png Binary files differindex 41b8244..41b8244 100644 --- a/images/favicon-16x16.png +++ b/content/images/favicon-16x16.png diff --git a/images/favicon-32x32.png b/content/images/favicon-32x32.png Binary files differindex b9484ab..b9484ab 100644 --- a/images/favicon-32x32.png +++ b/content/images/favicon-32x32.png diff --git a/content/index.md b/content/index.md new file mode 100644 index 0000000..2ded7e3 --- /dev/null +++ b/content/index.md @@ -0,0 +1,11 @@ +# eva's site + +## About Me + +I've graduated in business information systems. I like to go bouldering in my +spare time. Occasionaly I'll write some software, but don't expect me to host +anything useful. + +## Blog posts + +You can read my thoughts [here](thoughts/thought-1.html). diff --git a/styles/style.css b/content/styles/style.css index 728114d..725b930 100644 --- a/styles/style.css +++ b/content/styles/style.css @@ -7,18 +7,28 @@ p { padding-bottom: 30px; } +#wrapper { + background-color: #000000; + max-width: 974px; + min-width: 850px; + margin: auto; + margin-top: -10px; +} + .center { text-align: center; justify-content: center; - display: flex; } .left { text-align: left; justify-content: center; - display: flex; } .limit-text-width { width: 50%; } + +.header_linker { + font-size: x-small; +} diff --git a/content/thoughts/thought-1.md b/content/thoughts/thought-1.md new file mode 100644 index 0000000..4cac1b9 --- /dev/null +++ b/content/thoughts/thought-1.md @@ -0,0 +1,8 @@ +# 2024-10-24 + +Finally launching this website. This will be a purely static site with just my +occasional thoughts. This site is still in its infancy, so there might be some +changes along the way. + +Got to put this link into a navigation tag. Too lazy to do it now, will do it +later. diff --git a/generate.py b/generate.py new file mode 100755 index 0000000..65e6ef6 --- /dev/null +++ b/generate.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 + +from pygments import highlight +from pygments.lexers import get_lexer_by_name +from pygments.formatters import HtmlFormatter +from urllib.parse import urlparse + +import urllib.parse +import lxml.html +import mistune +import houdini +import jinja2 +import shutil +import os + +ENV = jinja2.Environment(loader=jinja2.FileSystemLoader('templates')) + +class MyRenderer(mistune.HTMLRenderer): + def block_code(self, code, info=None): + if not info: + return '\n<pre><code>{}</code></pre>\n'.format(houdini.escape_html(code.strip())) + lexer = get_lexer_by_name(info, stripall=True) + formatter = HtmlFormatter() + return highlight(code, lexer, formatter) + + def block_quote(self, content): + content = content[3:-5] + out = '\n<blockquote>' + for line in houdini.escape_html(content.strip()).split("\n"): + out += '\n<span class="quote">{}</span><br>'.format(line) + return out + '\n</blockquote>' + + def image(self, link, text, title): + return "<a href='%s' target='_blank'><img alt='%s' src='%s'></a>" % ( + urlparse(link)._replace(query='').geturl(), text, link + ) + + def heading(self, text, level): + hash_ = urllib.parse.quote_plus(text) + return "<h%d id='%s'>%s <a class='header_linker' href='#%s'>[#]</a></h%d>\n" % ( + level, hash_, text, hash_, level + ) + +def parse_file(path): + with open(path, "r") as f: + unformatted = f.read() + + return parse_text(unformatted)[0] + +def parse_text(unformatted): + md = mistune.create_markdown( + renderer = MyRenderer(), + plugins = ["strikethrough", "table", "url", "task_lists", "def_list"] + ) + html = md(unformatted) + if html == "": + return "", "" + + return html, get_headers(html) + +def get_headers(html): + root = lxml.html.fromstring(html) + + headers = [] + thesmallestlevel = 7 + for node in root.xpath('//h1|//h2|//h3|//h4|//h5//h6'): + level = int(node.tag[-1]) + if level < thesmallestlevel: + thesmallestlevel = level + headers.append(( + urllib.parse.unquote_plus(node.attrib["id"]), + level, + "#%s" % node.attrib["id"]) + ) + + headers = [(i[0], i[1] - thesmallestlevel, i[2]) for i in headers] + md_template = jinja2.Template(""" +{% for text, depth, link in contents -%} + {{ " " * depth }} - [{{ text }}]({{ link }}) +{% endfor %} + """) + + return mistune.html(md_template.render(contents = headers)) + +def index(): + src_file = "content/index.md" + template_file = "index.html.j2" + dst_file = "index.html" + + template = ENV.get_template(template_file) + + with open(os.path.join('static/%s' % dst_file), 'w') as html_file: + with open(src_file, "r") as f: + html = template.render( + prefix = "./", + title = "eva's site", + content = parse_text(f.read())[0] + ) + html_file.write(html) + +def thoughts(): + src_path = "content/thoughts" + template_file = "thoughts.html.j2" + dst_path = "static/thoughts" + + template = ENV.get_template(template_file) + + if not os.path.isdir(dst_path): + os.mkdir(dst_path) + + for file in os.listdir(src_path): + dst_file = file.replace(".md", ".html") + with open(os.path.join(dst_path, dst_file), 'w') as html_file: + with open(os.path.join(src_path, file), 'r') as f: + html = template.render( + prefix = "../", + title = "eva's site :: thoughts", + content = parse_text(f.read())[0] + ) + html_file.write(html) + +def main(): + if os.path.isdir("static"): + shutil.rmtree("static") + os.mkdir("static") + + shutil.copytree("content/styles", "static/styles") + shutil.copytree("content/images", "static/images") + + index() + thoughts() + +if __name__ == '__main__': + main() diff --git a/index.html b/index.html deleted file mode 100644 index 7e41287..0000000 --- a/index.html +++ /dev/null @@ -1,24 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - -<head> - <title>cafebabe.gay :: eva's site :3</title> - <meta charset="UTF-8"> - <meta name="viewport" content="width=devide-width,initial-scale=1"> - <link rel="stylesheet" href="styles/style.css"> - <link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" /> - <link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" /> -</head> - -<body> - <div class="center"> - <h1 class="limit-text-width">eva's site :3</h1> - </div> - - <div class="center"> - <h2 class="limit-text-width">UNDER CONSTRUCTION!</h2> - </div> -</body> - - -</html> diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..239b927 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +Jinja2==3.1.4 +mistune==3.0.2 +lxml +Pygments +houdini.py diff --git a/templates/index.html.j2 b/templates/index.html.j2 new file mode 100644 index 0000000..8257ab2 --- /dev/null +++ b/templates/index.html.j2 @@ -0,0 +1,4 @@ +{% extends "template.html.j2" %} +{% block content %} + {{ content }} +{% endblock %} diff --git a/templates/template.html.j2 b/templates/template.html.j2 new file mode 100644 index 0000000..96f7f9d --- /dev/null +++ b/templates/template.html.j2 @@ -0,0 +1,15 @@ +<!doctype html> +<html lang="en"> + <head> + <link rel='stylesheet' href="{{ prefix }}styles/style.css"> + <title>{{ title }}</title> + </head> + <body> + <div id='wrapper'> + <div id='content'> + {% block content %} + {% endblock %} + </div> + </div> + </body> +</html> diff --git a/templates/thoughts.html.j2 b/templates/thoughts.html.j2 new file mode 100644 index 0000000..17b2797 --- /dev/null +++ b/templates/thoughts.html.j2 @@ -0,0 +1,5 @@ +{% extends "template.html.j2" %} +{% block content %} + <a href='../index.html'>Back to main page</a> + {{ content }} +{% endblock %} |
