Skip to content

Commit 95ba38b

Browse files
committed
refactor to eleventyNavigation
1 parent 68af361 commit 95ba38b

73 files changed

Lines changed: 870 additions & 853 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eleventy.config.js

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,37 @@
1-
import { EleventyRenderPlugin } from "@11ty/eleventy";
2-
import markdownIt from "markdown-it";
3-
import markdownAnchor from "markdown-it-anchor";
1+
import { EleventyRenderPlugin, IdAttributePlugin } from "@11ty/eleventy";
42

53
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
6-
import { eleventyAlembic } from "@openlab/alembic/11ty.js";
4+
import eleventyAlembic from "@openlab/alembic/11ty.js";
5+
import eleventyNavigation from "@11ty/eleventy-navigation";
76
import slugify from "slugify";
87

98
import pkg from "./package.json" with { type: "json" };
109
import site from "./source/_data/site.json" with { type: "json" };
1110

12-
// TODO: refactor this out when upgrading to eleventy@2
13-
const md = markdownIt({
14-
html: true,
15-
});
16-
md.use(markdownAnchor, {
17-
slugify: (str) => slugify(str, { lower: true, strict: true }),
18-
});
19-
md.disable("code");
20-
21-
// TODO: add watch/rebuild for src in development mode?
22-
23-
/** @param {import('@11ty/eleventy/src/UserConfig')} eleventyConfig */
11+
/** @param {import('@11ty/eleventy/UserConfig').default} eleventyConfig */
2412
export default function (eleventyConfig) {
25-
eleventyConfig.setLibrary("md", md);
13+
eleventyConfig.setDataDeepMerge(true); // TODO: remove for eleventy@4
2614

15+
eleventyConfig.addPlugin(IdAttributePlugin);
2716
eleventyConfig.addPlugin(EleventyRenderPlugin);
2817
eleventyConfig.addPlugin(eleventyAlembic);
2918
eleventyConfig.addPlugin(syntaxHighlight);
19+
eleventyConfig.addPlugin(eleventyNavigation);
3020

31-
eleventyConfig.addFilter("apiSort", (items) => {
32-
return Array.from(items).sort((a, b) =>
33-
b.data.title.localeCompare(a.data.title),
34-
);
35-
});
3621
eleventyConfig.addFilter("fullUrl", (path) => {
3722
return new URL(path, site.url).href;
3823
});
3924
eleventyConfig.addFilter("isCurrentPage", (pageUrl, currentUrl) => {
4025
return currentUrl.startsWith(pageUrl);
4126
});
42-
eleventyConfig.addFilter("md", (content) => {
43-
// TODO: this seems to have 11ty's syntax added already
44-
return md.render(content);
45-
});
46-
eleventyConfig.addFilter("json", (content) =>
47-
JSON.stringify(content, null, 2),
48-
);
49-
eleventyConfig.addFilter("getPages", (collection, tags = []) => {
50-
const set = new Set(tags);
51-
return collection
52-
.filter((item) => item.data.tags?.some((t) => set.has(t)))
53-
.sort((a, b) => a.data.title?.localeCompare(b.data.title));
54-
});
55-
eleventyConfig.addFilter("slug", (text) => slugify(text));
5627

5728
eleventyConfig.addShortcode("pkgVersion", () => pkg.version);
5829
eleventyConfig.addPairedShortcode(
5930
"error",
6031
(content) => `<p class="eleventyError">${content}</p>`,
6132
);
6233

34+
// TODO: add watch/rebuild for src in development mode?
6335
// eleventyConfig.addWatchTarget('./source/**/*.css')
6436
// eleventyConfig.addWatchTarget('./source/**/*.ts')
6537
}

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
"build": "./scripts/build-library.js && ./scripts/build-docs.sh",
2828
"start": "NOVA_TASK_NAME=run npm run build",
2929
"test": "tsx --test **/*.test.*",
30-
"format": "prettier -w **/*.{js,ts,css,md,json,yml}"
30+
"format": "prettier --write '**/*.{js,ts,json,css,md}'"
3131
},
3232
"devDependencies": {
3333
"@11ty/eleventy": "^3.1.1",
34+
"@11ty/eleventy-navigation": "^1.0.5",
3435
"@11ty/eleventy-plugin-syntaxhighlight": "^5.0.1",
3536
"@types/node": "^22.19.15",
3637
"@types/svgo": "^2.6.3",

source/11ty.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,5 @@ export function eleventyAlembic(
118118
);
119119
});
120120
}
121+
122+
export default eleventyAlembic;

source/_data/layouts.json

Lines changed: 0 additions & 62 deletions
This file was deleted.

source/_data/nav.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

source/_includes/footer-nav.njk

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{% if footerNav %}
22
<footer class="docsLayout-footer">
33
<reel-layout class="layoutReel">
4-
{% for item in footerNav %}
5-
{% set page = collections[item.tag][0] %}
6-
<a href="#{{ item.id }}" class="layoutReel-item">
4+
{% for entry in collections.all | eleventyNavigation(footerNav) %}
5+
<a href="#{{ entry.title | lower | slugify }}" class="layoutReel-item">
76
<img
87
width="96"
98
height="96"
10-
src="{{ page.data.tile | url }}"
11-
alt="{{ item.name }}"
9+
src="{{ entry.data.tile | url }}"
10+
alt="{{ entry.title }}"
1211
/>
13-
<p>{{item.name}}</p>
12+
<p>{{ entry.title }}</p>
1413
</a>
1514
{% endfor %}
1615
</reel-layout>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
**Prerequisites**
22

3-
- Node.js v18+
4-
- npm v7+
3+
- Node.js v22+
54

65
Then install Alembic with NPM:
76

source/_includes/nav-cards.njk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{% from 'macros.njk' import icon %}
22

3-
{% if links %}
3+
{% if siblings %}
44
<grid-layout>
5-
{% for link in collections.all | getPages(links) %}
5+
{% for entry in collections.all | eleventyNavigation(siblings) %}
66
<box-layout class="navCard">
7-
<a href="{{ link.url }}">
7+
<a href="{{ entry.url }}">
88
<h2>
99
<icon-layout>
10-
{{ link.data.title }}
10+
{{ entry.title }}
1111
{{ icon('right') }}
1212
</icon-layout>
1313
</h2>
14-
<p> {{ link.data.strapline }} </p>
14+
<p> {{ entry.excerpt }} </p>
1515
</a>
1616
</box-layout>
1717
{% endfor %}

source/_includes/siblings.njk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
{% if siblings %}
55
<nav class="siblings" aria-labelledby="siblings">
6-
<p id="siblings">{{ siblingTitle or 'Pages' }}</p>
6+
<p id="siblings">{{ siblings }}</p>
77
<ul>
8-
{% for target in collections.all | getPages(siblings) %}
8+
{% for entry in collections.all | eleventyNavigation(siblings) %}
99
<li>
10-
{% if target.url | isCurrentPage(page.url) %}
11-
<strong>{{ target.data.title }}</strong>
10+
{% if entry.url == page.url %}
11+
<strong>{{ entry.title }}</strong>
1212
{% else %}
13-
<a href="{{ target.url }}" >
13+
<a href="{{ entry.url }}" >
1414
<icon-layout>
15-
{{ target.data.title }}
15+
{{ entry.title }}
1616
{{ icon('right') }}
1717
</icon-layout>
1818
</a>

0 commit comments

Comments
 (0)