Using deep data merge (post tag is inherited from posts/posts.json) and updates to use 0.7.0.

This commit is contained in:
Zach Leatherman 2019-01-10 22:20:14 -06:00
parent 0cb6dab28a
commit 496982355e
11 changed files with 51 additions and 52 deletions

View File

@ -5,6 +5,7 @@ const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
module.exports = function(eleventyConfig) { module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginRss); eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight); eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.setDataDeepMerge(true);
eleventyConfig.addLayoutAlias("post", "layouts/post.njk"); eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
@ -12,6 +13,11 @@ module.exports = function(eleventyConfig) {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("dd LLL yyyy"); return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("dd LLL yyyy");
}); });
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat('yyyy-LL-dd');
});
// Get the first `n` elements of a collection. // Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => { eleventyConfig.addFilter("head", (array, n) => {
if( n < 0 ) { if( n < 0 ) {
@ -21,18 +27,6 @@ module.exports = function(eleventyConfig) {
return array.slice(0, n); return array.slice(0, n);
}); });
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat('yyyy-LL-dd');
});
// only content in the `posts/` directory
eleventyConfig.addCollection("posts", function(collection) {
return collection.getFilteredByGlob("./posts/*").sort(function(a, b) {
return a.date - b.date;
});
});
eleventyConfig.addCollection("tagList", require("./_11ty/getTagList")); eleventyConfig.addCollection("tagList", require("./_11ty/getTagList"));
eleventyConfig.addPassthroughCopy("img"); eleventyConfig.addPassthroughCopy("img");

View File

@ -1,11 +1,8 @@
module.exports = function(collection) { module.exports = function(collection) {
let tagSet = new Set(); let tagSet = new Set();
collection.getAllSorted().forEach(function(item) { collection.getAll().forEach(function(item) {
if( "tags" in item.data ) { if( "tags" in item.data ) {
let tags = item.data.tags; let tags = item.data.tags;
if( typeof tags === "string" ) {
tags = [tags];
}
tags = tags.filter(function(item) { tags = tags.filter(function(item) {
switch(item) { switch(item) {

View File

@ -1,6 +1,7 @@
{ {
"title": "Your Blog Name", "title": "Your Blog Name",
"url": "https://myurl.com/", "url": "https://myurl.com/",
"description": "I am writing about my experiences as a naval navel-gazer.",
"feed": { "feed": {
"subtitle": "I am writing about my experiences as a naval navel-gazer.", "subtitle": "I am writing about my experiences as a naval navel-gazer.",
"filename": "feed.xml", "filename": "feed.xml",

View File

@ -1,38 +1,39 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ renderData.title or title or metadata.title }}</title> <title>{{ renderData.title or title or metadata.title }}</title>
<link rel="stylesheet" href="{{ '/css/index.css' | url }}"> <meta name="Description" content="{{ renderData.description or description or metadata.description }}">
<link rel="stylesheet" href="{{ '/css/prism-base16-monokai.dark.css' | url }}"> <link rel="stylesheet" href="{{ '/css/index.css' | url }}">
<link rel="alternate" href="{{ metadata.feed.path | url }}" type="application/atom+xml" title="{{ metadata.title }}"> <link rel="stylesheet" href="{{ '/css/prism-base16-monokai.dark.css' | url }}">
</head> <link rel="alternate" href="{{ metadata.feed.path | url }}" type="application/atom+xml" title="{{ metadata.title }}">
<body> </head>
<header> <body>
<h1 class="home"><a href="{{ '/' | url }}">{{ metadata.title }}</a></h1> <header>
<ul class="nav"> <h1 class="home"><a href="{{ '/' | url }}">{{ metadata.title }}</a></h1>
{%- for nav in collections.nav | reverse -%} <ul class="nav">
<li class="nav-item{% if nav.url == page.url %} nav-item-active{% endif %}"><a href="{{ nav.url | url }}">{{ nav.data.navtitle }}</a></li> {%- for nav in collections.nav | reverse -%}
{%- endfor -%} <li class="nav-item{% if nav.url == page.url %} nav-item-active{% endif %}"><a href="{{ nav.url | url }}">{{ nav.data.navtitle }}</a></li>
</ul> {%- endfor -%}
</header> </ul>
</header>
<main{% if templateClass %} class="{{ templateClass }}"{% endif %}> <main{% if templateClass %} class="{{ templateClass }}"{% endif %}>
<div class="warning"> <div class="warning">
<ol> <ol>
<li>Edit the <code>_data/metadata.json</code> with your blogs information.</li> <li>Edit the <code>_data/metadata.json</code> with your blogs information.</li>
<li>(Optional) Edit <code>.eleventy.js</code> with your configuration preferences.</li> <li>(Optional) Edit <code>.eleventy.js</code> with your configuration preferences.</li>
<li>Delete this message from <code>_includes/layouts/base.njk</code>.</li> <li>Delete this message from <code>_includes/layouts/base.njk</code>.</li>
</ol> </ol>
<p><em>This is an <a href="https://www.11ty.io/">Eleventy project</a> created from the <a href="https://github.com/11ty/eleventy-base-blog"><code>eleventy-base-blog</code> repo</a>.</em></p> <p><em>This is an <a href="https://www.11ty.io/">Eleventy project</a> created from the <a href="https://github.com/11ty/eleventy-base-blog"><code>eleventy-base-blog</code> repo</a>.</em></p>
</div> </div>
{{ content | safe }} {{ content | safe }}
</main> </main>
<footer></footer> <footer></footer>
<!-- Current page: {{ page.url | url }} --> <!-- Current page: {{ page.url | url }} -->
</body> </body>
</html> </html>

View File

@ -4,7 +4,7 @@
<a href="{{ post.url | url }}" class="postlist-link">{% if post.data.title %}{{ post.data.title }}{% else %}<code>{{ post.url }}</code>{% endif %}</a> <a href="{{ post.url | url }}" class="postlist-link">{% if post.data.title %}{{ post.data.title }}{% else %}<code>{{ post.url }}</code>{% endif %}</a>
<time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time> <time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time>
{% for tag in post.data.tags %} {% for tag in post.data.tags %}
{%- if tag != "post" -%} {%- if tag != "posts" -%}
{% set tagUrl %}/tags/{{ tag }}/{% endset %} {% set tagUrl %}/tags/{{ tag }}/{% endset %}
<a href="{{ tagUrl | url }}" class="tag">{{ tag }}</a> <a href="{{ tagUrl | url }}" class="tag">{{ tag }}</a>
{%- endif -%} {%- endif -%}

View File

@ -22,7 +22,7 @@
}, },
"homepage": "https://github.com/11ty/eleventy-base-blog#readme", "homepage": "https://github.com/11ty/eleventy-base-blog#readme",
"devDependencies": { "devDependencies": {
"@11ty/eleventy": "^0.5.4", "@11ty/eleventy": "^0.7.0",
"@11ty/eleventy-plugin-rss": "^1.0.3", "@11ty/eleventy-plugin-rss": "^1.0.3",
"@11ty/eleventy-plugin-syntaxhighlight": "^2.0.0", "@11ty/eleventy-plugin-syntaxhighlight": "^2.0.0",
"luxon": "^1.0.0", "luxon": "^1.0.0",

View File

@ -1,8 +1,8 @@
--- ---
title: This is my first post. title: This is my first post.
description: This is a post on My Blog about agile frameworks.
date: 2018-05-01 date: 2018-05-01
tags: tags:
- post
- another-tag - another-tag
layout: layouts/post.njk layout: layouts/post.njk
--- ---

View File

@ -1,5 +1,6 @@
--- ---
title: This is my fourth post. title: This is my fourth post.
description: This is a post on My Blog about touchpoints and circling wagons.
date: 2018-09-30 date: 2018-09-30
tags: second-tag tags: second-tag
layout: layouts/post.njk layout: layouts/post.njk

5
posts/posts.json Normal file
View File

@ -0,0 +1,5 @@
{
"tags": [
"posts"
]
}

View File

@ -1,8 +1,8 @@
--- ---
title: This is my second post. title: This is my second post.
description: This is a post on My Blog about leveraging agile frameworks.
date: 2018-07-04 date: 2018-07-04
tags: tags:
- post
- number-2 - number-2
layout: layouts/post.njk layout: layouts/post.njk
--- ---

View File

@ -1,8 +1,8 @@
--- ---
title: This is my third post. title: This is my third post.
description: This is a post on My Blog about win-win survival strategies.
date: 2018-08-24 date: 2018-08-24
tags: tags:
- post
- second-tag - second-tag
layout: layouts/post.njk layout: layouts/post.njk
--- ---