Commit 5be63a63 authored by wu-lee's avatar wu-lee

metalsmith.js - add a long title (includes path)

parent ddb7e951
......@@ -44,13 +44,16 @@ function addMeta(meta) {
}
/** Converts a path to a title, so titles don't need to be defined */
function pathToTitle(path) {
return path
.split('/')
.pop()
.replace(/[.][^.]*/, '')
.replace(/^(.)/, (_, ch) => ch.toUpperCase())
.replace(/-(.?)/g, (_, ch) => ' '+ch.toUpperCase());
function pathToTitle(path, truncate = true) {
var path = path.split('/')
if (truncate && path.length)
path = path.splice(path.length-1);
return path.map(
c =>
c.replace(/[.][^.]*/, '')
.replace(/^(.)/, (_, ch) => ch.toUpperCase())
.replace(/-(.?)/g, (_, ch) => ' '+ch.toUpperCase())
).join('/');
}
/** Extract a layout name if the file is part of a collection, and an
......@@ -150,6 +153,7 @@ module.exports = () => {
.use(addMeta({
config: config.theme,
title: (d) => pathToTitle(d.path),
longtitle: (d) => pathToTitle(d.path, false),
layout: (d) => layoutFromCollection(d),
filename: (d, f) => {
// set path to file path, set filename to original path
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment