Skip to content

Commit

Permalink
Add eleventyNavigation
Browse files Browse the repository at this point in the history
  • Loading branch information
xjensen committed Jan 9, 2024
1 parent 8267efd commit 9b5b230
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 66 deletions.
5 changes: 3 additions & 2 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const cagovBuildSystem = require("@cagov/11ty-build-system");
const linkedom = require("linkedom");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const fs = require('fs');

module.exports = function (eleventyConfig) {
eleventyConfig.htmlTemplateEngine = "njk";
const wordpressImagePath = "img/wordpress";

eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(cagovBuildSystem, {
processors: {
sass: {
Expand Down Expand Up @@ -65,8 +68,6 @@ module.exports = function (eleventyConfig) {
.reverse();
});

eleventyConfig.addPlugin(pluginRss);

eleventyConfig.addFilter("dateformat", function (dateString) {
const d = new Date(dateString);
return `${d.getMonth() + 1}/${d.getDate()}/${d.getFullYear()}`;
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@11ty/eleventy": "^2.0.1",
"@11ty/eleventy-navigation": "^0.3.5",
"@11ty/eleventy-plugin-rss": "^1.1.2",
"@cagov/11ty-build-system": "^1.0.0-beta.3",
"@cagov/ds-accordion": "^2.0.0",
Expand Down
16 changes: 0 additions & 16 deletions pages/_data/fileids.js

This file was deleted.

17 changes: 17 additions & 0 deletions pages/_includes/breadcrumb.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% macro breadcrumb(articleId, articleTitle, collections) %}
<div class="breadcrumb" aria-label="Breadcrumb" role="region">
<a class="crumb" href="https://ca.gov" title="CA.gov">CA.gov</a>

<span class="crumb separator">/</span>
<a class="crumb" href="/" title="Office of Data and Innovation">Office of Data and Innovation</a>

{% set crumbs = collections.all | eleventyNavigationBreadcrumb(articleId) %}
{%- for crumb in crumbs %}
<span class="crumb separator">/</span>
<span class="crumb">{{ crumb.title | safe }}</span>
{%- endfor %}

<span class="crumb separator">/</span>
<span class="crumb current">{{ articleTitle | safe }}</span>
</div>
{% endmacro %}
13 changes: 2 additions & 11 deletions pages/_includes/content.njk
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
{% extends "base-layout.njk" %}
{% from "breadcrumb.njk" import breadcrumb %}

{% block content %}
<div id="page-container" class="with-sidebar has-sidebar-left page-container-ds">
<div class="main-content-ds single-column">
<div class="breadcrumb" aria-label="Breadcrumb" role="region">
<a class="crumb" href="https://ca.gov" title="CA.gov">CA.gov</a>
<span class="crumb separator">/</span>
<a class="crumb" href="/" title="Office of Data and Innovation">Office of Data and Innovation</a>
{% if parentid %}
<span class="crumb separator">/</span>
<span class="crumb">{{ fileids[parentid] | safe }}</span>
{% endif %}
<span class="crumb separator">/</span>
<span class="crumb current">{{ title | safe }}</span>
</div>
{{ breadcrumb(id, title, collections) }}
<div class="ds-content-layout">
<aside>
<div class="sidebar-container everylayout" style="z-index: 1;">
Expand Down
13 changes: 2 additions & 11 deletions pages/_includes/single-column-conditional.njk
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
{% extends "base-layout.njk" %}
{% from "breadcrumb.njk" import breadcrumb %}

{% block content %}
<div id="page-container" class="page-container-ds">
<div class="breadcrumb" aria-label="Breadcrumb" role="region">
<a class="crumb" href="https://ca.gov" title="CA.gov">CA.gov</a>
<span class="crumb separator">/</span>
<a class="crumb" href="/" title="Office of Data and Innovation">Office of Data and Innovation</a>
{% if parentid %}
<span class="crumb separator">/</span>
<span class="crumb">{{ fileids[parentid] | safe }}</span>
{% endif %}
<span class="crumb separator">/</span>
<span class="crumb current">{{ title | safe }}</span>
</div>
{{ breadcrumb(id, title, collections) }}
<main id="body-content">
{% if previewimage %}
<img src="/{{ previewimage }}" class="mb-2" alt="" />
Expand Down
13 changes: 2 additions & 11 deletions pages/_includes/single-column.njk
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
{% extends "base-layout.njk" %}
{% from "breadcrumb.njk" import breadcrumb %}

{% block content %}
<div id="page-container" class="page-container-ds">
<div class="breadcrumb" aria-label="Breadcrumb" role="region">
<a class="crumb" href="https://ca.gov" title="CA.gov">CA.gov</a>
<span class="crumb separator">/</span>
<a class="crumb" href="/" title="Office of Data and Innovation">Office of Data and Innovation</a>
{% if parentid %}
<span class="crumb separator">/</span>
<span class="crumb">{{ fileids[parentid] | safe }}</span>
{% endif %}
<span class="crumb separator">/</span>
<span class="crumb current">{{ title | safe }}</span>
</div>
{{ breadcrumb(id, title, collections) }}
<main id="body-content">
<div class="single-column">
{% if previewimage %}
Expand Down
35 changes: 20 additions & 15 deletions pages/wordpress-pages/wordpress-pages.11tydata.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
function cleanUrl(url) {
if (url && url.includes(".pantheonsite.io/"))
return url.split(".pantheonsite.io/")[1] || "/";
return url;
}

module.exports = {
eleventyComputed: {
permalink: article => cleanUrl(article.data.wordpress_url),
title: article => article.data.title,
publishdate: article => article.data.date.split("T")[0],
date: article => article.data.date,
id: article => article.data.id,
tags: article => article.data.tags,
meta: article => article.data.excerpt,
description: article => article.data.excerpt,
permalink: article => {
const url = article.data.wordpress_url;
if (url && url.includes(".pantheonsite.io/"))
return url.split(".pantheonsite.io/")[1] || "/";
return url;
},
layout: article => {
if(article.data.tags.includes('layout-no-sidebar'))
if (article.data.tags.includes('layout-no-sidebar'))
return 'single-column';
if(article.page.url == "/")
return "landing";
if (!article.data.layout)
return "content";

return article.data.template;
},
publishdate: article => article.data.date.split("T")[0],
date: article => article.data.date,
parentid: article => article.data.parent,
tags: article => article.data.tags,
meta: article => article.data.excerpt,
description: article => article.data.excerpt,
eleventyNavigation: article => {
const key = article.data.id;
const title = article.data.title;
const wpParent = article.data.parent;
const parent = wpParent != 0 ? wpParent : undefined;
return { key, title, parent };
}
}
}

0 comments on commit 9b5b230

Please sign in to comment.