Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Eleventy 3.0 alpha 2 #19

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import eleventyPluginRSS from "@11ty/eleventy-plugin-rss";
import eleventyPluginTimeToRead from "eleventy-plugin-time-to-read";
import highlightJs from "highlight.js";
import markdownItAnchor from "markdown-it-anchor";
import MarkdownIt from "markdown-it";
import filters from "./lib/filters.js";

/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
module.exports = function (eleventyConfig) {
export default function (eleventyConfig) {
setUpLiquid(eleventyConfig);
setUpMarkdown(eleventyConfig);
setUpCollections(eleventyConfig);
Expand Down Expand Up @@ -34,15 +41,15 @@ module.exports = function (eleventyConfig) {
"assets/styles/highlight.js/github-dark.css",
});

eleventyConfig.addPlugin(require("@11ty/eleventy-plugin-rss"));
eleventyConfig.addPlugin(require("eleventy-plugin-time-to-read"));
eleventyConfig.addPlugin(eleventyPluginRSS);
eleventyConfig.addPlugin(eleventyPluginTimeToRead);

return {
dir: {
layouts: "_layouts",
},
};
};
}

function setUpLiquid(eleventyConfig) {
// Support unquoted filenames and a=b arguments in include tags like Jekyll
Expand All @@ -53,7 +60,6 @@ function setUpLiquid(eleventyConfig) {
});

// Import all filters in /lib/filters/index.js
const filters = require("./lib/filters");
Object.keys(filters).forEach((filter) =>
eleventyConfig.addFilter(filter, filters[filter]),
);
Expand Down Expand Up @@ -82,10 +88,10 @@ function setUpLiquid(eleventyConfig) {
}

function setUpMarkdown(eleventyConfig) {
const anchor = require("markdown-it-anchor");
const hljs = require("highlight.js");
const anchor = markdownItAnchor;
const hljs = highlightJs;

let markdownIt = require("markdown-it")({
let markdownIt = MarkdownIt({
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
Expand Down
2 changes: 1 addition & 1 deletion _data/layout.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = "default";
export default "default";
15 changes: 15 additions & 0 deletions lib/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { collapseWhitespace } from "./filters/collapse-whitespace.js";
import { exclude } from "./filters/exclude.js";
import { findBySlug } from "./filters/find-by-slug.js";
import { toHTMLDatetime } from "./filters/to-html-datetime.js";
import { whereExcludes } from "./filters/where-excludes.js";
import { whereIncludes } from "./filters/where-includes.js";

export default {
collapseWhitespace,
exclude,
findBySlug,
toHTMLDatetime,
whereExcludes,
whereIncludes,
};
8 changes: 3 additions & 5 deletions lib/filters/collapse-whitespace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
collapseWhitespace: function (str) {
return str.replace(/\s+/g, " ");
},
};
export function collapseWhitespace(str) {
return str.replace(/\s+/g, " ");
}
10 changes: 4 additions & 6 deletions lib/filters/exclude.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
module.exports = {
exclude: function (arr, toExclude) {
const arrayToExclude = [toExclude].flat();
return arr.filter((item) => !arrayToExclude.includes(item));
},
};
export function exclude(arr, toExclude) {
const arrayToExclude = [toExclude].flat();
return arr.filter((item) => !arrayToExclude.includes(item));
}
8 changes: 3 additions & 5 deletions lib/filters/find-by-slug.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
findBySlug: function (collection, slug) {
return collection.find(({ fileSlug }) => fileSlug === slug);
},
};
export function findBySlug(collection, slug) {
return collection.find(({ fileSlug }) => fileSlug === slug);
}
8 changes: 0 additions & 8 deletions lib/filters/index.js

This file was deleted.

8 changes: 3 additions & 5 deletions lib/filters/to-html-datetime.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
toHTMLDatetime: function (date) {
return date.toISOString();
},
};
export function toHTMLDatetime(date) {
return date.toISOString();
}
54 changes: 26 additions & 28 deletions lib/filters/where-excludes.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
const { isFalsy, toValue } = require("liquidjs");

module.exports = {
/**
* An enhancement to LiquidJS's where filter that looks for the specified
* value in an array, if one is found in the named field of each object,
* and filters *out* matching items.
*
* Most of the code in this file is borrowed from LiquidJS with types removed.
*
* TODO: Convert this back to TypeScript.
*/
whereExcludes: function* (arr, property, doNotWant) {
const values = [];
arr = toArray(toValue(arr));
for (const item of arr) {
values.push(
yield this.context._getFromScope(item, stringify(property).split("."))
);
}
return arr.filter((_, i) => {
if (doNotWant === undefined) return isFalsy(values[i], this.context);
if (isArray(values[i])) return !values[i].includes(doNotWant);
if (isComparable(doNotWant)) return !doNotWant.equals(values[i]);
return values[i] !== doNotWant;
});
},
};
import { isFalsy, toValue } from "liquidjs";

/**
* An enhancement to LiquidJS's where filter that looks for the specified
* value in an array, if one is found in the named field of each object,
* and filters *out* matching items.
*
* Most of the code in this file is borrowed from LiquidJS with types removed.
*
* TODO: Convert this back to TypeScript.
*/
export function* whereExcludes(arr, property, doNotWant) {
const values = [];
arr = toArray(toValue(arr));
for (const item of arr) {
values.push(
yield this.context._getFromScope(item, stringify(property).split(".")),
);
}
return arr.filter((_, i) => {
if (doNotWant === undefined) return isFalsy(values[i], this.context);
if (isArray(values[i])) return !values[i].includes(doNotWant);
if (isComparable(doNotWant)) return !doNotWant.equals(values[i]);
return values[i] !== doNotWant;
});
}

function toArray(val) {
if (isNil(val)) return [];
Expand Down
52 changes: 25 additions & 27 deletions lib/filters/where-includes.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
const { isTruthy, toValue } = require("liquidjs");

module.exports = {
/**
* An enhancement to LiquidJS's where filter that looks for the specified
* value in an array, if one is found in the named field of each object.
*
* Most of the code in this file is borrowed from LiquidJS with types removed.
*
* TODO: Convert this back to TypeScript.
*/
whereIncludes: function* (arr, property, expected) {
const values = [];
arr = toArray(toValue(arr));
for (const item of arr) {
values.push(
yield this.context._getFromScope(item, stringify(property).split("."))
);
}
return arr.filter((_, i) => {
if (expected === undefined) return isTruthy(values[i], this.context);
if (isArray(values[i])) return values[i].includes(expected);
if (isComparable(expected)) return expected.equals(values[i]);
return values[i] === expected;
});
},
};
import { isTruthy, toValue } from "liquidjs";

/**
* An enhancement to LiquidJS's where filter that looks for the specified
* value in an array, if one is found in the named field of each object.
*
* Most of the code in this file is borrowed from LiquidJS with types removed.
*
* TODO: Convert this back to TypeScript.
*/
export function* whereIncludes(arr, property, expected) {
const values = [];
arr = toArray(toValue(arr));
for (const item of arr) {
values.push(
yield this.context._getFromScope(item, stringify(property).split(".")),
);
}
return arr.filter((_, i) => {
if (expected === undefined) return isTruthy(values[i], this.context);
if (isArray(values[i])) return values[i].includes(expected);
if (isComparable(expected)) return expected.equals(values[i]);
return values[i] === expected;
});
}

function toArray(val) {
if (isNil(val)) return [];
Expand Down
Loading