diff options
author | Alan Pearce | 2017-06-19 21:19:02 +0200 |
---|---|---|
committer | Alan Pearce | 2017-06-19 21:19:02 +0200 |
commit | 4d6378483d46806d0006d6e5755e0eedd6372154 (patch) | |
tree | bde43ff429ecbab1902cca54dd04a74a5cdbb58b /src | |
parent | acd2fe16e6323fdf6b6a10f05603c94b3a535fd7 (diff) | |
download | homestead-4d6378483d46806d0006d6e5755e0eedd6372154.tar.lz homestead-4d6378483d46806d0006d6e5755e0eedd6372154.tar.zst homestead-4d6378483d46806d0006d6e5755e0eedd6372154.zip |
feat: add link helper to view globals
Diffstat (limited to 'src')
-rw-r--r-- | src/index.js | 9 | ||||
-rw-r--r-- | src/views/index.njk | 6 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/index.js b/src/index.js index 8c69cc8..fe0351d 100644 --- a/src/index.js +++ b/src/index.js @@ -21,19 +21,20 @@ app.use( view(`${__dirname}/views`, { extname: 'njk', globals: { - site: config.site + site: config.site, + url: (...args) => router.url(...args) } }) ) const postsArray = Array.from(posts.entries()) -router.get('/', async function (ctx) { +router.get('home', '/', async function (ctx) { await ctx.render('index', { posts: postsArray }) }) -router.get('/post/:filename', async function (ctx) { +router.get('post', '/post/:filename', async function (ctx) { ctx.assert(posts.has(ctx.params.filename), 404, 'Post not found') const post = posts.get(ctx.params.filename) post.body = Posts.render(post) @@ -44,7 +45,7 @@ router.get('/post/:filename', async function (ctx) { const taxonomies = Posts.taxonomise(config.taxonomies, posts) for (let [term, items] of taxonomies) { - router.get(`/${term}/:value`, async function (ctx) { + router.get(`taxon-${term}`, `/${term}/:value`, async function (ctx) { const value = ctx.params.value ctx.assert( items.has(ctx.params.value), diff --git a/src/views/index.njk b/src/views/index.njk index e5f4034..9a7cc80 100644 --- a/src/views/index.njk +++ b/src/views/index.njk @@ -6,7 +6,11 @@ <ul> {% for filename, post in posts %} - <li>{{ post.data.get('title') }}</li> + <li> + <a href="{{ router.url('post', post.basename)}}"> + {{ post.data.get('title') }} + </a> + </li> {% endfor %} </ul> |