Add simple date, tags to posts.
This commit is contained in:
parent
feefd1f4d5
commit
189a94c930
@ -21,6 +21,7 @@ import shutil
|
||||
import traceback
|
||||
import time
|
||||
import re
|
||||
from typing import List
|
||||
|
||||
import jinja2
|
||||
import inotify.adapters
|
||||
@ -79,6 +80,13 @@ def parse_nikola_date(match):
|
||||
def parse_complete_date(match):
|
||||
return datetime.datetime.strptime(match.group(0), '%Y-%m-%d %H:%M:%S %Z%z')
|
||||
|
||||
def split_tags(tags: str) -> List[str]:
|
||||
if isinstance(tags, str):
|
||||
return [tag.strip() for tag in tags.split(',')]
|
||||
elif isinstance(tags, list):
|
||||
return tags
|
||||
else:
|
||||
raise NotImplementedError("Unknown tag type: {}".format(type(tags)))
|
||||
|
||||
def slugify(title):
|
||||
"""
|
||||
@ -163,7 +171,12 @@ def load_doc(filepath):
|
||||
|
||||
|
||||
def render_article(doc, front_matter, f):
|
||||
result = ARTICLE_TEMPLATE.render(content=doc, title=front_matter['title'])
|
||||
result = ARTICLE_TEMPLATE.render(
|
||||
content=doc,
|
||||
title=front_matter['title'],
|
||||
post_publication_date=front_matter['date'],
|
||||
post_tags=split_tags(front_matter['tags']),
|
||||
)
|
||||
f.write(result)
|
||||
|
||||
def regen_all(source_top, dest_top, docs=None):
|
||||
@ -174,7 +187,13 @@ def regen_all(source_top, dest_top, docs=None):
|
||||
os.makedirs(os.path.dirname(doc_full_path), exist_ok=True)
|
||||
# print("==", doc_full_path)
|
||||
with open(doc_full_path + '.html', 'wt') as f:
|
||||
try:
|
||||
render_article(doc, front_matter, f)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
logging.error("Rendering failed 😿")
|
||||
continue
|
||||
|
||||
|
||||
for static in STATIC_RESOURCES:
|
||||
src_path = static[0]
|
||||
@ -212,7 +231,13 @@ def main(source_top, dest_top):
|
||||
filepath = os.path.join(directory, file)
|
||||
if filepath.startswith(STATIC_PATH):
|
||||
t0 = time.time()
|
||||
try:
|
||||
update_statics()
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
logging.error("Loading new templates failed 😿")
|
||||
continue
|
||||
|
||||
is_static_resource = False
|
||||
for static in STATIC_RESOURCES:
|
||||
src_path = static[0]
|
||||
@ -252,7 +277,13 @@ def main(source_top, dest_top):
|
||||
os.makedirs(os.path.dirname(doc_full_path), exist_ok=True)
|
||||
# print("==", doc_full_path)
|
||||
with open(doc_full_path + '.html', 'wt') as f:
|
||||
try:
|
||||
render_article(doc, front_matter, f)
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
logging.error("Rendering failed 😿")
|
||||
continue
|
||||
|
||||
logging.info("Updated all in {:.2f}s".format(time.time() - t0))
|
||||
|
||||
|
||||
|
@ -29,7 +29,19 @@
|
||||
<div class="content">
|
||||
<article class="post">
|
||||
<h2 class="post-title">{{ title }}</h2>
|
||||
<div class="post-metadata">
|
||||
<time datetime="{{ post_publication_date }}">
|
||||
{{ post_publication_date }}
|
||||
</time>
|
||||
<ul class="post-tags">
|
||||
{% for post_tag in post_tags %}
|
||||
<li class="post-tag">{{ post_tag }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="post-content">
|
||||
{{ content | safe }}
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -110,6 +110,8 @@ article.post {
|
||||
.site-header h1 {
|
||||
margin-top: 0;
|
||||
font-size: 200%;
|
||||
font-family: monospace, sans;
|
||||
color: #000;
|
||||
}
|
||||
.site-header .site-links .fancy-link {
|
||||
border-right: 1px solid #000;
|
||||
@ -119,6 +121,20 @@ article.post {
|
||||
border: none;
|
||||
}
|
||||
|
||||
/* Post header */
|
||||
.post-metadata ul.post-tags {
|
||||
list-style: none;
|
||||
display: inline;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.post-metadata ul.post-tags li.post-tag::before {
|
||||
content: '#';
|
||||
}
|
||||
.post-metadata ul.post-tags li {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
|
||||
/* Dark mode. */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
@ -133,7 +149,6 @@ article.post {
|
||||
color: #94dcff;
|
||||
}
|
||||
h1,h2,h3,h4,h5,h6 {
|
||||
margin-top: 0;
|
||||
color: #f7da4a;
|
||||
}
|
||||
/* Header */
|
||||
@ -166,6 +181,5 @@ article.post {
|
||||
background: #262826;
|
||||
color: #FFF;
|
||||
font-family: Menlo, Monaco, "Courier New", monospace;
|
||||
font-size: 85%;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user