7 次代碼提交 e5ba8ccefe ... 9f860a953f

作者 SHA1 備註 提交日期
  Getty Ritter 9f860a953f add quote 2 月之前
  Getty Ritter 9049749a1b make some changes 2 月之前
  Getty Ritter 66cc9c717b added new quip 6 月之前
  Getty Ritter 5655e225c4 add protagonist config 6 月之前
  Getty Ritter 5b7dcb608e update to use short hash 6 月之前
  Getty Ritter 2898ca4172 added new quip 10 月之前
  Getty Ritter 701fad26d8 added new quip 10 月之前

+ 21 - 1
BUILD.bazel

@@ -5,6 +5,18 @@ py_binary(
     name = "main",
     srcs = ["main.py"],
     data = glob(["templates/*.mustache", "static/*"]),
+    deps = [
+        requirement("Markdown"),
+        requirement("pystache"),
+        requirement("PyYAML"),
+        requirement("base58"),
+    ]
+)
+
+py_binary(
+    name = "experimental",
+    srcs = ["experimental.py"],
+    data = glob(["templates/*.mustache", "static/*"]),
     deps = [
         requirement("Markdown"),
         requirement("pystache"),
@@ -14,7 +26,7 @@ py_binary(
 
 filegroup(
     name = "data",
-    srcs=glob(["quips/*", "quotes/*", "works/**/*", "works.json"], exclude=["*~"]),
+    srcs=glob(["quips/*", "quotes/*", "works/**/*", "works.json"], exclude=["**/*~"]),
 )
 
 genrule(
@@ -24,3 +36,11 @@ genrule(
     outs = ["output"],
     cmd = "$(location :main) $(location output) $(locations :data)",
 )
+
+genrule(
+    name = "experiment",
+    srcs = [":data"] + glob(["templates/*.mustache", "static/*"]),
+    tools = [":experimental"],
+    outs = ["exp"],
+    cmd = "$(location :experimental) $(location exp) $(locations :data)",
+)

+ 3 - 0
PROTAGONIST

@@ -0,0 +1,3 @@
+SERVER=rosencrantz
+TYPE=static
+DIR=/srv/http/lib/www

+ 13 - 5
WORKSPACE

@@ -2,14 +2,22 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
 
 http_archive(
     name = "rules_python",
-    sha256 = "9fcf91dbcc31fde6d1edb15f117246d912c33c36f44cf681976bd886538deba6",
-    strip_prefix = "rules_python-0.8.0",
-    url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.8.0.tar.gz",
+    sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b",
+    strip_prefix = "rules_python-0.26.0",
+    url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.26.0.tar.gz",
 )
 
-load("@rules_python//python:pip.bzl", "pip_install")
+load("@rules_python//python:repositories.bzl", "py_repositories")
 
-pip_install(
+py_repositories()
+
+load("@rules_python//python:pip.bzl", "pip_parse")
+
+pip_parse(
    name = "deps",
    requirements = "//:requirements.txt",
 )
+
+load("@deps//:requirements.bzl", "install_deps")
+
+install_deps()

+ 7 - 4
bin/add-quip

@@ -1,8 +1,11 @@
 #!/bin/bash -e
 
 UUID=$(uuidgen)
-printf "content: |\n   ...\nid: $UUID\n" >quips/$UUID
-if [ ! $EDITOR quotes/$UUID ]; then
-   rm quips/$UUID
+TGT="quips/${UUID}"
+printf "content: |\n   ...\nid: $UUID\n" >$TGT
+if ! $EDITOR $TGT; then
+   rm $TGT
 fi
-rm -f "quips/${UUID}~"
+rm -f "${TGT}~"
+git add $TGT
+git commit -m "added new quip"

+ 1 - 1
bin/add-quote

@@ -2,7 +2,7 @@
 
 UUID=$(uuidgen)
 printf "content: |\n   ...\nauthor: ...\nid: $UUID\n" >quotes/$UUID
-if [ ! $EDITOR quotes/$UUID ]; then
+if ! $EDITOR quotes/$UUID; then
    rm quotes/$UUID
 fi
 rm -f "quotes/${UUID}~"

+ 41 - 22
main.py

@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 
 from dataclasses import dataclass
+import base58
 import datetime
 import os
 import markdown
@@ -11,6 +12,9 @@ import tempfile
 from typing import Optional
 import yaml
 
+def short_hash(s: str) -> str:
+    return base58.b58encode(bytes.fromhex(s.replace('-', '')))[:16].decode('utf-8')
+
 class Datum:
     @classmethod
     def from_yaml(cls, data):
@@ -28,11 +32,17 @@ class Quote(Datum):
     content: str
     author: str
 
+    def short_hash(self) -> str:
+        return "qt_" + short_hash(self.id)
+
 @dataclass
 class Quip(Datum):
     id: str
     content: str
 
+    def short_hash(self) -> str:
+        return "qp_" + short_hash(self.id)
+
 @dataclass
 class Work:
     slug: str
@@ -90,6 +100,7 @@ class Template:
     main = load_template("main")
     quote = load_template("quote")
     list = load_template("list")
+    textpage = load_template("textpage")
 
 
 def main():
@@ -105,17 +116,21 @@ def main():
         q = Quip.from_file(Path.data('quips', uuid))
         q.content = markdown.markdown(q.content)
         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:
-            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
     quips.sort(key=lambda q: q.id)
@@ -133,18 +148,22 @@ def main():
         q.content = markdown.markdown(q.content)
         q.author = markdown.markdown(q.author)
         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:
-            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
     quotes.sort(key=lambda q: q.id)
@@ -183,7 +202,7 @@ def main():
             with open(Path.data('works', slug, work, 'metadata.yaml')) as f:
                 meta = yaml.safe_load(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(
                 slug=meta.get('slug', work),
                 category=meta.get('category', slug),

+ 0 - 4
quips/18e6b4b1-1095-4b56-8f69-db862cd3c6e5

@@ -1,4 +0,0 @@
-content: 'I for one will try to deduct rum expenses under fuel costs.
-
-  '
-id: 18e6b4b1-1095-4b56-8f69-db862cd3c6e5

+ 2 - 0
quips/2a48e100-4377-4369-b3a8-9f0d0fa8838d

@@ -0,0 +1,2 @@
+content: "we fooled everyone 'cause everyone's a fool"
+id: 2a48e100-4377-4369-b3a8-9f0d0fa8838d

+ 2 - 0
quips/be4ce1ba-38ff-4161-81a5-dc2f1fbaa821

@@ -0,0 +1,2 @@
+content: if you are to be born a ruling king of the world you must confuse it with new words
+id: be4ce1ba-38ff-4161-81a5-dc2f1fbaa821

+ 2 - 0
quips/c870e9b1-1de1-4f25-8a4d-6ae8a86491f4

@@ -0,0 +1,2 @@
+content: "it's nice to be wanted / it says it on the poster"
+id: c870e9b1-1de1-4f25-8a4d-6ae8a86491f4

+ 3 - 0
quotes/696c549e-42d6-4c24-96c7-4505c7b8c2dc

@@ -0,0 +1,3 @@
+content: "Fire is the reuniting of matter with oxygen. If one bears that in mind, every blaze may be seen as a reunion, an occasion of chemical joy. To smoke a cigar is to end a long separation; to burn down a police station is to hold homecoming for billions of happy molecules."
+author: "Tom Robbins, _Even Cowgirls Get The Blues_"
+id: 696c549e-42d6-4c24-96c7-4505c7b8c2dc

File diff suppressed because it is too large
+ 0 - 1
quotes/8418e91b-c340-440c-91c9-78385fd2c2b8


+ 2 - 1
requirements.txt

@@ -1,3 +1,4 @@
 Markdown==3.3.6
 pystache==0.6.0
-PyYAML==6.0
+PyYAML==6.0.1
+base58==2.1.1

+ 81 - 23
static/main.css

@@ -3,10 +3,85 @@
     src: url("/static/leaguespartan-bold.ttf");
 }
 
-body {
-    background-color: #eeeeee;
+body, html {
+    width: 100%;
+    margin: 0em;
+    background-color: #eee;
     font-family: league-spartan, sans-serif;
-    font-size: 14pt;
+    font-size: 18pt;
+}
+
+@media (orientation: landscape) {
+    .all {
+        display: grid;
+        grid-template-columns: 16em auto;
+        grid-template-rows: 1fr auto 1fr;
+        text-align: justify;
+    }
+
+    .header {
+        grid-column: 1 / span 2;
+    }
+
+    .menu {
+        grid-column: 1;
+        display: flex;
+        flex-direction: column;
+        font-size: 20pt;
+    }
+
+    .menu > a {
+        padding: 0.5em 0em;
+    }
+
+    .contents {
+        grid-column: 2;
+        display: flex;
+        justify-content: center;
+    }
+
+    .footer {
+        grid-column: 1 / span 2;
+    }
+
+    .maintext {
+        width: 80%;
+    }
+
+    .work {
+        font-size: 24pt;
+    }
+}
+
+@media (orientation: portrait) {
+    body {
+        font-size: 24pt;
+    }
+
+    .all {
+        width: 100%;
+        display: flex;
+        flex-direction: column;
+        align-items: stretch;
+    }
+
+    .menu {
+        width: 90%;
+        display: flex;
+        flex-direction: row;
+        justify-content: space-between;
+    }
+
+    .maintext {
+        padding: 1em 2em;
+        margin-left: auto;
+        margin-right: auto;
+    }
+
+    .work {
+        font-size: 28pt;
+        padding: 0.5em 0em;
+    }
 }
 
 .header {
@@ -32,27 +107,15 @@ body {
 }
 
 .contents {
-    text-align: justify;
     line-height: 1.5;
-    padding: 40px;
     font-family: "Helvetica", "Arial", sans-serif;
-    margin: 40px;
-    width: 80%;
-    background-color: #e8e8e8;
-    margin-left: auto;
-    margin-right: auto;
 }
 
 .menu {
     text-transform: uppercase;
     letter-spacing: 2px;
-    text-align: center;
-    border-top-style: solid;
-    border-bottom-style: solid;
     padding-top: 5px;
     padding-bottom: 5px;
-    border-width: 1px;
-    width: 60%;
     margin-left: auto;
     margin-right: auto;
 }
@@ -78,17 +141,15 @@ pre {
 }
 
 .quote {
-    border-top-style: solid;
-    border-bottom-style: solid;
-    border-width: 1px;
     padding: 20px;
     margin-top: 20px;
     margin-bottom: 20px;
     width: 75%;
     margin-left: auto;
     margin-right: auto;
-    background-color: #eee;
+    border-bottom: 2px solid #000;
 }
+
 .quotelink {
     margin-top: 10px;
     text-align: right;
@@ -96,17 +157,14 @@ pre {
 }
 
 .link {
-    border-top-style: solid;
-    border-bottom-style: solid;
-    border-width: 1px;
     padding: 20px;
     margin-top: 20px;
     margin-bottom: 20px;
     width: 75%;
     margin-left: auto;
     margin-right: auto;
-    background-color: #eee;
 }
+
 .permalink {
     margin-top: 10px;
     text-align: right;

+ 0 - 1
templates/list.mustache

@@ -1,4 +1,3 @@
-{{! (pgnum, maxpg, works, show_cat, page='recent') }}
 <div class="maintext">
   {{#works}}
     <div class="work">

+ 14 - 14
templates/main.mustache

@@ -18,26 +18,26 @@
   <body>
     <div class="all">
       <div class="header">
-    <div class="sitename">
-      <h1>Librarian of Alexandria</h1>
-    </div>
-    <div class="title">
-      <h2>{{title}}</h2>
-    </div>
+        <div class="sitename">
+          <h1>Librarian of Alexandria</h1>
+        </div>
+        <div class="title">
+          <h2>{{title}}</h2>
+        </div>
       </div>
       <div class="menu">
-    <a href="/">Index</a>&nbsp;&nbsp;&nbsp;
-    <a href="/category/">Collections</a>&nbsp;&nbsp;&nbsp;
-    <a href="/quotes/">Quotes</a>&nbsp;&nbsp;&nbsp;
-    <a href="/quips/">Quips</a>&nbsp;&nbsp;&nbsp;
-    <a href="http://journal.infinitenegativeutility.com/">Blog</a>&nbsp;&nbsp;&nbsp;
-    <a href="/about/">About</a>
+        <a href="/">Index</a>
+        <a href="/category/">Collections</a>
+        <a href="/quotes/">Quotes</a>
+        <a href="/quips/">Quips</a>
+        <a href="http://journal.infinitenegativeutility.com/">Blog</a>
+        <a href="/about/">About</a>
       </div>
       <div class="contents">
-    {{{contents}}}
+        {{{contents}}}
       </div>
       <div class="footer">
-    {{copy}}{{^copy}}&copy;2022 Getty Ritter{{/copy}}
+        {{copy}}{{^copy}}&copy;2024 Getty Ritter{{/copy}}
       </div>
     </div>
   </body>

+ 1 - 1
templates/quote.mustache

@@ -7,7 +7,7 @@
         &mdash;{{{author}}}
       </div>
     {{/author}}
-    <div class="quotelink"><a href="{{id}}">#{{id}}</a></div>
+    <div class="quotelink"><a href="{{short_hash}}">#{{short_hash}}</a></div>
     </div>
   {{/quotelist}}
 </div>

File diff suppressed because it is too large
+ 1 - 9
works/pages/about/text