Skip to content

Commit

Permalink
Merge pull request #184 from 11ty/v9
Browse files Browse the repository at this point in the history
Eleventy Base Blog v9 (using Eleventy v3 and ESM)
  • Loading branch information
zachleat authored Oct 1, 2024
2 parents 231c29b + 9b0cb97 commit bff655c
Show file tree
Hide file tree
Showing 36 changed files with 402 additions and 431 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
20
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# eleventy-base-blog v8
# eleventy-base-blog v9

A starter repository showing how to build a blog with the [Eleventy](https://www.11ty.dev/) site generator (using the [v2.0 release](https://www.11ty.dev/blog/eleventy-v2/)).

Expand Down Expand Up @@ -45,36 +45,35 @@ Or you can run [debug mode](https://www.11ty.dev/docs/debugging/) to see all the

## Features

- Using [Eleventy v2.0](https://www.11ty.dev/blog/eleventy-v2/) with zero-JavaScript output.
- Using [Eleventy v3](https://github.com/11ty/eleventy/releases/tag/v3.0.0) with zero-JavaScript output.
- Content is exclusively pre-rendered (this is a static site).
- Can easily [deploy to a subfolder without changing any content](https://www.11ty.dev/docs/plugins/html-base/)
- All URLs are decoupled from the content’s location on the file system.
- Configure templates via the [Eleventy Data Cascade](https://www.11ty.dev/docs/data-cascade/)
- **Performance focused**: four-hundos Lighthouse score out of the box!
- [View the Lighthouse report for the latest build](https://eleventy-base-blog.netlify.app/reports/lighthouse/) courtesy of the [Netlify Lighthouse plugin](https://github.com/netlify/netlify-plugin-lighthouse).
- _0 Cumulative Layout Shift_
- _0ms Total Blocking Time_
- Local development live reload provided by [Eleventy Dev Server](https://www.11ty.dev/docs/dev-server/).
- Content-driven [navigation menu](https://www.11ty.dev/docs/plugins/navigation/)
- [Image optimization](https://www.11ty.dev/docs/plugins/image/) via the `{% image %}` shortcode.
- Fully automated [Image optimization](https://www.11ty.dev/docs/plugins/image/)
- Zero-JavaScript output.
- Support for modern image formats automatically (e.g. AVIF and WebP)
- Processes images on-request during `--serve` for speedy local builds.
- Prefers `<img>` markup if possible (single image format) but switches automatically to `<picture>` for multiple image formats.
- Automated `<picture>` syntax markup with `srcset` and optional `sizes`
- Includes `width`/`height` attributes to avoid [content layout shift](https://web.dev/cls/).
- Includes `loading="lazy"` for native lazy loading without JavaScript.
- Includes [`decoding="async"`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding)
- Images can be co-located with blog post files.
- View the [Image plugin source code](https://github.com/11ty/eleventy-base-blog/blob/main/eleventy.config.images.js)
- Per page CSS bundles [via `eleventy-plugin-bundle`](https://github.com/11ty/eleventy-plugin-bundle).
- Built-in [syntax highlighter](https://www.11ty.dev/docs/plugins/syntaxhighlight/) (zero-JavaScript output).
- Draft content: use `draft: true` to mark any template as a draft. Drafts are **only** included during `--serve`/`--watch` and are excluded from full builds. This is driven by the `addPreprocessor` configuration API in `eleventy.config.js`. Schema validator will show an error if non-boolean value is set in data cascade.
- Blog Posts
- Draft posts: use `draft: true` to mark a blog post as a draft. Drafts are **only** included during `--serve`/`--watch` and are excluded from full builds. View the [Drafts plugin source code](https://github.com/11ty/eleventy-base-blog/blob/main/eleventy.config.drafts.js).
- Automated next/previous links
- Accessible deep links to headings
- Generated Pages
- Home, Archive, and About pages.
- [Feeds for Atom and JSON](https://www.11ty.dev/docs/plugins/rss/)
- [Atom feed included (with easy one-line swap to use RSS or JSON](https://www.11ty.dev/docs/plugins/rss/)
- `sitemap.xml`
- Zero-maintenance tag pages ([View on the Demo](https://eleventy-base-blog.netlify.app/tags/))
- Content not found (404) page
Expand All @@ -83,20 +82,19 @@ Or you can run [debug mode](https://www.11ty.dev/docs/debugging/) to see all the

- [Netlify](https://eleventy-base-blog.netlify.app/)
- [Vercel](https://demo-base-blog.11ty.dev/)
- [GitHub Pages](https://11ty.github.io/eleventy-base-blog/)
- [Remix on Glitch](https://glitch.com/~11ty-eleventy-base-blog)
- [Cloudflare Pages](https://eleventy-base-blog-d2a.pages.dev/)
- [GitHub Pages](https://11ty.github.io/eleventy-base-blog/)

## Deploy this to your own site

Deploy this Eleventy site in just a few clicks on these services:

- Read more about [Deploying an Eleventy project](https://www.11ty.dev/docs/deployment/) to the web.
- [Deploy this to **Netlify**](https://app.netlify.com/start/deploy?repository=https://github.com/11ty/eleventy-base-blog)
- [Deploy this to **Vercel**](https://vercel.com/import/project?template=11ty%2Feleventy-base-blog)
- Look in `.github/workflows/gh-pages.yml.sample` for information on Deploying to **GitHub Pages**.
- [Try it out on **Stackblitz**](https://stackblitz.com/github/11ty/eleventy-base-blog)
- If you run Eleventy locally you can drag your `_site` folder to [`netlify.com/drop`](https://netlify.com/drop) to upload it without using `git`.
- Read more about [Deploying an Eleventy project](https://www.11ty.dev/docs/deployment/) to the web.

### Implementation Notes

Expand All @@ -105,9 +103,6 @@ Deploy this Eleventy site in just a few clicks on these services:
- Use the `eleventyNavigation` key (via the [Eleventy Navigation plugin](https://www.11ty.dev/docs/plugins/navigation/)) in your front matter to add a template to the top level site navigation. This is in use on `content/index.njk` and `content/about/index.md`.
- Content can be in _any template format_ (blog posts needn’t exclusively be markdown, for example). Configure your project’s supported templates in `eleventy.config.js` -> `templateFormats`.
- The `public` folder in your input directory will be copied to the output folder (via `addPassthroughCopy` in the `eleventy.config.js` file). This means `./public/css/*` will live at `./_site/css/*` after your build completes.
- Provides two content feeds:
- `content/feed/feed.njk`
- `content/feed/json.njk`
- This project uses three [Eleventy Layouts](https://www.11ty.dev/docs/layouts/):
- `_includes/layouts/base.njk`: the top level HTML structure
- `_includes/layouts/home.njk`: the home page template (wrapped into `base.njk`)
Expand Down
40 changes: 40 additions & 0 deletions _config/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { DateTime } from "luxon";

export default function(eleventyConfig) {
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(format || "dd LLLL yyyy");
});

eleventyConfig.addFilter("htmlDateString", (dateObj) => {
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat('yyyy-LL-dd');
});

// Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => {
if(!Array.isArray(array) || array.length === 0) {
return [];
}
if( n < 0 ) {
return array.slice(n);
}

return array.slice(0, n);
});

// Return the smallest number argument
eleventyConfig.addFilter("min", (...numbers) => {
return Math.min.apply(null, numbers);
});

// Return the keys used in an object
eleventyConfig.addFilter("getKeys", target => {
return Object.keys(target);
});

eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "posts"].indexOf(tag) === -1);
});

};
13 changes: 13 additions & 0 deletions _data/eleventyDataSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from "zod";
import { fromZodError } from 'zod-validation-error';

export default function(data) {
// Draft content, validate `draft` front matter
let result = z.object({
draft: z.boolean().or(z.undefined()),
}).safeParse(data);

if(result.error) {
throw fromZodError(result.error);
}
}
4 changes: 2 additions & 2 deletions _data/metadata.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
title: "Eleventy Base Blog v8",
export default {
title: "Eleventy Base Blog v9",
url: "https://example.com/",
language: "en",
description: "I am writing about my experiences as a naval navel-gazer.",
Expand Down
36 changes: 22 additions & 14 deletions _includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,36 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title or metadata.title }}</title>
<meta name="description" content="{{ description or metadata.description }}">

{#- Atom and JSON feeds included by default #}
<link rel="alternate" href="/feed/feed.xml" type="application/atom+xml" title="{{ metadata.title }}">
<link rel="alternate" href="/feed/feed.json" type="application/json" title="{{ metadata.title }}">
<link rel="alternate" href="feed/feed.xml" type="application/atom+xml" title="{{ metadata.title }}">

{#- Uncomment this if you’d like folks to know that you used Eleventy to build your site! #}
{#- <meta name="generator" content="{{ eleventy.generator }}"> #}

{#-
CSS bundles are provided via the `eleventy-plugin-bundle` plugin:
1. You can add to them using `{% css %}`
2. You can get from them using `{% getBundle "css" %}` or `{% getBundleFileUrl "css" %}`
3. You can do the same for JS: {% js %}{% endjs %} and <script>{% getBundle "js" %}</script>
4. Learn more: https://github.com/11ty/eleventy-plugin-bundle
Plain-text bundles are provided via the `eleventy-plugin-bundle` plugin:
1. CSS:
* Add to a per-page bundle using `{% css %}{% endcss %}`
* Retrieve bundle content using `{% getBundle "css" %}` or `{% getBundleFileUrl "css" %}`
2. Or for JavaScript:
* Add to a per-page bundle using `{% js %}{% endjs %}`
* Retrieve via `{% getBundle "js" %}` or `{% getBundleFileUrl "js" %}`
3. Learn more: https://github.com/11ty/eleventy-plugin-bundle
#}

{#- Add an arbitrary string to the bundle #}
{%- css %}* { box-sizing: border-box; }{% endcss %}
{%- css %}/* This is an arbitrary CSS string added to the bundle */{% endcss %}
{#- Add the contents of a file to the bundle #}
{%- css %}{% include "public/css/index.css" %}{% endcss %}
{#- Or add from node_modules #}
{#- Or you can add from node_modules #}
{# {%- css %}{% include "node_modules/prismjs/themes/prism-okaidia.css" %}{% endcss %} #}

{#- Render the CSS bundle using Inlined CSS (for the fastest site performance in production) #}
{#- Render the CSS bundle using inlined CSS (for the fastest site performance in production) #}
<style>{% getBundle "css" %}</style>
{#- Renders the CSS bundle using a separate file, if you can't set CSP directive style-src: 'unsafe-inline' #}
{#- <link rel="stylesheet" href="{% getBundleFileUrl "css" %}"> #}

{#- Add the heading-anchors web component to the JavaScript bundle #}
{%- js %}{% include "node_modules/@zachleat/heading-anchors/heading-anchors.js" %}{% endjs %}
</head>
<body>
<a href="#skip" class="visually-hidden">Skip to main content</a>
Expand All @@ -51,11 +54,16 @@
</header>

<main id="skip">
{{ content | safe }}
<heading-anchors>
{{ content | safe }}
</heading-anchors>
</main>

<footer></footer>
<footer>
<p><em>Built with <a href="https://www.11ty.dev/">{{ eleventy.generator }}</a></em></p>
</footer>

<!-- This page `{{ page.url | htmlBaseUrl }}` was built on {% currentBuildDate %} -->
<script type="module" src="{% getBundleFileUrl "js" %}"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions _includes/layouts/home.njk
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
layout: layouts/base.njk
---
<!-- Delete this message, it will also remove the component CSS from the bundle -->
<!-- Delete this block, which will also remove the component CSS from the bundle -->
{%- css %}{% include "public/css/message-box.css" %}{% endcss %}
<div class="message-box">
<ol>
<li>Edit the <code>_data/metadata.js</code> with your blog’s information.</li>
<li>Edit <code>_data/metadata.js</code> with your blog’s information.</li>
<li>(Optional) Edit <code>eleventy.config.js</code> with your <a href="https://www.11ty.dev/docs/config/">configuration preferences</a>.</li>
<li>Delete this message from <code>_includes/layouts/home.njk</code>.</li>
</ol>
Expand Down
6 changes: 3 additions & 3 deletions _includes/layouts/post.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: layouts/base.njk
---
{# Only include the syntax highlighter CSS on blog posts #}
{# Only include the syntax highlighter CSS on blog posts, included with the CSS per-page bundle #}
{%- css %}{% include "node_modules/prismjs/themes/prism-okaidia.css" %}{% endcss %}
{%- css %}{% include "public/css/prism-diff.css" %}{%- endcss %}
<h1>{{ title }}</h1>
Expand All @@ -21,8 +21,8 @@ layout: layouts/base.njk
{%- set nextPost = collections.posts | getNextCollectionItem %}
{%- if nextPost or previousPost %}
<ul class="links-nextprev">
{%- if previousPost %}<li>Previous: <a href="{{ previousPost.url }}">{{ previousPost.data.title }}</a></li>{% endif %}
{%- if nextPost %}<li>Next: <a href="{{ nextPost.url }}">{{ nextPost.data.title }}</a></li>{% endif %}
{%- if previousPost %}<li class="links-nextprev-prev">← Previous<br> <a href="{{ previousPost.url }}">{{ previousPost.data.title }}</a></li>{% endif %}
{%- if nextPost %}<li class="links-nextprev-next">Next →<br><a href="{{ nextPost.url }}">{{ nextPost.data.title }}</a></li>{% endif %}
</ul>
{%- endif %}
{%- endif %}
3 changes: 1 addition & 2 deletions content/404.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
---
layout: layouts/home.njk
permalink: 404.html
eleventyExcludeFromCollections: true
---
# Content not found.

Go <a href="/">home</a>.
Go <a href="index.njk">home</a>.

<!--
Expand Down
9 changes: 9 additions & 0 deletions content/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---js
const eleventyNavigation = {
key: "About",
order: 3
};
---
# About

I am a person that writes stuff.
9 changes: 0 additions & 9 deletions content/about/index.md

This file was deleted.

10 changes: 5 additions & 5 deletions content/blog.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
layout: layouts/home.njk
eleventyNavigation:
key: Archive
order: 2
---js
const eleventyNavigation = {
key: "Archive",
order: 2
};
---
<h1>Archive</h1>

Expand Down
2 changes: 1 addition & 1 deletion content/blog/blog.11tydata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
tags: [
"posts"
],
Expand Down
8 changes: 4 additions & 4 deletions content/blog/fifthpost.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: This is a fifth post (draft)
date: 2023-01-23
draft: true
---js
const title = "This is a fifth post (draft)";
const date = "2023-01-23";
const draft = true;
---
This is a draft post
3 changes: 1 addition & 2 deletions content/blog/firstpost.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
title: This is my first post.
description: This is a post on My Blog about agile frameworks.
date: 2018-05-01
tags:
- another tag
tags: another tag
---
Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.

Expand Down
4 changes: 2 additions & 2 deletions content/blog/fourthpost/fourthpost.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
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
tags: second tag
Expand All @@ -8,7 +8,7 @@ Leverage agile frameworks to provide a robust synopsis for high level overviews.

Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.

{% image "./possum.png", "A possum parent and two possum kids hanging from the iconic red balloon" %}
<img src="./possum.png" alt="A possum parent and two possum kids hanging from the iconic red balloon">

## Section Header

Expand Down
7 changes: 3 additions & 4 deletions content/blog/secondpost.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
title: This is my second post with a much longer title.
description: This is a post on My Blog about leveraging agile frameworks.
date: 2018-07-04
tags:
- number 2
tags: number 2
---
Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.

## Section Header

<a href="/blog/firstpost/">First post</a>
<a href="/blog/thirdpost/">Third post</a>
<a href="/blog/firstpost.md">First post</a>
<a href="blog/thirdpost.md">Third post</a>

Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.

Expand Down
8 changes: 3 additions & 5 deletions content/blog/thirdpost.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
title: This is my third post.
description: This is a post on My Blog about win-win survival strategies.
date: 2018-08-24
tags:
- second tag
- posts with two tags
tags: ["second tag", "posts with two tags"]
---
Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.

## Code

### Styled (with Syntax)
### This is a very long heading that I want to wrap This is a very long heading that I want to wrap This is a very long heading that I want to wrap This is a very long heading that I want to wrap

Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.

Expand All @@ -25,7 +23,7 @@ function myCommand() {
console.log('Test');
```

### Unstyled
### Heading with a [link](#code)

Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.

Expand Down
3 changes: 3 additions & 0 deletions content/content.11tydata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
layout: "layouts/home.njk",
};
1 change: 1 addition & 0 deletions content/feed/.virtual
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For RSS feed, Atom Feed, and JSON feed templates, see the plugin in eleventy.config.js
3 changes: 0 additions & 3 deletions content/feed/feed.11tydata.js

This file was deleted.

Loading

0 comments on commit bff655c

Please sign in to comment.