Tags: Introduction of tag pages linked from the index and the recettes

This commit is contained in:
Thomas Schwery 2016-05-30 00:23:00 +02:00
parent 96a6e5b97e
commit 32f5db8c62
7 changed files with 67 additions and 34 deletions

View file

@ -6,6 +6,7 @@ var pagination = require('metalsmith-pagination')
var paths = require('metalsmith-paths') var paths = require('metalsmith-paths')
var filemetadata = require('metalsmith-filemetadata') var filemetadata = require('metalsmith-filemetadata')
var matters = require('metalsmith-matters') var matters = require('metalsmith-matters')
var tags = require('metalsmith-tags')
var fs = require('fs'); var fs = require('fs');
var moment = require('moment'); var moment = require('moment');
@ -15,6 +16,7 @@ var hlayouts = require('handlebars-layouts');
handlebars.registerHelper(hlayouts(handlebars)); handlebars.registerHelper(hlayouts(handlebars));
handlebars.registerPartial('base', fs.readFileSync('templates/base.hbs', 'utf8')); handlebars.registerPartial('base', fs.readFileSync('templates/base.hbs', 'utf8'));
handlebars.registerPartial('index', fs.readFileSync('templates/index.hbs', 'utf8'));
handlebars.registerHelper('formatDate', function(date) { handlebars.registerHelper('formatDate', function(date) {
return moment(new Date(date)).format('MMMM D, YYYY HH:mm:ss'); return moment(new Date(date)).format('MMMM D, YYYY HH:mm:ss');
@ -81,10 +83,12 @@ metalsmith(__dirname)
.frontmatter(false) .frontmatter(false)
.use(matters(require('./config/matters'))) .use(matters(require('./config/matters')))
.use(filemetadata(require('./config/filemetadata'))) .use(filemetadata(require('./config/filemetadata')))
.use(addCategory())
.use(collections(require('./config/collections'))) .use(collections(require('./config/collections')))
.use(markdown(require('./config/markdown'))) .use(markdown(require('./config/markdown')))
.use(pagination(require('./config/pagination'))) .use(pagination(require('./config/pagination')))
.use(paths(require('./config/paths'))) .use(paths(require('./config/paths')))
.use(tags(require('./config/tags')))
.use(layouts(require('./config/layouts'))) .use(layouts(require('./config/layouts')))
.use(copyVendor()) .use(copyVendor())
.destination('build') .destination('build')
@ -94,6 +98,23 @@ metalsmith(__dirname)
} }
}) })
function addCategory() {
return function(files, metalsmith, done) {
for (var f in files) {
if (f.indexOf('.md') > 0) {
var idx = f.indexOf('/');
var cat = f.substring(0, idx);
files[f].category = cat;
}
}
return done();
}
}
function debugCollection() { function debugCollection() {
return function(files, metalsmith, done) { return function(files, metalsmith, done) {
console.log(files); console.log(files);
@ -116,21 +137,6 @@ function debugMeta(metaname) {
} }
} }
function debugPagination() {
return function(files, metalsmith, done) {
for (var i in files) {
var f = files[i];
if (f !== undefined && f.path != undefined) {
console.log(f.path);
}
}
return done();
}
}
function copyVendor() { function copyVendor() {
return function(files, metalsmith, done){ return function(files, metalsmith, done){

4
config/tags.js Normal file
View file

@ -0,0 +1,4 @@
module.exports = {
handle: 'category',
layout: 'tag.hbs'
}

View file

@ -14,10 +14,9 @@
"metalsmith-layouts": "^1.6.5", "metalsmith-layouts": "^1.6.5",
"metalsmith-markdown": "^0.2.1", "metalsmith-markdown": "^0.2.1",
"metalsmith-matters": "^1.2.0", "metalsmith-matters": "^1.2.0",
"metalsmith-paginate": "^0.3.0",
"metalsmith-pagination": "^1.0.0", "metalsmith-pagination": "^1.0.0",
"metalsmith-paths": "^2.1.2", "metalsmith-paths": "^2.1.2",
"metalsmith-permalinks": "^0.4.0", "metalsmith-tags": "^1.2.1",
"moment": "^2.6.0", "moment": "^2.6.0",
"serve": "^1.4.0" "serve": "^1.4.0"
}, },

View file

@ -16,7 +16,7 @@
<nav class="navbar navbar-default"> <nav class="navbar navbar-default">
<div class="container"> <div class="container">
<div class="navbar-header"> <div class="navbar-header">
<a class="navbar-brand">{{#block "title"}} {{/block}}</a> <a class="navbar-brand" href="/">{{#block "title"}} {{/block}}</a>
{{!-- Fixme {{!-- Fixme
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">

View file

@ -18,6 +18,8 @@
{{/content}} {{/content}}
{{#content "content"}} {{#content "content"}}
<div class="content row">
<div class="list-recette list col-sm-8">
{{#each pagination.files}} {{#each pagination.files}}
<article class="content"> <article class="content">
<header class="header"> <header class="header">
@ -30,6 +32,19 @@
</section> </section>
</article> </article>
{{/ each}} {{/ each}}
</div>
<div class="list-tags list col-sm-4">
<ul class="list-group">
{{#each tags}}
<a href="/tags/{{ @key }}/" class="list-group-item {{#ifCond @key '==' ../tag }}active{{/ifCond }}">
<span class="badge">{{ this.length }}</span>
{{ @key }}
</a>
{{/each}}
</ul>
</div>
</div>
<nav class="navigation cf"> <nav class="navigation cf">
{{#if pagination.previous }} {{#if pagination.previous }}
<a href="{{ pagination.previous.path.href }}" class="btn pull-right"> <a href="{{ pagination.previous.path.href }}" class="btn pull-right">

View file

@ -1,7 +1,7 @@
{{#extend "base"}} {{#extend "base"}}
{{#content "title"}} {{#content "title"}}
Recettes • {{ data.title }} Recettes • {{ category }}{{ data.title }}
{{/ content}} {{/ content}}
{{#content "navitems"}} {{#content "navitems"}}
@ -19,11 +19,13 @@
<h1 class="content-title"> <h1 class="content-title">
Recette {{ data.title }} Recette {{ data.title }}
</h1> </h1>
<small class="header-category">
<a href="/tags/{{ category }}/">{{ category }}</a>
</small>
<small class="header-metadata"> <small class="header-metadata">
{{#if data.category }}{{ data.category }}{{/if }}
{{#if data.description }}{{ data.description }}{{/if }} {{#if data.description }}{{ data.description }}{{/if }}
{{ data.portion }} {{ data.portion }}
{{ data.time }} {{#if data.time }}{{ data.time }}{{/if }}
</small> </small>
</header> </header>
<section class="content"> <section class="content">

7
templates/tag.hbs Normal file
View file

@ -0,0 +1,7 @@
{{#extend "index"}}
{{#content "title"}}
Recettes • {{ tag }}
{{/ content}}
{{/ extend}}