|
@@ -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
|
|
@@ -105,17 +115,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 +147,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)
|