From fb7e421b9efea0a96adcf30d30cc2d318980d928 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sat, 1 Jul 2017 11:49:18 +0200 Subject: Switch templating to hyperfast This also means that highland is not (currently) required --- src/actions.js | 59 +++++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) (limited to 'src/actions.js') diff --git a/src/actions.js b/src/actions.js index 02414a1..11acff5 100644 --- a/src/actions.js +++ b/src/actions.js @@ -1,46 +1,41 @@ -'use strict' +"use strict"; -const send = require('koa-send') -const h = require('highland') -const responders = require('./responders') +const send = require("koa-send"); +const responders = require("./responders"); -function toArrayStream (iterator) { - return h(iterator.entries()) +function home(config, posts) { + const postsArray = Array.from(posts.values()); + return async function(ctx, next) { + responders.home(ctx, config, postsArray); + }; } -function home (config, posts) { - const postsStream = toArrayStream(posts) - return async function (ctx, next) { - responders.home(ctx, config, postsStream) - } -} - -function post (config, posts) { - return async function (ctx, next) { - ctx.assert(posts.has(ctx.params.filename), 404, 'Post not found') - const post = posts.get(ctx.params.filename) +function post(config, posts) { + return async function(ctx, next) { + ctx.assert(posts.has(ctx.params.filename), 404, "Post not found"); + const post = posts.get(ctx.params.filename); - responders.post(ctx, config, post) - } + responders.post(ctx, config, post); + }; } -function taxonGenerator (config, term, items) { - return async function (ctx, next) { - const value = ctx.params.value - ctx.assert(items.has(ctx.params.value), 404, `${term} ${value} not found`) +function taxonGenerator(config, term, 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 = toArrayStream(items.get(value)) + const taxonItems = items.get(value); - responders.taxon(ctx, config, taxonItems) - } + responders.taxon(ctx, config, taxonItems); + }; } -const prefix = /^\/static\// -async function serveFiles (ctx) { +const prefix = /^\/static\//; +async function serveFiles(ctx) { if (prefix.test(ctx.path)) { - await send(ctx, ctx.path.replace(prefix, ''), { - root: './static' - }) + await send(ctx, ctx.path.replace(prefix, ""), { + root: "./static" + }); } } @@ -49,4 +44,4 @@ module.exports = { post, taxonGenerator, serveFiles -} +}; -- cgit 1.4.1