summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2017-10-03 15:30:54 +0200
committerAlan Pearce2017-10-03 15:30:54 +0200
commitad56116d0df26b4a6fe7f9cd04a21965d3184af5 (patch)
treeb8fcb4944e9e0d60cbe11b2226b9acd42713b7f7
parent84da95bc4a8374bd3962e2479df560c67a1b94ca (diff)
downloadhomestead-ad56116d0df26b4a6fe7f9cd04a21965d3184af5.tar.lz
homestead-ad56116d0df26b4a6fe7f9cd04a21965d3184af5.tar.zst
homestead-ad56116d0df26b4a6fe7f9cd04a21965d3184af5.zip
Reify taxonomies into just tags.
I'm probably not going to need anything else, and this makes it a lot clearer
-rw-r--r--config/default.toml4
-rw-r--r--src/actions.js16
-rw-r--r--src/app.js12
-rw-r--r--src/domain/posts.js22
-rw-r--r--test/domain/posts.test.js6
5 files changed, 22 insertions, 38 deletions
diff --git a/config/default.toml b/config/default.toml
index 5dceae1..b5a5d6a 100644
--- a/config/default.toml
+++ b/config/default.toml
@@ -28,9 +28,5 @@ domainStartDate = "2016-01-01"
 [posts]
 folder = "./posts"
 
-[posts.taxonomies]
-tag = "tags"
-category = "categories"
-
 [posts.code]
 theme = "default"
\ No newline at end of file
diff --git a/src/actions.js b/src/actions.js
index 2ad0c77..61f4fd8 100644
--- a/src/actions.js
+++ b/src/actions.js
@@ -50,17 +50,15 @@ function post(config, responder, posts) {
   };
 }
 
-function taxonGenerator(config, responder, term, items) {
+function tag(config, responder, items) {
   return async function(ctx, next) {
-    const value = ctx.params.value;
-    ctx.assert(items.has(ctx.params.value), 404, `${term} ${value} not found`);
-
-    const taxonItems = items.get(value);
+    const tag = ctx.params.name;
+    ctx.assert(items.has(tag), 404, `tag ${tag} not found`);
 
     responder(ctx, config, {
-      listType: term,
-      listName: value,
-      posts: taxonItems
+      listType: "tag",
+      listName: tag,
+      posts: items.get(tag)
     });
   };
 }
@@ -79,6 +77,6 @@ module.exports = {
   posts,
   highlightTheme,
   post,
-  taxonGenerator,
+  tag,
   serveFiles
 };
diff --git a/src/app.js b/src/app.js
index a323b9c..2c23258 100644
--- a/src/app.js
+++ b/src/app.js
@@ -53,13 +53,11 @@ module.exports = async function() {
     actions.post(config, responders.post, Posts.posts)
   );
 
-  for (let [term, items] of Posts.taxonomies) {
-    router.get(
-      `taxon-${term}`,
-      `/${term}/:value`,
-      actions.taxonGenerator(config, responders.list, term, items)
-    );
-  }
+  router.get(
+    "tag",
+    "/tag/:name",
+    actions.tag(config, responders.list, Posts.tags)
+  );
 
   app.use(
     helmet({
diff --git a/src/domain/posts.js b/src/domain/posts.js
index c6b57c5..1214072 100644
--- a/src/domain/posts.js
+++ b/src/domain/posts.js
@@ -68,33 +68,29 @@ async function getFolder(folder, getURL) {
   return new Map(posts.map(f => [getTitle(f), f]));
 }
 
-function taxonomise(taxonomies, posts) {
-  const taxons = new Map(Object.keys(taxonomies).map(t => [t, new Map()]));
+function tag(posts) {
+  const tags = new Map();
 
   for (let [, post] of posts) {
-    for (let [singularName, pluralName] of Object.entries(taxonomies)) {
-      if (post.data.has(pluralName)) {
-        for (let term of post.data.get(pluralName)) {
-          const current = taxons.get(singularName).get(term);
-          taxons
-            .get(singularName)
-            .set(term, current ? current.concat(post) : [post]);
-        }
+    if (post.data.has("tags")) {
+      for (let term of post.data.get("tags")) {
+        const current = tags.get(term);
+        tags.set(term, current ? current.concat(post) : [post]);
       }
     }
   }
 
-  return taxons;
+  return tags;
 }
 
 module.exports = async function(config, getURL) {
   const posts = await getFolder(config.folder, getURL);
-  const taxonomies = taxonomise(config.taxonomies, posts);
+  const tags = tag(posts);
   const lastPostDate = Math.max(Array.from(posts.values(), p => p.date));
   return {
     lastPostDate,
     posts,
-    taxonomies,
+    tags,
     get
   };
 };
diff --git a/test/domain/posts.test.js b/test/domain/posts.test.js
index bb97361..f56489d 100644
--- a/test/domain/posts.test.js
+++ b/test/domain/posts.test.js
@@ -6,11 +6,7 @@ const Posts = require("../../src/domain/posts.js");
 test.beforeEach(async t => {
   t.context = await Posts(
     {
-      folder: path.resolve(__dirname, "../testsite/posts/"),
-      taxonomies: {
-        tag: "tags",
-        category: "categories"
-      }
+      folder: path.resolve(__dirname, "../testsite/posts/")
     },
     basename => basename
   );