Tags: Introduction of tag pages linked from the index and the recettes
This commit is contained in:
parent
96a6e5b97e
commit
32f5db8c62
7 changed files with 67 additions and 34 deletions
36
build.js
36
build.js
|
@ -6,6 +6,7 @@ var pagination = require('metalsmith-pagination')
|
|||
var paths = require('metalsmith-paths')
|
||||
var filemetadata = require('metalsmith-filemetadata')
|
||||
var matters = require('metalsmith-matters')
|
||||
var tags = require('metalsmith-tags')
|
||||
|
||||
var fs = require('fs');
|
||||
var moment = require('moment');
|
||||
|
@ -15,6 +16,7 @@ var hlayouts = require('handlebars-layouts');
|
|||
|
||||
handlebars.registerHelper(hlayouts(handlebars));
|
||||
handlebars.registerPartial('base', fs.readFileSync('templates/base.hbs', 'utf8'));
|
||||
handlebars.registerPartial('index', fs.readFileSync('templates/index.hbs', 'utf8'));
|
||||
|
||||
handlebars.registerHelper('formatDate', function(date) {
|
||||
return moment(new Date(date)).format('MMMM D, YYYY HH:mm:ss');
|
||||
|
@ -81,10 +83,12 @@ metalsmith(__dirname)
|
|||
.frontmatter(false)
|
||||
.use(matters(require('./config/matters')))
|
||||
.use(filemetadata(require('./config/filemetadata')))
|
||||
.use(addCategory())
|
||||
.use(collections(require('./config/collections')))
|
||||
.use(markdown(require('./config/markdown')))
|
||||
.use(pagination(require('./config/pagination')))
|
||||
.use(paths(require('./config/paths')))
|
||||
.use(tags(require('./config/tags')))
|
||||
.use(layouts(require('./config/layouts')))
|
||||
.use(copyVendor())
|
||||
.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() {
|
||||
return function(files, metalsmith, done) {
|
||||
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() {
|
||||
|
||||
return function(files, metalsmith, done){
|
||||
|
|
4
config/tags.js
Normal file
4
config/tags.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
handle: 'category',
|
||||
layout: 'tag.hbs'
|
||||
}
|
|
@ -14,10 +14,9 @@
|
|||
"metalsmith-layouts": "^1.6.5",
|
||||
"metalsmith-markdown": "^0.2.1",
|
||||
"metalsmith-matters": "^1.2.0",
|
||||
"metalsmith-paginate": "^0.3.0",
|
||||
"metalsmith-pagination": "^1.0.0",
|
||||
"metalsmith-paths": "^2.1.2",
|
||||
"metalsmith-permalinks": "^0.4.0",
|
||||
"metalsmith-tags": "^1.2.1",
|
||||
"moment": "^2.6.0",
|
||||
"serve": "^1.4.0"
|
||||
},
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<nav class="navbar navbar-default">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand">{{#block "title"}} {{/block}}</a>
|
||||
<a class="navbar-brand" href="/">{{#block "title"}} {{/block}}</a>
|
||||
{{!-- Fixme
|
||||
<div id="navbar" class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
|
|
|
@ -18,18 +18,33 @@
|
|||
{{/content}}
|
||||
|
||||
{{#content "content"}}
|
||||
{{#each pagination.files}}
|
||||
<article class="content">
|
||||
<header class="header">
|
||||
<h2 class="content-title">
|
||||
<a href="{{ path.href }}"><span class="glyphicon glyphicon-apple"></span>{{ data.title }}</a>
|
||||
</h2>
|
||||
</header>
|
||||
<section class="content-article">
|
||||
{{{ data.description }}}
|
||||
</section>
|
||||
</article>
|
||||
{{/ each}}
|
||||
<div class="content row">
|
||||
<div class="list-recette list col-sm-8">
|
||||
{{#each pagination.files}}
|
||||
<article class="content">
|
||||
<header class="header">
|
||||
<h2 class="content-title">
|
||||
<a href="{{ path.href }}"><span class="glyphicon glyphicon-apple"></span>{{ data.title }}</a>
|
||||
</h2>
|
||||
</header>
|
||||
<section class="content-article">
|
||||
{{{ data.description }}}
|
||||
</section>
|
||||
</article>
|
||||
{{/ 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">
|
||||
{{#if pagination.previous }}
|
||||
<a href="{{ pagination.previous.path.href }}" class="btn pull-right">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{#extend "base"}}
|
||||
|
||||
{{#content "title"}}
|
||||
Recettes • {{ data.title }}
|
||||
Recettes • {{ category }} • {{ data.title }}
|
||||
{{/ content}}
|
||||
|
||||
{{#content "navitems"}}
|
||||
|
@ -19,11 +19,13 @@
|
|||
<h1 class="content-title">
|
||||
Recette {{ data.title }}
|
||||
</h1>
|
||||
<small class="header-category">
|
||||
<a href="/tags/{{ category }}/">{{ category }}</a>
|
||||
</small>
|
||||
<small class="header-metadata">
|
||||
{{#if data.category }}{{ data.category }} • {{/if }}
|
||||
{{#if data.description }}{{ data.description }} • {{/if }}
|
||||
{{ data.portion }} •
|
||||
{{ data.time }}
|
||||
{{ data.portion }}
|
||||
{{#if data.time }} • {{ data.time }}{{/if }}
|
||||
</small>
|
||||
</header>
|
||||
<section class="content">
|
||||
|
|
7
templates/tag.hbs
Normal file
7
templates/tag.hbs
Normal file
|
@ -0,0 +1,7 @@
|
|||
{{#extend "index"}}
|
||||
|
||||
{{#content "title"}}
|
||||
Recettes • {{ tag }}
|
||||
{{/ content}}
|
||||
|
||||
{{/ extend}}
|
Loading…
Add table
Reference in a new issue