Browse Source

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

upstream
Zach Leatherman 3 years ago
parent
commit
496982355e
11 changed files with 51 additions and 52 deletions
  1. +6
    -12
      .eleventy.js
  2. +1
    -4
      _11ty/getTagList.js
  3. +1
    -0
      _data/metadata.json
  4. +32
    -31
      _includes/layouts/base.njk
  5. +1
    -1
      _includes/postslist.njk
  6. +1
    -1
      package.json
  7. +1
    -1
      posts/firstpost.md
  8. +1
    -0
      posts/fourthpost.md
  9. +5
    -0
      posts/posts.json
  10. +1
    -1
      posts/secondpost.md
  11. +1
    -1
      posts/thirdpost.md

+ 6
- 12
.eleventy.js View File

@ -5,6 +5,7 @@ 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");
@ -12,6 +13,11 @@ module.exports = function(eleventyConfig) {
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 ) {
@ -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");


+ 1
- 4
_11ty/getTagList.js View File

@ -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) {


+ 1
- 0
_data/metadata.json View File

@ -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",


+ 32
- 31
_includes/layouts/base.njk View File

@ -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>

+ 1
- 1
_includes/postslist.njk 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>
<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 -%}


+ 1
- 1
package.json View File

@ -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",


+ 1
- 1
posts/firstpost.md View File

@ -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
---


+ 1
- 0
posts/fourthpost.md View File

@ -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


+ 5
- 0
posts/posts.json View File

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

+ 1
- 1
posts/secondpost.md View File

@ -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
---


+ 1
- 1
posts/thirdpost.md View File

@ -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
---


Loading…
Cancel
Save