Closed jcrawford closed 5 years ago
What happens if you change index.md.njk to index.njk.md?
Oh wait. The markdown is in a layout. Are you running in-place before layouts?
Yes in place is run before layouts
/*jslint es6 */
/*
* Metalsmith build file
* Build site with `node build`
*/
'use strict';
const devBuild = ((process.env.NODE_ENV || '').trim().toLowerCase() !== 'production')
const metalsmith = require('metalsmith');
const serve = require('metalsmith-serve');
const watch = require('metalsmith-watch');
const layouts = require('metalsmith-layouts');
const assets = require('metalsmith-assets');
const inplace = require('metalsmith-in-place');
const collections = require('metalsmith-collections');
const debug = (devBuild) ? require('metalsmith-debug-ui') : null;
const excerpts = require('metalsmith-excerpts');
const paginate = require('metalsmith-pager');
const publish = require('metalsmith-publish');
const htmlmin = (devBuild) ? null : require(' ');
const tags = require('metalsmith-tags');
/* Local Plugins */
const utils = require('./lib/utils');
const articles = require('./lib/articles');
const permalinks = require('./lib/my-permalinks');
const search = (devBuild) ? null : require('./lib/search');
var dateFilter = require('nunjucks-date-filter');
dateFilter.setDefaultFormat('MMMM d, Y');
const templateConfig = {
engineOptions: {
highlight: utils.highlight,
filters: {
date: dateFilter
}
}
};
let ms = metalsmith(__dirname);
if(devBuild) debug.patch(ms);
ms.metadata({
site: {
name: 'A Developers Blog',
author: 'Joseph Crawford',
description: 'A Developers Blog'
}
})
.clean(true)
.source('./src/')
.destination('./build/')
.use(collections({
posts: {
pattern: 'posts/**/*.njk',
sortBy: 'date',
reverse: true,
refer: false
},
articles: {
pattern: ['articles/*.njk', 'articles/**/*.njk'],
refer: false
},
reviews: {
pattern: ['reviews/*.njk', 'reviews/**/*.njk'],
sortBy: 'date',
reverse: true,
refer: false
}
}))
.use(tags({
"handle": "tags",
"path": "topics/:tag.html",
"layout": "/tag.njk",
/* Can also use deprecated template property.
"template": "/partials/tag.hbt",
*/
"sortBy": "date",
"reverse": true,
"skipMetadata": false,
"slug": {
"mode": "rfc3986"
}
}))
.use(articles({
collection: 'articles'
}))
.use(excerpts())
.use(paginate({
collection: 'posts',
elementsPerPage: 1,
pagePattern: 'page/:PAGE/index.html',
index: 'index.html',
paginationTemplatePath: '../layouts/partials/paginator.njk',
layoutName: 'category.njk'
}))
.use(publish())
.use(inplace(templateConfig));
if(!devBuild) {
ms.use(search({
projectId: 'LCIGKBLVSG',
privateKey: 'c490aa2a9f619c422d2ef63d2004d5c3',
index: 'jcrawford.github.io',
clearIndex: true,
collections: ['posts', 'reviews', 'articles']
}));
}
ms.use(layouts(templateConfig))
.use(permalinks({
relative: false,
pattern: ":title",
// each linkset defines a match, and any other desired option
linksets: [{
match: { collection: 'posts' },
pattern: 'posts/:date/:title',
},{
match: { collection: 'articles' },
pattern: 'articles/:series.name/:title'
},{
match: { collection: 'reviews' },
pattern: 'reviews/:date/:title'
}]
}))
.use(assets({
source: __dirname + '/assets/',
destination: '.'
}));
if(!devBuild) {
ms.use(htmlmin());
}
ms.use(serve({
port: 8080,
verbose: true,
http_error_files: {
404: "/404/index.html"
}
}))
.use(watch({
paths: {
"${source}/**/*": true,
"lib/**/*": "**/*",
"assets/**/*": "**/*",
"layouts/**/*": "**/*"
}
}))
.build(function (err) {
if (err) {
console.log(err);
throw err;
}
console.log('Build finished!');
});
Yeah that’s the problem. When in-place runs the file is empty as the layout hasn’t been applied yet.
I’ll close this as it’s not a bug or feature request.
So I have to run layouts before in place? Everything I have seen has shown in place before layouts?
Running layouts before in place gives me html that looks like this
<p><!doctype html>
<html dir="ltr" lang="en-US">
<head></p>
<pre><code> <meta property="og:type" content="blog" />
<meta property="og:title" content="A Developers Blog - A Developers Blog" />
<meta property="og:url" content="" />
<title>A Developers Blog - A Developers Blog</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="description" content="Blog &amp; Magazine Theme">
It also still leads to this in the debugging output
metalsmith-in-place rendering njk extension for index.md.njk +0ms
metalsmith-in-place last extension reached, replacing last extension with html +5ms
metalsmith-in-place rendering md extension for index.md.njk +0ms
metalsmith-in-place done rendering index.md.njk, renamed to index.html +3ms
I see the issue, I had markdown in my layout file but the layout file was named homepage.njk
so it was missing the md extension. I also think it is best practice to keep the md out of the layout file but I may be wrong.
I am not quite sure why this is happening but the output from debugging has shown this
I am initiating metalsmith-in-place like so.
The source of the
index.md.njk
is the followingThe source for
homepage.njk
layout is thisThe generated output for
index.html
is the following: