diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2022-03-12 21:10:13 +0000 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2022-03-12 21:10:13 +0000 |
commit | 799284d7065f8db02e7c8d935def80b7a2dd6f9f (patch) | |
tree | e8428bc96a336834451ab4db0b82d9f47398fcf5 | |
parent | c7fea1d2c78e77654f098f9ac7409f97ad171f44 (diff) | |
download | eda.gay-799284d7065f8db02e7c8d935def80b7a2dd6f9f.tar.gz eda.gay-799284d7065f8db02e7c8d935def80b7a2dd6f9f.zip |
Added contents, made a new template for blog posts
-rw-r--r-- | app.py | 8 | ||||
-rw-r--r-- | database.py | 2 | ||||
-rwxr-xr-x | parser.py | 22 | ||||
-rw-r--r-- | static/style.css | 9 | ||||
-rw-r--r-- | templates/template.jinja | 30 | ||||
-rw-r--r-- | templates/thought.jinja | 29 |
6 files changed, 61 insertions, 39 deletions
@@ -98,12 +98,12 @@ def get_thought(): except TypeError: flask.abort(404) return - return flask.render_template_string( - '{% extends "template.jinja" %}\n{% block content %}\n' + parsed + '\n{% endblock %}', + return flask.render_template( + "thought.jinja", **get_template_items(title, db), - thought = True, + md_html = parsed, + contents_html = headers, dt = "published: " + str(dt), - headers = headers, category = category_name, othercategories = db.get_categories_not(category_name), related = db.get_similar_thoughts(category_name, thought_id) diff --git a/database.py b/database.py index 42833d5..61ca2f7 100644 --- a/database.py +++ b/database.py @@ -250,4 +250,4 @@ if __name__ == "__main__": import parser with Database() as db: # print(db.get_similar_thoughts("about me", 5)) - print(parser.parse_file("cpus.md"))
\ No newline at end of file + print(parser.parse_file("out.md")) @@ -13,6 +13,7 @@ import argparse import getpass import houdini import mistune +import jinja2 import app import sys import re @@ -66,20 +67,35 @@ def parse_text(unformatted): plugins = ["strikethrough", "table", "url", "task_lists"] ) html = md(unformatted) + + 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(( # lxml.etree.tostring(node), # "<p>%s</p>" % urllib.parse.unquote_plus(node.attrib["id"]), # possibly insecure? urllib.parse.unquote_plus(node.attrib["id"]), - int(node.tag[-1]), # -horrible hack + level, # -horrible hack "#%s" % node.attrib["id"]) ) + + headers = [(i[0], i[1] - thesmallestlevel, i[2]) for i in headers] # print(headers) - - return html, headers + md_template = jinja2.Template(""" +{% for text, depth, link in contents %} +{{ " " * depth }} - [{{ text }}]({{ link }}) +{% endfor %} + """) + + return mistune.html(md_template.render(contents = headers)) def preview_markdown(path, title, category): def startBrowser(): diff --git a/static/style.css b/static/style.css index 89d8814..cc6b460 100644 --- a/static/style.css +++ b/static/style.css @@ -108,11 +108,16 @@ aside { float: right; } -#header_linkers { +#contents { font-size: xx-small; } -#header_linkers li { +#contents ul { + padding-left: 12px; + line-height: 3px; + } + +#contents ul li { list-style: none; } diff --git a/templates/template.jinja b/templates/template.jinja index f28163e..2fd86f9 100644 --- a/templates/template.jinja +++ b/templates/template.jinja @@ -38,41 +38,13 @@ </a> </div> </header> - <!-- yes, this is stupid asf, using another template would be better (i cant get that to work) --> - {% if thought %} - <aside> - <h4>{{dt}}</h4> - <h5>contents:</h5> - <ul id="header_linkers"> - {% for text, depth, link in headers %} - <li>{{ '#'*depth }} <a href="{{ link }}">{{ text }}</a></li> - {% endfor %} - </ul> - <h5>this category:</h5> - <ul> - <li><b><a href="{{'/thoughts#'+category.replace(' ', '_')}}">{{category}}</a></b></li> - </ul> - <h5>related thoughts:</h5> - <ul> - {% for id_, title, dt, category in related %} - <li><a href="{{'/thought?id=%i' % id_}}">{{title}}</a></li> - {% endfor %} - </ul> - <h5>other categories:</h5> - {% for category_name in othercategories %} - <ul> - <li><a href="{{'/thoughts#'+category_name.replace(' ', '_')}}">{{category_name}}</a></li> - </ul> - {% endfor %} - </aside> - {% endif %} <div id="content"> {% block content %} {% endblock %} </div> <footer> <p>this site is <a href="/thought?id=3">javascript free</a></p> - <a href="https://github.com/jwansek/edaweb">sauce code released under gplv3</a> + <a href="https://git.eda.gay/eda.gay/file/LICENSE.html">sauce code released under gplv3</a> <a href="https://github.com/jwansek/eda.gay">alternate git link</a> <p> <a href="http://jigsaw.w3.org/css-validator/check/referer"> <img style="border:0;width:88px;height:31px" diff --git a/templates/thought.jinja b/templates/thought.jinja new file mode 100644 index 0000000..df6fe7a --- /dev/null +++ b/templates/thought.jinja @@ -0,0 +1,29 @@ +{% extends "template.jinja" %} +{% block content %} + <aside> + <h4>{{ dt }}</h4> + {% if contents_html != "" %} + <h5>contents:</h5> + <div id="contents"> + {{ contents_html|safe }} + </div> + {% endif %} + <h5>this category:</h5> + <ul> + <li><b><a href="{{'/thoughts#'+category.replace(' ', '_')}}">{{category}}</a></b></li> + </ul> + <h5>related thoughts:</h5> + <ul> + {% for id_, title, dt, category in related %} + <li><a href="{{'/thought?id=%i' % id_}}">{{title}}</a></li> + {% endfor %} + </ul> + <h5>other categories:</h5> + {% for category_name in othercategories %} + <ul> + <li><a href="{{'/thoughts#'+category_name.replace(' ', '_')}}">{{category_name}}</a></li> + </ul> + {% endfor %} + </aside> + {{ md_html|safe }} +{% endblock %}
\ No newline at end of file |