1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
reyasume/.eleventy.js

252 lines
8.9 KiB

Set up for Eleventy and add resources. Squashed commit of the following: commit 58781e4e2c883b7a26d371250ed1f3aa88dcc7bf Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 17:36:30 2020 +0900 Set up the basic eleventy templates. commit a5adff6749345e2a08895b6d6efe976fd6712d60 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:55:50 2020 +0900 Install markdown-it and set up .eleventy.js commit fc6f413e80fc77048af1d9f391d5ad1623b171c2 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:23:35 2020 +0900 Add .nvmrc and netlify.toml for deployment commit fe7ee3d07ea9606e17bf66503aa8758e5669e732 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:14:24 2020 +0900 Add .eleventyignore which skips README.md. commit 4614029ef4529537cc13a64dd8cb854fdc57a6a6 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:07:03 2020 +0900 Add npx and cross-env, scripts, more links. commit 21e7127a5f7bd0245aa46db333c5d1ee6b988476 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:55:32 2020 +0900 Add Netlify status badge to README.md. commit 5a4dc75f8ec8fdbd555aa00c34cf01451eb76517 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:50:50 2020 +0900 Install Eleventy. commit 1680633c111ffd8e8d3348f81995d2e141eae2b4 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:46:52 2020 +0900 Add initial tiny package.json. commit d33a877725172cbd7f5ff0f7d6bfc69293bc7079 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:42:21 2020 +0900 Add a basic node-stuff .gitignore. commit c38c934f7f2a2a20740d7652024ec6472462772e Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:38:39 2020 +0900 Add something like a real README.md. commit 586a2d680aa68983b66e1d5b7eb372f0df31a690 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:25:02 2020 +0900 Add commissioned art and favicon package
4 years ago
const HTMLMinifier = require("html-minifier");
const CleanCSS = require("clean-css");
const UglifyES = require("uglify-es");
const MarkdownIt = require("markdown-it");
const JSYaml = require("js-yaml");
require('intl');
Set up for Eleventy and add resources. Squashed commit of the following: commit 58781e4e2c883b7a26d371250ed1f3aa88dcc7bf Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 17:36:30 2020 +0900 Set up the basic eleventy templates. commit a5adff6749345e2a08895b6d6efe976fd6712d60 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:55:50 2020 +0900 Install markdown-it and set up .eleventy.js commit fc6f413e80fc77048af1d9f391d5ad1623b171c2 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:23:35 2020 +0900 Add .nvmrc and netlify.toml for deployment commit fe7ee3d07ea9606e17bf66503aa8758e5669e732 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:14:24 2020 +0900 Add .eleventyignore which skips README.md. commit 4614029ef4529537cc13a64dd8cb854fdc57a6a6 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:07:03 2020 +0900 Add npx and cross-env, scripts, more links. commit 21e7127a5f7bd0245aa46db333c5d1ee6b988476 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:55:32 2020 +0900 Add Netlify status badge to README.md. commit 5a4dc75f8ec8fdbd555aa00c34cf01451eb76517 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:50:50 2020 +0900 Install Eleventy. commit 1680633c111ffd8e8d3348f81995d2e141eae2b4 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:46:52 2020 +0900 Add initial tiny package.json. commit d33a877725172cbd7f5ff0f7d6bfc69293bc7079 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:42:21 2020 +0900 Add a basic node-stuff .gitignore. commit c38c934f7f2a2a20740d7652024ec6472462772e Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:38:39 2020 +0900 Add something like a real README.md. commit 586a2d680aa68983b66e1d5b7eb372f0df31a690 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:25:02 2020 +0900 Add commissioned art and favicon package
4 years ago
const markdownIt = MarkdownIt({
html: true,
breaks: true,
linkify: true
});
module.exports = function(eleventyConfig) {
eleventyConfig.setLibrary("md", markdownIt);
eleventyConfig.addPassthroughCopy({
"static/favicon": ".",
"static/img": "img"
});
eleventyConfig.addFilter("monthAndYear", function(date) {
return date.toLocaleDateString(undefined, {
year: "numeric",
month: "short"
});
});
// Creates a child object with a new or overridden property without affecting
// the original.
function inheritAndAdd(base, newProperties) {
return Object.assign(Object.create(base), newProperties);
}
// Sorts highlights before lowlights, and adds a highlight boolean property.
//
// itemList is an array of objects with "id" (string) properties
// filter is a specification for how to filter this list, which can be:
// * true or "all", in which case all items are highlights
// * some falsy value, in which case no items are highlights
// * an array containing item IDs which are highlights and others are
// lowlights
// * an array containing "all" and item IDs each prepended by "-", where
// negated IDs are lowlights and others are highlights
// * an object, in which case its keys are used as an array (as above)m
// regardless of their values
// Returns an array of objects, each of which has a one-to-one correspondence
// with an input item, using that object as its prototype and adding a
// boolean "highlight" property. Order is preserved within highlights and
// lowlights, but highlights are first in the list.
function identifyHighlights(itemList, filter) {
if (!Array.isArray(itemList)) {
return itemList;
}
const highlights = [];
const lowlights = [];
if (!Array.isArray(filter)) {
if (filter === true || filter === "all") {
filter = ["all"]
} else if (typeof filter === "object") {
filter = Object.keys(filter);
} else {
filter = [];
}
}
itemList.forEach(function(item) {
if ((filter.includes("all")
&& !filter.includes("-" + item.id))
|| filter.includes(item.id)) {
highlights.push(inheritAndAdd(item, {highlight: true}));
} else {
lowlights.push(inheritAndAdd(item, {highlight: false}));
}
});
return highlights.concat(lowlights);
}
eleventyConfig.addFilter("identifyHighlights", identifyHighlights);
// Sorts highlights before lowlights for this list and each of the child
// layers listed.
//
// itemList is an array of objects with
// "id" (string) and headAttribute (list of object) properties.
// filter is a specification for how to filter this list and its children:
// * true or "all", in which case all items on all layers are highlights
// * some falsy value, in which case all items on all layers are lowlights
// * an array containing item IDs, in which case all matching items on this
// layer are highlights, as well as all of their descendants, and all
// non-matching items on this layer and all of their descendants are
// lowlights
// * an array containing "all" and item IDs preceded by "-", in which case all
// negated IDs and their descendants are lowlights, and all others and
// their descendants are highlights
// * an object whose keys are used as an array (as above) to match this layer,
// but whose values are used as the value for filter when recursively
// calling on the value of headAttribute.
// If one of these keys exists, the child will be called with its value as
// the filter argument, in this order:
// * child.id
// * "-" + child.id
// * "all"
// * "-all"
// Otherwise, the child will be called with false.
// headAttribute, nextAttribute, and tailAttributes are strings; nextAttribute
// and tailAttributes are optional.
// Returns an array of objects, each of which has a one-to-one correspondence
// with an input item, using that object as its prototype and adding a
// boolean "highlight" property and a list of objects headAttribute property
// fulfilling the same type of contract as described here. Order is
// preserved within highlights and lowlights, but highlights are first in
// the list.
function identifyHighlightsRecursive(itemList, filter, headAttribute, nextAttribute, ...tailAttributes) {
if (Array.isArray(filter)) {
const newFilter = {};
filter.forEach(function(item) {
if (item.startsWith("-")) {
newFilter[item] = false;
} else {
newFilter[item] = true;
}
});
filter = newFilter;
} else if (typeof filter !== "object"){
if (filter === true || filter === "all") {
filter = { "all": true };
} else {
filter = {};
}
}
const highlightList = identifyHighlights(itemList, filter);
if (!headAttribute || !Array.isArray(highlightList)) {
return highlightList;
}
highlightList.forEach(function(item) {
if (!(headAttribute in item)) {
// can't recurse into an item which doesn't have our recursive property
return;
}
const children = item[headAttribute];
const match = [item.id, "-" + item.id, "all", "-all"].find((key) => key in filter);
const childFilter = match ? filter[match] : false;
// safe to modify in-place because we got this result back from
// identifyHighlights, which inherits from its input
item[headAttribute] = identifyHighlightsRecursive(children, childFilter, nextAttribute, ...tailAttributes);
});
return highlightList;
}
eleventyConfig.addFilter("identifyHighlightsRecursive", identifyHighlightsRecursive);
// Checks if there are any items with a truthy highlight property in itemList.
function hasHighlights(itemList) {
if (!Array.isArray(itemList)) {
return false;
}
return itemList.some(function(item) {
return item.highlight;
});
}
eleventyConfig.addFilter("hasHighlights", hasHighlights);
// Checks if there are any items with a falsy highlight property in itemList.
function hasLowlights(itemList) {
if (!Array.isArray(itemList)) {
return false;
}
return itemList.some(function(item) {
return !item.highlight;
});
}
eleventyConfig.addFilter("hasLowlights", hasLowlights);
// Checks if there are any items within this list or its children with a
// truthy highlight property.
function hasHighlightsRecursive(itemList, headAttribute, nextAttribute, tailAttributes) {
if (!Array.isArray(itemList)) {
return false;
}
return hasHighlights(itemList) || itemList.some(
(child) => headAttribute in child && child.hasHighlightsRecursive(
child[headAttribute], nextAttribute, ...tailAttributes));
}
eleventyConfig.addFilter("hasHighlightsRecursive", hasHighlightsRecursive);
// Checks if there are any items within this list or its children with a
// falsy highlight property.
function hasLowlightsRecursive(itemList, headAttribute, nextAttribute, tailAttributes) {
if (!Array.isArray(itemList)) {
return false;
}
return hasLowlights(itemList) || itemList.some(
(child) => headAttribute in child && child.hasLowlightsRecursive(
child[headAttribute], nextAttribute, ...tailAttributes));
}
eleventyConfig.addFilter("hasLowlightsRecursive", hasLowlightsRecursive);
eleventyConfig.addFilter("md", function(content) {
return markdownIt.render(content);
});
Set up for Eleventy and add resources. Squashed commit of the following: commit 58781e4e2c883b7a26d371250ed1f3aa88dcc7bf Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 17:36:30 2020 +0900 Set up the basic eleventy templates. commit a5adff6749345e2a08895b6d6efe976fd6712d60 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:55:50 2020 +0900 Install markdown-it and set up .eleventy.js commit fc6f413e80fc77048af1d9f391d5ad1623b171c2 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:23:35 2020 +0900 Add .nvmrc and netlify.toml for deployment commit fe7ee3d07ea9606e17bf66503aa8758e5669e732 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:14:24 2020 +0900 Add .eleventyignore which skips README.md. commit 4614029ef4529537cc13a64dd8cb854fdc57a6a6 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:07:03 2020 +0900 Add npx and cross-env, scripts, more links. commit 21e7127a5f7bd0245aa46db333c5d1ee6b988476 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:55:32 2020 +0900 Add Netlify status badge to README.md. commit 5a4dc75f8ec8fdbd555aa00c34cf01451eb76517 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:50:50 2020 +0900 Install Eleventy. commit 1680633c111ffd8e8d3348f81995d2e141eae2b4 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:46:52 2020 +0900 Add initial tiny package.json. commit d33a877725172cbd7f5ff0f7d6bfc69293bc7079 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:42:21 2020 +0900 Add a basic node-stuff .gitignore. commit c38c934f7f2a2a20740d7652024ec6472462772e Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:38:39 2020 +0900 Add something like a real README.md. commit 586a2d680aa68983b66e1d5b7eb372f0df31a690 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:25:02 2020 +0900 Add commissioned art and favicon package
4 years ago
eleventyConfig.addTransform("minifyHTML", function(html, path) {
if(path && path.endsWith(".html")) {
return HTMLMinifier.minify(html, {
collapseWhitespace: true,
removeComments: true,
useShortDoctype: true,
});
}
return html;
});
eleventyConfig.addNunjucksAsyncFilter("minifyCSS", function(code, callback) {
return new CleanCSS({ level: 2, inline: ['all'] }).minify(code, (err, result) => {
if (err) {
callback(err, null);
} else {
callback(null, result.styles);
}
});
Set up for Eleventy and add resources. Squashed commit of the following: commit 58781e4e2c883b7a26d371250ed1f3aa88dcc7bf Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 17:36:30 2020 +0900 Set up the basic eleventy templates. commit a5adff6749345e2a08895b6d6efe976fd6712d60 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:55:50 2020 +0900 Install markdown-it and set up .eleventy.js commit fc6f413e80fc77048af1d9f391d5ad1623b171c2 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:23:35 2020 +0900 Add .nvmrc and netlify.toml for deployment commit fe7ee3d07ea9606e17bf66503aa8758e5669e732 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:14:24 2020 +0900 Add .eleventyignore which skips README.md. commit 4614029ef4529537cc13a64dd8cb854fdc57a6a6 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:07:03 2020 +0900 Add npx and cross-env, scripts, more links. commit 21e7127a5f7bd0245aa46db333c5d1ee6b988476 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:55:32 2020 +0900 Add Netlify status badge to README.md. commit 5a4dc75f8ec8fdbd555aa00c34cf01451eb76517 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:50:50 2020 +0900 Install Eleventy. commit 1680633c111ffd8e8d3348f81995d2e141eae2b4 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:46:52 2020 +0900 Add initial tiny package.json. commit d33a877725172cbd7f5ff0f7d6bfc69293bc7079 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:42:21 2020 +0900 Add a basic node-stuff .gitignore. commit c38c934f7f2a2a20740d7652024ec6472462772e Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:38:39 2020 +0900 Add something like a real README.md. commit 586a2d680aa68983b66e1d5b7eb372f0df31a690 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:25:02 2020 +0900 Add commissioned art and favicon package
4 years ago
});
eleventyConfig.addFilter("minifyJS", function(code) {
let minified = UglifyES.minify(code);
if(minified.error) {
console.log("UglifyES failed with an error: ", minified.error);
throw new Error("Javascript minification failure");
}
return minified.code;
});
eleventyConfig.addDataExtension("yaml", contents => JSYaml.safeLoad(contents));
Set up for Eleventy and add resources. Squashed commit of the following: commit 58781e4e2c883b7a26d371250ed1f3aa88dcc7bf Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 17:36:30 2020 +0900 Set up the basic eleventy templates. commit a5adff6749345e2a08895b6d6efe976fd6712d60 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:55:50 2020 +0900 Install markdown-it and set up .eleventy.js commit fc6f413e80fc77048af1d9f391d5ad1623b171c2 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:23:35 2020 +0900 Add .nvmrc and netlify.toml for deployment commit fe7ee3d07ea9606e17bf66503aa8758e5669e732 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:14:24 2020 +0900 Add .eleventyignore which skips README.md. commit 4614029ef4529537cc13a64dd8cb854fdc57a6a6 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 16:07:03 2020 +0900 Add npx and cross-env, scripts, more links. commit 21e7127a5f7bd0245aa46db333c5d1ee6b988476 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:55:32 2020 +0900 Add Netlify status badge to README.md. commit 5a4dc75f8ec8fdbd555aa00c34cf01451eb76517 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:50:50 2020 +0900 Install Eleventy. commit 1680633c111ffd8e8d3348f81995d2e141eae2b4 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:46:52 2020 +0900 Add initial tiny package.json. commit d33a877725172cbd7f5ff0f7d6bfc69293bc7079 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:42:21 2020 +0900 Add a basic node-stuff .gitignore. commit c38c934f7f2a2a20740d7652024ec6472462772e Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:38:39 2020 +0900 Add something like a real README.md. commit 586a2d680aa68983b66e1d5b7eb372f0df31a690 Author: Mari <mstaib.git@reya.zone> Date: Sun Jan 12 15:25:02 2020 +0900 Add commissioned art and favicon package
4 years ago
return {
templateFormats: [
"html",
"md",
"njk"
],
pathPrefix: "",
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
passthroughFileCopy: true,
dir: {
input: ".",
includes: "_includes",
data: "_data",
output: "_site"
}
};
}