configurability
This commit is contained in:
parent
bf09a8ffbb
commit
0577a56127
32
config.py
Normal file
32
config.py
Normal file
@ -0,0 +1,32 @@
|
||||
from random import choice
|
||||
|
||||
## Title of the blog
|
||||
## Used for default first navbar entry to "/" root.
|
||||
##
|
||||
title = "mjestečko"
|
||||
|
||||
## Shows on top of every page providing navigation.
|
||||
## Every entry forms a <li><a> child element of <nav>,
|
||||
## where each dictionary pair forms an attached xml property.
|
||||
##
|
||||
navbar = [
|
||||
("source", { "href": "https://git.poto.cafe/veclavtalica/mjestecko" }),
|
||||
("rss", { "href": "/feed.xml" }),
|
||||
("about", { "href": "/articles/mjestečko.html" }),
|
||||
("tracks", { "href": "https://modarchive.org/index.php?request=view_artist_modules&query=96070" }),
|
||||
("mastodon", { "href": "https://poto.cafe/@veclavtalica", "rel": "me" }),
|
||||
]
|
||||
|
||||
## Optional description that will be shown on top of the main page.
|
||||
## Could be plain text or callable with no parameters.
|
||||
##
|
||||
description = lambda: f"Personal blog of one {choice(adjectives)} Veclav Talica."
|
||||
adjectives = ["*wild*", "**wacky**", "very humble", "**most serious**"]
|
||||
|
||||
## Optional link to logo image that will appear on top of the main page.
|
||||
##
|
||||
logo = "/logo.png"
|
||||
|
||||
## Language specifier, used in RSS feed.
|
||||
##
|
||||
language = "en"
|
@ -7,7 +7,8 @@ import time, urllib.parse, re
|
||||
import os.path as path
|
||||
|
||||
from article_utils import the_line_after_metadata, parse_metadata
|
||||
from page_shares import wrap_page, MONTHS
|
||||
from page_builder import wrap_page
|
||||
from date_descriptions import MONTHS
|
||||
|
||||
if len(argv) <= 1:
|
||||
print("No file was supplied")
|
||||
|
1
tools/config.py
Symbolic link
1
tools/config.py
Symbolic link
@ -0,0 +1 @@
|
||||
../config.py
|
24
tools/date_descriptions.py
Normal file
24
tools/date_descriptions.py
Normal file
@ -0,0 +1,24 @@
|
||||
MONTHS = {
|
||||
1: "January",
|
||||
2: "February",
|
||||
3: "March",
|
||||
4: "April",
|
||||
5: "May",
|
||||
6: "June",
|
||||
7: "July",
|
||||
8: "August",
|
||||
9: "September",
|
||||
10: "October",
|
||||
11: "November",
|
||||
12: "December"
|
||||
}
|
||||
|
||||
WEEKDAYS = {
|
||||
0: "Monday",
|
||||
1: "Tuesday",
|
||||
2: "Wednesday",
|
||||
3: "Thursday",
|
||||
4: "Friday",
|
||||
5: "Saturday",
|
||||
6: "Sunday"
|
||||
}
|
@ -7,9 +7,10 @@ from textwrap import indent
|
||||
import time, urllib.parse, re, subprocess
|
||||
|
||||
from article_utils import parse_metadata
|
||||
from page_shares import ADJECTIVES
|
||||
from rfc822 import stringify_date
|
||||
|
||||
import config
|
||||
|
||||
if len(argv) <= 1:
|
||||
print("No directory was supplied")
|
||||
exit(-1)
|
||||
@ -25,10 +26,10 @@ address = argv[2]
|
||||
# todo: Find the latest pubDate
|
||||
feed = f"""<rss version="2.0">
|
||||
<channel>
|
||||
<title>mjestečko</title>
|
||||
<title>{config.title}</title>
|
||||
<link>{address}</link>
|
||||
<description>Personal blog of one {choice(ADJECTIVES)} Veclav Talica</description>
|
||||
<language>en</language>
|
||||
<description>{config.description() if callable(config.description) else config.description}</description>
|
||||
<language>{config.language}</language>
|
||||
<lastBuildDate>{stringify_date(time.gmtime(int(time.time())))}</lastBuildDate>
|
||||
"""
|
||||
|
||||
|
@ -1,11 +1,14 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from sys import argv, exit
|
||||
from random import choice, seed
|
||||
from random import seed
|
||||
import time
|
||||
|
||||
from article_utils import parse_article_directory, sort_titles_by_date
|
||||
from page_shares import wrap_page, ADJECTIVES, MONTHS
|
||||
from page_builder import wrap_page
|
||||
from date_descriptions import MONTHS
|
||||
|
||||
import config
|
||||
|
||||
if len(argv) <= 1:
|
||||
print("No directory was supplied")
|
||||
@ -13,15 +16,15 @@ if len(argv) <= 1:
|
||||
|
||||
seed()
|
||||
|
||||
page_metadata = """Title: mjestečko
|
||||
page_metadata = f"""Title: {config.title}
|
||||
CSS: /style.css
|
||||
HTML header: <meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
"""
|
||||
|
||||
page = f"""![](/logo.png)
|
||||
page = f"""![]({config.logo})
|
||||
|
||||
Personal blog of one {choice(ADJECTIVES)} Veclav Talica.
|
||||
{config.description() if callable(config.description) else config.description}
|
||||
|
||||
### Articles ###
|
||||
|
||||
|
43
tools/page_builder.py
Normal file
43
tools/page_builder.py
Normal file
@ -0,0 +1,43 @@
|
||||
import config
|
||||
|
||||
_navbar = config.navbar.copy()
|
||||
_navbar.insert(0, ('<strong>' + config.title + '</strong>', {"href": "/"}))
|
||||
_navbar.append(("tags", {"href": "/tags.html"}))
|
||||
|
||||
_navbar_lis = '\n'.join(f"""<li><a {' '.join(
|
||||
f'{p}="{v}"' for p, v in e[1].items())}>{e[0]}</a></li>"""
|
||||
for e in _navbar)
|
||||
|
||||
_head = f"""
|
||||
|
||||
<div class="container">
|
||||
<nav class="custom-nav">
|
||||
<ul>
|
||||
{_navbar_lis}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
"""
|
||||
|
||||
_footer = """
|
||||
<footer>
|
||||
<a href="#top">^ Return</a>
|
||||
</footer>
|
||||
|
||||
"""
|
||||
|
||||
_tail = """
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
|
||||
def mixin_tag(content: str, tag: str) -> str:
|
||||
return f"""<{tag}>
|
||||
|
||||
{content}</{tag}>
|
||||
|
||||
"""
|
||||
|
||||
def wrap_page(page: str) -> str:
|
||||
return _head + mixin_tag(page, "main") + _footer + _tail
|
@ -1,67 +0,0 @@
|
||||
|
||||
HEAD_EMBED = """
|
||||
|
||||
<div class="container">
|
||||
<nav class="custom-nav">
|
||||
<ul>
|
||||
<li><a href="/"><strong>mjestečko</strong></a></li>
|
||||
<li><a href="https://git.poto.cafe/veclavtalica/mjestecko">source</a></li>
|
||||
<li><a href="/feed.xml">rss</a></li>
|
||||
<li><a href="/articles/mjestečko.html">about</a></li>
|
||||
<li><a href="https://modarchive.org/index.php?request=view_artist_modules&query=96070">tracks</a></li>
|
||||
<li><a rel="me" href="https://poto.cafe/@veclavtalica">mastodon</a></li>
|
||||
<li><a href="/tags.html">tags</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
"""
|
||||
|
||||
NOTICE = """
|
||||
<footer>
|
||||
<a href="#top">^ Return</a>
|
||||
</footer>
|
||||
|
||||
"""
|
||||
|
||||
TAIL_EMBED = """
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
|
||||
ADJECTIVES = ["*wild*", "**wacky**", "very humble", "**most serious**"]
|
||||
|
||||
MONTHS = {
|
||||
1: "January",
|
||||
2: "February",
|
||||
3: "March",
|
||||
4: "April",
|
||||
5: "May",
|
||||
6: "June",
|
||||
7: "July",
|
||||
8: "August",
|
||||
9: "September",
|
||||
10: "October",
|
||||
11: "November",
|
||||
12: "December"
|
||||
}
|
||||
|
||||
WEEKDAYS = {
|
||||
0: "Monday",
|
||||
1: "Tuesday",
|
||||
2: "Wednesday",
|
||||
3: "Thursday",
|
||||
4: "Friday",
|
||||
5: "Saturday",
|
||||
6: "Sunday"
|
||||
}
|
||||
|
||||
def mixin_tag(content: str, tag: str) -> str:
|
||||
return f"""<{tag}>
|
||||
|
||||
{content}</{tag}>
|
||||
|
||||
"""
|
||||
|
||||
def wrap_page(page: str) -> str:
|
||||
return HEAD_EMBED + mixin_tag(page, "main") + NOTICE + TAIL_EMBED
|
@ -1,4 +1,4 @@
|
||||
from page_shares import MONTHS, WEEKDAYS
|
||||
from date_descriptions import MONTHS, WEEKDAYS
|
||||
|
||||
def stringify_date(date) -> str:
|
||||
return f"{WEEKDAYS[date.tm_wday][:3]}, {date.tm_mday} {MONTHS[date.tm_mon][:3]} {date.tm_year} {date.tm_hour:02d}:{date.tm_min:02d}:{date.tm_sec:02d} GMT"
|
||||
|
@ -8,8 +8,9 @@ from os import walk
|
||||
import os.path as path
|
||||
|
||||
from article_utils import the_line_after_metadata, parse_metadata
|
||||
from page_shares import wrap_page
|
||||
from page_builder import wrap_page
|
||||
|
||||
# todo: Reuse
|
||||
tag_listing_header = """CSS: /style.css
|
||||
HTML header: <meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user