|
@@ -1,6 +1,7 @@
|
|
#!/usr/bin/env python3
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
from dataclasses import dataclass
|
|
from dataclasses import dataclass
|
|
|
|
+import base58
|
|
import datetime
|
|
import datetime
|
|
import os
|
|
import os
|
|
import markdown
|
|
import markdown
|
|
@@ -11,6 +12,9 @@ import tempfile
|
|
from typing import Optional
|
|
from typing import Optional
|
|
import yaml
|
|
import yaml
|
|
|
|
|
|
|
|
+def short_hash(s: str) -> str:
|
|
|
|
+ return base58.b58encode(bytes.fromhex(s.replace('-', '')))[:16].decode('utf-8')
|
|
|
|
+
|
|
class Datum:
|
|
class Datum:
|
|
@classmethod
|
|
@classmethod
|
|
def from_yaml(cls, data):
|
|
def from_yaml(cls, data):
|
|
@@ -28,11 +32,17 @@ class Quote(Datum):
|
|
content: str
|
|
content: str
|
|
author: str
|
|
author: str
|
|
|
|
|
|
|
|
+ def short_hash(self) -> str:
|
|
|
|
+ return "qt_" + short_hash(self.id)
|
|
|
|
+
|
|
@dataclass
|
|
@dataclass
|
|
class Quip(Datum):
|
|
class Quip(Datum):
|
|
id: str
|
|
id: str
|
|
content: str
|
|
content: str
|
|
|
|
|
|
|
|
+ def short_hash(self) -> str:
|
|
|
|
+ return "qp_" + short_hash(self.id)
|
|
|
|
+
|
|
@dataclass
|
|
@dataclass
|
|
class Work:
|
|
class Work:
|
|
slug: str
|
|
slug: str
|
|
@@ -90,6 +100,7 @@ class Template:
|
|
main = load_template("main")
|
|
main = load_template("main")
|
|
quote = load_template("quote")
|
|
quote = load_template("quote")
|
|
list = load_template("list")
|
|
list = load_template("list")
|
|
|
|
+ textpage = load_template("textpage")
|
|
|
|
|
|
|
|
|
|
def main():
|
|
def main():
|
|
@@ -105,17 +116,21 @@ def main():
|
|
q = Quip.from_file(Path.data('quips', uuid))
|
|
q = Quip.from_file(Path.data('quips', uuid))
|
|
q.content = markdown.markdown(q.content)
|
|
q.content = markdown.markdown(q.content)
|
|
quips.append(q)
|
|
quips.append(q)
|
|
|
|
+ h = q.short_hash()
|
|
|
|
+ html = Template.main({
|
|
|
|
+ 'title': f"Quip",
|
|
|
|
+ 'contents': Template.quote({'quotelist': [q]}),
|
|
|
|
+ 'copy': no_copy,
|
|
|
|
+ 'opengraph': {
|
|
|
|
+ 'title': f'quip:{h}',
|
|
|
|
+ 'url': f'/quip/{h}/',
|
|
|
|
+ 'description': q.content,
|
|
|
|
+ },
|
|
|
|
+ })
|
|
with Path.write('quips', uuid, 'index.html') as f:
|
|
with Path.write('quips', uuid, 'index.html') as f:
|
|
- f.write(Template.main({
|
|
|
|
- 'title': f"Quip",
|
|
|
|
- 'contents': Template.quote({'quotelist': [q]}),
|
|
|
|
- 'copy': no_copy,
|
|
|
|
- 'opengraph': {
|
|
|
|
- 'title': f'quip:{uuid}',
|
|
|
|
- 'url': f'/quip/{uuid}/',
|
|
|
|
- 'description': q.content,
|
|
|
|
- },
|
|
|
|
- }))
|
|
|
|
|
|
+ f.write(html)
|
|
|
|
+ with Path.write('quips', h, 'index.html') as f:
|
|
|
|
+ f.write(html)
|
|
|
|
|
|
# sort 'em and make the combined page
|
|
# sort 'em and make the combined page
|
|
quips.sort(key=lambda q: q.id)
|
|
quips.sort(key=lambda q: q.id)
|
|
@@ -133,18 +148,22 @@ def main():
|
|
q.content = markdown.markdown(q.content)
|
|
q.content = markdown.markdown(q.content)
|
|
q.author = markdown.markdown(q.author)
|
|
q.author = markdown.markdown(q.author)
|
|
quotes.append(q)
|
|
quotes.append(q)
|
|
|
|
+ contents = Template.quote({'quotelist': [q]})
|
|
|
|
+ short_hash = q.short_hash()
|
|
|
|
+ html = Template.main({
|
|
|
|
+ 'title': f"Quote",
|
|
|
|
+ 'contents': contents,
|
|
|
|
+ 'copy': no_copy,
|
|
|
|
+ 'opengraph': {
|
|
|
|
+ 'title': f'quote:{short_hash}',
|
|
|
|
+ 'url': f'/quote/{short_hash}/',
|
|
|
|
+ 'description': f'{q.content}\n—{q.author}',
|
|
|
|
+ },
|
|
|
|
+ })
|
|
with Path.write('quotes', uuid, 'index.html') as f:
|
|
with Path.write('quotes', uuid, 'index.html') as f:
|
|
- contents = Template.quote({'quotelist': [q]})
|
|
|
|
- f.write(Template.main({
|
|
|
|
- 'title': f"Quote",
|
|
|
|
- 'contents': contents,
|
|
|
|
- 'copy': no_copy,
|
|
|
|
- 'opengraph': {
|
|
|
|
- 'title': f'quote:{uuid}',
|
|
|
|
- 'url': f'/quote/{uuid}/',
|
|
|
|
- 'description': f'{q.content}\n---{q.author}',
|
|
|
|
- },
|
|
|
|
- }))
|
|
|
|
|
|
+ f.write(html)
|
|
|
|
+ with Path.write('quotes', short_hash, 'index.html') as f:
|
|
|
|
+ f.write(html)
|
|
|
|
|
|
# sort 'em and make their combined page
|
|
# sort 'em and make their combined page
|
|
quotes.sort(key=lambda q: q.id)
|
|
quotes.sort(key=lambda q: q.id)
|
|
@@ -183,7 +202,7 @@ def main():
|
|
with open(Path.data('works', slug, work, 'metadata.yaml')) as f:
|
|
with open(Path.data('works', slug, work, 'metadata.yaml')) as f:
|
|
meta = yaml.safe_load(f)
|
|
meta = yaml.safe_load(f)
|
|
with open(Path.data('works', slug, work, 'text')) as f:
|
|
with open(Path.data('works', slug, work, 'text')) as f:
|
|
- text = markdown.markdown(f.read(), extensions=['footnotes'])
|
|
|
|
|
|
+ text = Template.textpage({'contents': markdown.markdown(f.read(), extensions=['footnotes'])})
|
|
w = Work(
|
|
w = Work(
|
|
slug=meta.get('slug', work),
|
|
slug=meta.get('slug', work),
|
|
category=meta.get('category', slug),
|
|
category=meta.get('category', slug),
|