ソースを参照

opengraph for works

Getty Ritter 2 年 前
コミット
435f77e86a
4 ファイル変更34 行追加23 行削除
  1. 12 0
      main.py
  2. 22 16
      works.json
  3. 0 6
      works/comics/dominus-001/metadata.yaml
  4. 0 1
      works/comics/dominus-001/text

+ 12 - 0
main.py

@@ -154,6 +154,8 @@ def main():
     with open(Path.data('works.json')) as f:
         categories = yaml.safe_load(f)
 
+    category_lookup = {c['slug']: c for c in categories}
+
     # make an index page for each category
     with Path.write('category', 'index.html') as f:
         f.write(Template.main({
@@ -192,11 +194,21 @@ def main():
                 # report other works in their own year
                 copy = f'© Getty Ritter {w.date}'
 
+            if slug in category_lookup:
+                singular = category_lookup[slug]['singular']
+                description = f'{w.title}: a {singular}'
+            else:
+                description = '...'
             with Path.write(w.slug, 'index.html') as f:
                 f.write(Template.main({
                     'title': w.title,
                     'contents': text,
                     'copy': copy,
+                    'opengraph': {
+                        'title': w.title,
+                        'url': f'/{w.slug}/',
+                        'description': description,
+                    },
                 }))
             works.append(w)
         works.sort(key=lambda w: w.slug)

+ 22 - 16
works.json

@@ -1,19 +1,25 @@
 [ { "category": "Fascicles"
-  , "slug": "fascicles"
-  }
-, { "category": "Strophes"
-  , "slug": "strophes"
-  }
-, { "category": "Stories"
-  , "slug": "stories"
-  }
-, { "category": "Poems"
-  , "slug": "poems"
-  }
-, { "category": "Nonsense"
-  , "slug": "nonsense"
-  }
-, { "category": "Cocktails"
-  , "slug": "cocktails"
+    , "slug": "fascicles"
+    , "singular": "fascicle"
   }
+  , { "category": "Strophes"
+      , "slug": "strophes"
+      , "singular": "strophe"
+    }
+  , { "category": "Stories"
+      , "slug": "stories"
+      , "singular": "story"
+    }
+  , { "category": "Poems"
+      , "slug": "poems"
+      , "singular": "poem"
+    }
+  , { "category": "Nonsense"
+      , "slug": "nonsense"
+      , "singular": "work of nonsense"
+    }
+  , { "category": "Cocktails"
+      , "slug": "cocktails"
+      , "singular": "cocktail"
+    }
 ]

+ 0 - 6
works/comics/dominus-001/metadata.yaml

@@ -1,6 +0,0 @@
-{
-  "name": "Dominus #1: The Astronaut",
-  "category": "comic",
-  "date": "2011",
-  "slug": "dominus-001"
-}

+ 0 - 1
works/comics/dominus-001/text

@@ -1 +0,0 @@
-![The Astronaut](http://76.105.173.15/images/the_moon.png)