diff options
author | Alan Pearce | 2017-10-03 17:28:29 +0200 |
---|---|---|
committer | Alan Pearce | 2017-10-03 17:28:29 +0200 |
commit | 529946dc5bdccc2153c97e2040953047319480f4 (patch) | |
tree | 23ab43f182514da801e6a71a215a336773e2586f /src | |
parent | ad56116d0df26b4a6fe7f9cd04a21965d3184af5 (diff) | |
download | homestead-529946dc5bdccc2153c97e2040953047319480f4.tar.lz homestead-529946dc5bdccc2153c97e2040953047319480f4.tar.zst homestead-529946dc5bdccc2153c97e2040953047319480f4.zip |
Add tags listing
Diffstat (limited to 'src')
-rw-r--r-- | src/actions.js | 9 | ||||
-rw-r--r-- | src/app.js | 2 | ||||
-rw-r--r-- | src/responders.js | 22 | ||||
-rw-r--r-- | src/templates/tags.html | 5 |
4 files changed, 37 insertions, 1 deletions
diff --git a/src/actions.js b/src/actions.js index 61f4fd8..50b8079 100644 --- a/src/actions.js +++ b/src/actions.js @@ -50,6 +50,14 @@ function post(config, responder, posts) { }; } +function tags(config, responder, tags) { + return async function(ctx, next) { + responder(ctx, config, { + tags: tags.keys() + }); + }; +} + function tag(config, responder, items) { return async function(ctx, next) { const tag = ctx.params.name; @@ -77,6 +85,7 @@ module.exports = { posts, highlightTheme, post, + tags, tag, serveFiles }; diff --git a/src/app.js b/src/app.js index 2c23258..20ffb69 100644 --- a/src/app.js +++ b/src/app.js @@ -53,6 +53,8 @@ module.exports = async function() { actions.post(config, responders.post, Posts.posts) ); + router.get("tags", "/tag", actions.tags(config, responders.tags, Posts.tags)); + router.get( "tag", "/tag/:name", diff --git a/src/responders.js b/src/responders.js index f4ea0a6..8260734 100644 --- a/src/responders.js +++ b/src/responders.js @@ -27,7 +27,9 @@ const postIndentLevel = baseIndentLevel + getTemplateIndent(findPostContent, "post.html"); function indentForTemplate(text, indentLevel = 0) { - return indent(text, indentLevel).slice(indentLevel).replace(/\n+$/, ""); + return indent(text, indentLevel) + .slice(indentLevel) + .replace(/\n+$/, ""); } function templateReader(template, indentLevel) { @@ -39,6 +41,7 @@ const templates = { home: templateReader("home.html", baseIndentLevel), post: templateReader("post.html", baseIndentLevel), list: templateReader("list.html", baseIndentLevel), + tags: templateReader("tags.html", baseIndentLevel), feed: templateReader("feed.xml") }; @@ -135,6 +138,23 @@ module.exports = { ); }, + tags(ctx, config, { tags }) { + ctx.type = "html"; + + ctx.body = layout( + config, + "Tags", + hyperfast(templates.tags, { + ".tag": Array.from(tags).map(tag => ({ + ".u-url": { + href: ctx.getURL("tag", tag), + _text: Case.title(tag) + } + })) + }) + ); + }, + post(ctx, config, { post }) { ctx.type = "html"; diff --git a/src/templates/tags.html b/src/templates/tags.html new file mode 100644 index 0000000..01a7e37 --- /dev/null +++ b/src/templates/tags.html @@ -0,0 +1,5 @@ +<ul class="tags"> + <li class="tag h-feed"> + <a class="u-url p-name" href="/">Tag</a> + </li> +</ul> |