Skip to content

Commit

Permalink
Added new logic and data to the results page
Browse files Browse the repository at this point in the history
  • Loading branch information
natashapl committed Oct 1, 2024
1 parent 7866090 commit 97f4e11
Show file tree
Hide file tree
Showing 220 changed files with 1,689 additions and 9,898 deletions.
152 changes: 79 additions & 73 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,60 @@
const { DateTime } = require('luxon');
const fs = require('fs');
const pluginRss = require('@11ty/eleventy-plugin-rss');
const pluginNavigation = require('@11ty/eleventy-navigation');
const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');
const { DateTime } = require("luxon");
const fs = require("fs");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginNavigation = require("@11ty/eleventy-navigation");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const yaml = require("js-yaml");
const svgSprite = require("eleventy-plugin-svg-sprite");
const { imageShortcode, imageWithClassShortcode } = require('./config');
const { imageShortcode, imageWithClassShortcode } = require("./config");
const htmlmin = require("html-minifier");
const UglifyJS = require("uglify-js");

module.exports = function (config) {
// Set pathPrefix for site
let pathPrefix = '/';

// Minify inline (not imported) JS
config.addFilter("jsmin", function (code) {
let minified = UglifyJS.minify(code);
if (minified.error) {
console.log("UglifyJS error: ", minified.error);
return code;
}
return minified.code;
});
// Minify HTML output
config.addTransform("htmlmin", function (content, outputPath) {
if (outputPath && outputPath.indexOf(".html") > -1) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
let pathPrefix = "/";

// Minify inline (not imported) JS
config.addFilter("jsmin", function (code) {
let minified = UglifyJS.minify(code);
if (minified.error) {
console.log("UglifyJS error: ", minified.error);
return code;
}
return minified.code;
});

// Minify HTML output
config.addTransform("htmlmin", function (content, outputPath) {
if (outputPath && outputPath.indexOf(".html") > -1) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});

// Copy the `admin` folders to the output
config.addPassthroughCopy('admin');
config.addPassthroughCopy("admin");

// Copy USWDS init JS so we can load it in HEAD to prevent banner flashing
config.addPassthroughCopy({'./node_modules/@uswds/uswds/dist/js/uswds-init.js': 'assets/js/uswds-init.js'});
config.addPassthroughCopy({ './node_modules/@uswds/uswds/dist/img': 'assets/uswds/img' });
config.addPassthroughCopy({ './node_modules/@uswds/uswds/dist/fonts': 'assets/fonts' });
config.addPassthroughCopy({ './theme/img': 'assets/img' });
config.addPassthroughCopy({ './favicon': '/favicon' });
config.addPassthroughCopy({ './favicon/favicon.ico': '/myfavicon.ico' });
config.addPassthroughCopy({ './pdf': 'assets/pdf' });
config.addPassthroughCopy({
"./node_modules/@uswds/uswds/dist/js/uswds-init.js":
"assets/js/uswds-init.js",
});
config.addPassthroughCopy({
"./node_modules/@uswds/uswds/dist/img": "assets/uswds/img",
});
config.addPassthroughCopy({
"./node_modules/@uswds/uswds/dist/fonts": "assets/fonts",
});
config.addPassthroughCopy({ "./_includes/theme/images": "assets/images" });
config.addPassthroughCopy({ "./favicon": "/favicon" });
config.addPassthroughCopy({ "./favicon/favicon.ico": "/myfavicon.ico" });
config.addPassthroughCopy({ "./pdf": "assets/pdf" });

// Add plugins
config.addPlugin(pluginRss);
Expand All @@ -56,33 +63,33 @@ module.exports = function (config) {
//// SVG Sprite Plugin for USWDS USWDS icons
config.addPlugin(svgSprite, {
path: "./node_modules/@uswds/uswds/dist/img/uswds-icons",
svgSpriteShortcode: 'uswds_icons_sprite',
svgShortcode: 'uswds_icons'
svgSpriteShortcode: "uswds_icons_sprite",
svgShortcode: "uswds_icons",
});

//// SVG Sprite Plugin for USWDS USA icons
config.addPlugin(svgSprite, {
path: "./node_modules/@uswds/uswds/dist/img/usa-icons",
svgSpriteShortcode: 'usa_icons_sprite',
svgShortcode: 'usa_icons'
svgSpriteShortcode: "usa_icons_sprite",
svgShortcode: "usa_icons",
});

// Allow yaml to be used in the _data dir
config.addDataExtension("yaml", contents => yaml.load(contents));
config.addDataExtension("yaml", (contents) => yaml.load(contents));

config.addFilter('readableDate', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat(
'dd LLL yyyy'
config.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
config.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd');
config.addFilter("htmlDateString", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat("yyyy-LL-dd");
});

// Get the first `n` elements of a collection.
config.addFilter('head', (array, n) => {
config.addFilter("head", (array, n) => {
if (!Array.isArray(array) || array.length === 0) {
return [];
}
Expand All @@ -94,20 +101,20 @@ module.exports = function (config) {
});

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

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

config.addFilter('filterTagList', filterTagList);
config.addFilter("filterTagList", filterTagList);

// Create an array of all tags
config.addCollection('tagList', function (collection) {
config.addCollection("tagList", function (collection) {
let tagSet = new Set();
collection.getAll().forEach((item) => {
(item.data.tags || []).forEach((tag) => tagSet.add(tag));
Expand All @@ -123,24 +130,24 @@ module.exports = function (config) {
linkify: true,
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
placement: 'after',
class: 'direct-link',
symbol: '#',
placement: "after",
class: "direct-link",
symbol: "#",
level: [1, 2, 3, 4],
}),
slugify: config.getFilter('slug'),
slugify: config.getFilter("slug"),
});
config.setLibrary('md', markdownLibrary);
config.setLibrary("md", markdownLibrary);

// Override Browsersync defaults (used only with --serve)
config.setBrowserSyncConfig({
callbacks: {
ready: function (err, browserSync) {
const content_404 = fs.readFileSync('_site/404/index.html');
const content_404 = fs.readFileSync("_site/404/index.html");

browserSync.addMiddleware('*', (req, res) => {
browserSync.addMiddleware("*", (req, res) => {
// Provides the 404 content without redirect.
res.writeHead(404, { 'Content-Type': 'text/html; charset=UTF-8' });
res.writeHead(404, { "Content-Type": "text/html; charset=UTF-8" });
res.write(content_404);
res.end();
});
Expand All @@ -151,35 +158,34 @@ module.exports = function (config) {
});

// Set image shortcodes
config.addLiquidShortcode('image', imageShortcode);
config.addLiquidShortcode('image_with_class', imageWithClassShortcode);
config.addLiquidShortcode("image", imageShortcode);
config.addLiquidShortcode("image_with_class", imageWithClassShortcode);
config.addLiquidShortcode("uswds_icon", function (name) {
return `
<svg class="usa-icon" aria-hidden="true" role="img">
<use xlink:href="#svg-${name}"></use>
</svg>`;
});


// If BASEURL env variable exists, update pathPrefix to the BASEURL
if (process.env.BASEURL) {
pathPrefix = process.env.BASEURL
pathPrefix = process.env.BASEURL;
}

return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: ['md', 'njk', 'html', 'liquid'],
templateFormats: ["md", "njk", "html", "liquid"],

// Pre-process *.md files with: (default: `liquid`)
// Other template engines are available
// See https://www.11ty.dev/docs/languages/ for other engines.
markdownTemplateEngine: 'liquid',
markdownTemplateEngine: "liquid",

// Pre-process *.html files with: (default: `liquid`)
// Other template engines are available
// See https://www.11ty.dev/docs/languages/ for other engines.
htmlTemplateEngine: 'liquid',
htmlTemplateEngine: "liquid",

// -----------------------------------------------------------------
// If your site deploys to a subdirectory, change `pathPrefix`.
Expand All @@ -197,10 +203,10 @@ module.exports = function (config) {

// These are all optional (defaults are shown):
dir: {
input: '.',
includes: '_includes',
data: '_data',
output: '_site',
input: ".",
includes: "_includes",
data: "_data",
output: "_site",
},
};
};
Loading

0 comments on commit 97f4e11

Please sign in to comment.