Skip to content

Commit

Permalink
Using deep data merge (post tag is inherited from posts/posts.json) a…
Browse files Browse the repository at this point in the history
…nd updates to use 0.7.0.
  • Loading branch information
zachleat committed Jan 11, 2019
1 parent 0cb6dab commit 4969823
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 52 deletions.
18 changes: 6 additions & 12 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.setDataDeepMerge(true);

eleventyConfig.addLayoutAlias("post", "layouts/post.njk");

eleventyConfig.addFilter("readableDate", dateObj => {
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.
eleventyConfig.addFilter("head", (array, n) => {
if( n < 0 ) {
Expand All @@ -21,18 +27,6 @@ module.exports = function(eleventyConfig) {
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.addPassthroughCopy("img");
Expand Down
5 changes: 1 addition & 4 deletions _11ty/getTagList.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module.exports = function(collection) {
let tagSet = new Set();
collection.getAllSorted().forEach(function(item) {
collection.getAll().forEach(function(item) {
if( "tags" in item.data ) {
let tags = item.data.tags;
if( typeof tags === "string" ) {
tags = [tags];
}

tags = tags.filter(function(item) {
switch(item) {
Expand Down
1 change: 1 addition & 0 deletions _data/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"title": "Your Blog Name",
"url": "https://myurl.com/",
"description": "I am writing about my experiences as a naval navel-gazer.",
"feed": {
"subtitle": "I am writing about my experiences as a naval navel-gazer.",
"filename": "feed.xml",
Expand Down
63 changes: 32 additions & 31 deletions _includes/layouts/base.njk
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ renderData.title or title or metadata.title }}</title>
<link rel="stylesheet" href="{{ '/css/index.css' | url }}">
<link rel="stylesheet" href="{{ '/css/prism-base16-monokai.dark.css' | url }}">
<link rel="alternate" href="{{ metadata.feed.path | url }}" type="application/atom+xml" title="{{ metadata.title }}">
</head>
<body>
<header>
<h1 class="home"><a href="{{ '/' | url }}">{{ metadata.title }}</a></h1>
<ul class="nav">
{%- for nav in collections.nav | reverse -%}
<li class="nav-item{% if nav.url == page.url %} nav-item-active{% endif %}"><a href="{{ nav.url | url }}">{{ nav.data.navtitle }}</a></li>
{%- endfor -%}
</ul>
</header>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ renderData.title or title or metadata.title }}</title>
<meta name="Description" content="{{ renderData.description or description or metadata.description }}">
<link rel="stylesheet" href="{{ '/css/index.css' | url }}">
<link rel="stylesheet" href="{{ '/css/prism-base16-monokai.dark.css' | url }}">
<link rel="alternate" href="{{ metadata.feed.path | url }}" type="application/atom+xml" title="{{ metadata.title }}">
</head>
<body>
<header>
<h1 class="home"><a href="{{ '/' | url }}">{{ metadata.title }}</a></h1>
<ul class="nav">
{%- for nav in collections.nav | reverse -%}
<li class="nav-item{% if nav.url == page.url %} nav-item-active{% endif %}"><a href="{{ nav.url | url }}">{{ nav.data.navtitle }}</a></li>
{%- endfor -%}
</ul>
</header>

<main{% if templateClass %} class="{{ templateClass }}"{% endif %}>
<div class="warning">
<ol>
<li>Edit the <code>_data/metadata.json</code> with your blog’s information.</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>
</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>
</div>
<main{% if templateClass %} class="{{ templateClass }}"{% endif %}>
<div class="warning">
<ol>
<li>Edit the <code>_data/metadata.json</code> with your blog’s information.</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>
</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>
</div>

{{ content | safe }}
</main>
{{ content | safe }}
</main>

<footer></footer>
<footer></footer>

<!-- Current page: {{ page.url | url }} -->
</body>
<!-- Current page: {{ page.url | url }} -->
</body>
</html>
2 changes: 1 addition & 1 deletion _includes/postslist.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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>
<time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time>
{% for tag in post.data.tags %}
{%- if tag != "post" -%}
{%- if tag != "posts" -%}
{% set tagUrl %}/tags/{{ tag }}/{% endset %}
<a href="{{ tagUrl | url }}" class="tag">{{ tag }}</a>
{%- endif -%}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
"devDependencies": {
"@11ty/eleventy": "^0.5.4",
"@11ty/eleventy": "^0.7.0",
"@11ty/eleventy-plugin-rss": "^1.0.3",
"@11ty/eleventy-plugin-syntaxhighlight": "^2.0.0",
"luxon": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion posts/firstpost.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: This is my first post.
description: This is a post on My Blog about agile frameworks.
date: 2018-05-01
tags:
- post
- another-tag
layout: layouts/post.njk
---
Expand Down
1 change: 1 addition & 0 deletions posts/fourthpost.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: This is my fourth post.
description: This is a post on My Blog about touchpoints and circling wagons.
date: 2018-09-30
tags: second-tag
layout: layouts/post.njk
Expand Down
5 changes: 5 additions & 0 deletions posts/posts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tags": [
"posts"
]
}
2 changes: 1 addition & 1 deletion posts/secondpost.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: This is my second post.
description: This is a post on My Blog about leveraging agile frameworks.
date: 2018-07-04
tags:
- post
- number-2
layout: layouts/post.njk
---
Expand Down
2 changes: 1 addition & 1 deletion posts/thirdpost.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: This is my third post.
description: This is a post on My Blog about win-win survival strategies.
date: 2018-08-24
tags:
- post
- second-tag
layout: layouts/post.njk
---
Expand Down

0 comments on commit 4969823

Please sign in to comment.