summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2017-07-04 21:03:24 +0200
committerAlan Pearce2017-07-04 21:03:24 +0200
commit9d601e206bdad2c384f2328a14fea8c0f5428ca9 (patch)
treef83086a1139ea84393ebe30436f30205f9750024
parente7b08b1dfe3f2a2596deb6e2a72bb79805d3708f (diff)
downloadhomestead-9d601e206bdad2c384f2328a14fea8c0f5428ca9.tar.lz
homestead-9d601e206bdad2c384f2328a14fea8c0f5428ca9.tar.zst
homestead-9d601e206bdad2c384f2328a14fea8c0f5428ca9.zip
feat: Add posts listing
-rw-r--r--src/actions.js10
-rw-r--r--src/app.js2
-rw-r--r--src/responders.js18
-rw-r--r--src/templates/list.html (renamed from src/templates/taxon.html)0
-rw-r--r--test/app.test.js31
-rw-r--r--test/snapshots/app.test.js.md68
-rw-r--r--test/snapshots/app.test.js.snapbin1550 -> 1658 bytes
7 files changed, 118 insertions, 11 deletions
diff --git a/src/actions.js b/src/actions.js
index 7c7482f..e6d7f98 100644
--- a/src/actions.js
+++ b/src/actions.js
@@ -12,6 +12,13 @@ function home(config, posts) {
   };
 }
 
+function posts(config, posts) {
+  const postsArray = Array.from(posts.values());
+  return async function(ctx, next) {
+    responders.list(ctx, config, null, "Posts", postsArray);
+  };
+}
+
 function highlightTheme(config) {
   const theme = config.posts.code.theme;
   const themeFile = path.resolve(
@@ -47,7 +54,7 @@ function taxonGenerator(config, term, items) {
 
     const taxonItems = items.get(value);
 
-    responders.taxon(ctx, config, term, value, taxonItems);
+    responders.list(ctx, config, term, value, taxonItems);
   };
 }
 
@@ -62,6 +69,7 @@ async function serveFiles(ctx) {
 
 module.exports = {
   home,
+  posts,
   highlightTheme,
   post,
   taxonGenerator,
diff --git a/src/app.js b/src/app.js
index 6be44bd..b6d8beb 100644
--- a/src/app.js
+++ b/src/app.js
@@ -21,6 +21,8 @@ module.exports = async function() {
 
   router.get("home", "/", actions.home(config, Posts.posts));
 
+  router.get("posts", "/post", actions.posts(config, Posts.posts));
+
   router.get(
     "highlight-theme",
     "/css/code.css",
diff --git a/src/responders.js b/src/responders.js
index 48d1949..75850f8 100644
--- a/src/responders.js
+++ b/src/responders.js
@@ -37,7 +37,7 @@ const templates = {
   layout: templateReader("layout"),
   home: templateReader("home", baseIndentLevel),
   post: templateReader("post", baseIndentLevel),
-  taxon: templateReader("taxon", baseIndentLevel)
+  list: templateReader("list", baseIndentLevel)
 };
 
 function title(siteTitle, pageTitle) {
@@ -97,25 +97,25 @@ module.exports = {
     );
   },
 
-  post(ctx, config, post) {
+  list(ctx, config, listType, listName, posts) {
     ctx.type = "html";
 
     ctx.body = layout(
       config,
-      post.data.get("title"),
-      hyperfast(templates.post, renderPost(ctx)(post))
+      Case.title(listName),
+      hyperfast(templates.list, {
+        ".h-entry": posts.map(renderPost(ctx))
+      })
     );
   },
 
-  taxon(ctx, config, term, value, taxonItems) {
+  post(ctx, config, post) {
     ctx.type = "html";
 
     ctx.body = layout(
       config,
-      Case.title(value),
-      hyperfast(templates.taxon, {
-        ".h-entry": taxonItems.map(renderPost(ctx))
-      })
+      post.data.get("title"),
+      hyperfast(templates.post, renderPost(ctx)(post))
     );
   }
 };
diff --git a/src/templates/taxon.html b/src/templates/list.html
index 44244e5..44244e5 100644
--- a/src/templates/taxon.html
+++ b/src/templates/list.html
diff --git a/test/app.test.js b/test/app.test.js
index ac0ce2d..1f8e72f 100644
--- a/test/app.test.js
+++ b/test/app.test.js
@@ -63,6 +63,37 @@ test("homepage", async function(t) {
   t.snapshot(data, "should contain relevant microformats data");
 });
 
+test("posts", async function(t) {
+  const res = await request(app.listen()).get("/post/");
+
+  t.is(res.statusCode, 200);
+  t.is(res.type, "text/html");
+  t.is(res.charset, "utf-8");
+  t.regex(res.text, /^<!DOCTYPE html>/);
+
+  const $ = parseResponse(res);
+
+  t.is(
+    $("head > title").text(),
+    "Posts · " + "John Doe",
+    "head title contains 'Posts' and site author"
+  );
+
+  const options = toMicroformatsOptions($);
+  const count = await mf.countAsync(options);
+
+  t.deepEqual(count, {
+    "h-card": 1,
+    "h-feed": 1,
+    "h-entry": 1,
+    rels: 1
+  });
+
+  const data = await mf.getAsync(options);
+
+  t.snapshot(data, "should contain relevant microformats data");
+});
+
 test("post", async function(t) {
   const res = await request(app.listen()).get("/post/testfile");
 
diff --git a/test/snapshots/app.test.js.md b/test/snapshots/app.test.js.md
index a595585..02eac70 100644
--- a/test/snapshots/app.test.js.md
+++ b/test/snapshots/app.test.js.md
@@ -190,4 +190,70 @@ Generated by [AVA](https://ava.li).
           '/css/code.css',
         ],
       },
-    }
+    
+
+## posts
+
+> should contain relevant microformats data
+
+    {
+      items: [
+        {
+          properties: {
+            name: [
+              'John Doe',
+            ],
+            photo: [
+              '/static/johndoe.jpg',
+            ],
+            url: [
+              '/',
+            ],
+          },
+          type: [
+            'h-card',
+          ],
+        },
+        {
+          children: [
+            {
+              properties: {
+                name: [
+                  'This is a test',
+                ],
+                published: [
+                  '2017-01-01T00:00:00.000Z',
+                ],
+                url: [
+                  '/post/testfile',
+                ],
+              },
+              type: [
+                'h-entry',
+              ],
+              value: 'This is a test Sunday, January 1, 2017',
+            },
+          ],
+          properties: {
+            name: [
+              'Posts · John Doe',
+            ],
+          },
+          type: [
+            'h-feed',
+          ],
+        },
+      ],
+      'rel-urls': {
+        '/css/code.css': {
+          rels: [
+            'stylesheet',
+          ],
+        },
+      },
+      rels: {
+        stylesheet: [
+          '/css/code.css',
+        ],
+      },
+    }
\ No newline at end of file
diff --git a/test/snapshots/app.test.js.snap b/test/snapshots/app.test.js.snap
index e356c77..b7ca373 100644
--- a/test/snapshots/app.test.js.snap
+++ b/test/snapshots/app.test.js.snap
Binary files differ