Fixes #62.
This commit is contained in:
parent
a9fdacc9a6
commit
7e5a1f5ce7
53
.eleventy.js
53
.eleventy.js
@ -7,12 +7,15 @@ const markdownIt = require("markdown-it");
|
||||
const markdownItAnchor = require("markdown-it-anchor");
|
||||
|
||||
module.exports = function(eleventyConfig) {
|
||||
// Add plugins
|
||||
eleventyConfig.addPlugin(pluginRss);
|
||||
eleventyConfig.addPlugin(pluginSyntaxHighlight);
|
||||
eleventyConfig.addPlugin(pluginNavigation);
|
||||
|
||||
// https://www.11ty.dev/docs/data-deep-merge/
|
||||
eleventyConfig.setDataDeepMerge(true);
|
||||
|
||||
// Alias `layout: post` to `layout: layouts/post.njk`
|
||||
eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
|
||||
|
||||
eleventyConfig.addFilter("readableDate", dateObj => {
|
||||
@ -33,43 +36,32 @@ module.exports = function(eleventyConfig) {
|
||||
return array.slice(0, n);
|
||||
});
|
||||
|
||||
// Return the smallest number argument
|
||||
eleventyConfig.addFilter("min", (...numbers) => {
|
||||
return Math.min.apply(null, numbers);
|
||||
});
|
||||
|
||||
// Create an array of all tags
|
||||
eleventyConfig.addCollection("tagList", function(collection) {
|
||||
let tagSet = new Set();
|
||||
collection.getAll().forEach(function(item) {
|
||||
if( "tags" in item.data ) {
|
||||
let tags = item.data.tags;
|
||||
|
||||
tags = tags.filter(function(item) {
|
||||
switch(item) {
|
||||
// this list should match the `filter` list in tags.njk
|
||||
case "all":
|
||||
case "nav":
|
||||
case "post":
|
||||
case "posts":
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
for (const tag of tags) {
|
||||
tagSet.add(tag);
|
||||
}
|
||||
// this list should match the `filter` list in tags.njk
|
||||
tags.filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1)
|
||||
.forEach(tag => tagSet.add(tag));
|
||||
}
|
||||
});
|
||||
|
||||
// returning an array in addCollection works in Eleventy 0.5.3
|
||||
return [...tagSet];
|
||||
});
|
||||
|
||||
// Copy the `img` and `css` folders to the output
|
||||
eleventyConfig.addPassthroughCopy("img");
|
||||
eleventyConfig.addPassthroughCopy("css");
|
||||
|
||||
/* Markdown Overrides */
|
||||
// Customize Markdown library and settings:
|
||||
let markdownLibrary = markdownIt({
|
||||
html: true,
|
||||
breaks: true,
|
||||
@ -81,7 +73,7 @@ module.exports = function(eleventyConfig) {
|
||||
});
|
||||
eleventyConfig.setLibrary("md", markdownLibrary);
|
||||
|
||||
// Browsersync Overrides
|
||||
// Override Browsersync defaults (used only with --serve)
|
||||
eleventyConfig.setBrowserSyncConfig({
|
||||
callbacks: {
|
||||
ready: function(err, browserSync) {
|
||||
@ -100,6 +92,8 @@ module.exports = function(eleventyConfig) {
|
||||
});
|
||||
|
||||
return {
|
||||
// Control which files Eleventy will process
|
||||
// e.g.: *.md, *.njk, *.html, *.liquid
|
||||
templateFormats: [
|
||||
"md",
|
||||
"njk",
|
||||
@ -107,21 +101,30 @@ module.exports = function(eleventyConfig) {
|
||||
"liquid"
|
||||
],
|
||||
|
||||
// If your site lives in a different subdirectory, change this.
|
||||
// Leading or trailing slashes are all normalized away, so don’t worry about those.
|
||||
// -----------------------------------------------------------------
|
||||
// If your site deploys to a subdirectory, change `pathPrefix`.
|
||||
// Don’t worry about leading and trailing slashes, we normalize these.
|
||||
|
||||
// If you don’t have a subdirectory, use "" or "/" (they do the same thing)
|
||||
// This is only used for link URLs (it does not affect your file structure)
|
||||
// Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/
|
||||
|
||||
// You can also pass this in on the command line using `--pathprefix`
|
||||
// pathPrefix: "/",
|
||||
|
||||
// Optional (default is shown)
|
||||
pathPrefix: "/",
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
// Pre-process *.md files with: (default: `liquid`)
|
||||
markdownTemplateEngine: "liquid",
|
||||
htmlTemplateEngine: "njk",
|
||||
dataTemplateEngine: "njk",
|
||||
|
||||
// These are all optional, defaults are shown:
|
||||
// Pre-process *.html files with: (default: `liquid`)
|
||||
htmlTemplateEngine: "njk",
|
||||
|
||||
// Opt-out of pre-processing global data JSON files: (default: `liquid`)
|
||||
dataTemplateEngine: false,
|
||||
|
||||
// These are all optional (defaults are shown):
|
||||
dir: {
|
||||
input: ".",
|
||||
includes: "_includes",
|
||||
|
@ -6,10 +6,12 @@ templateClass: tmpl-post
|
||||
|
||||
{{ content | safe }}
|
||||
|
||||
{%- set nextPost = collections.posts | getNextCollectionItem(page) %}
|
||||
{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %}
|
||||
{% if nextPost or previousPost %}
|
||||
<hr>
|
||||
<ul>
|
||||
{%- set nextPost = collections.posts | getNextCollectionItem(page) %}
|
||||
{%- if nextPost %}<li>Next: <a href="{{ nextPost.url | url }}">{{ nextPost.data.title }}</a></li>{% endif %}
|
||||
{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %}
|
||||
{%- if previousPost %}<li>Previous: <a href="{{ previousPost.url | url }}">{{ previousPost.data.title }}</a></li>{% endif %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
@ -4,7 +4,6 @@ eleventyNavigation:
|
||||
key: Home
|
||||
order: 1
|
||||
---
|
||||
|
||||
{% set maxPosts = collections.posts.length | min(3) %}
|
||||
<h1>Latest {% if maxPosts == 1 %}Post{% else %}{{ maxPosts }} Posts{% endif %}</h1>
|
||||
|
||||
|
@ -27,8 +27,8 @@
|
||||
"@11ty/eleventy": "^0.11.1",
|
||||
"@11ty/eleventy-navigation": "^0.1.6",
|
||||
"@11ty/eleventy-plugin-rss": "^1.1.0",
|
||||
"@11ty/eleventy-plugin-syntaxhighlight": "^3.0.6",
|
||||
"luxon": "^1.25.0",
|
||||
"@11ty/eleventy-plugin-syntaxhighlight": "^3.1.0",
|
||||
"luxon": "^1.26.0",
|
||||
"markdown-it": "^8.4.2",
|
||||
"markdown-it-anchor": "^5.2.5"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user