const markdownItFootnote = require('markdown-it-footnote');
const path = require("path");
-let markdownOptions = {
+const markdownOptions = {
html: true,
breaks: false,
linkify: true,
typographer: true,
};
-let mdLibrary = markdownIt(markdownOptions).use(markdownItFootnote);
+const mdLibrary = markdownIt(markdownOptions).use(markdownItFootnote);
function relativeToInputPath(inputPath, relativeFilePath) {
- let split = inputPath.split("/");
+ const split = inputPath.split("/");
split.pop();
return path.resolve(split.join(path.sep), relativeFilePath);
}
}
}
-module.exports = function (eleventyConfig) {
+module.exports = async function (eleventyConfig) {
eleventyConfig.addCollection("activities", function(collectionApi) {
- let collectionSubset = [
- ...collectionApi.getFilteredByTag("articles"),
- ...collectionApi.getFilteredByTag("links"),
- ...collectionApi.getFilteredByTag("reviews"),
- ];
- let sortedSubset = collectionSubset.sort(function(a, b) {
- // maintain sort order when working with default collections objects
- return a.date - b.date;
- });
- return sortedSubset;
+ return collectionApi.getFilteredByTag(
+ ...Object.keys(globalMetadata['categories'])
+ ).sort((a, b) => a.date - b.date)
});
eleventyConfig.addFilter("cssmin", function (code) {
return new cleanCSS({}).minify(code).styles;
return array.slice(0, n);
});
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
- // dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd');
});
eleventyConfig.addFilter("isoDate", (dateObj) => {
- // Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toISO();
});
eleventyConfig.addFilter("min", (...numbers) => {
- // Return the smallest number argument
return Math.min.apply(null, numbers);
});
eleventyConfig.addPairedShortcode(
"callout",
function (content, level = "", format = "md", customLabel = "") {
+ const label = customLabel || globalMetadata['calloutLabels'][level]
if (format === "md") {
content = mdLibrary.renderInline(content);
} else if (format === "md-block") {
content = mdLibrary.render(content);
- } else if (format === "html") {
- content = content
- }
- if (customLabel) {
- label = customLabel;
- } else if (level === "info") {
- label = "ⓘ Info"
- } else if (level === "warn") {
- label = "⚠ Warning";
- } else if (level === "error") {
- label = "! Error"
}
- let labelHtml = label
- ? `<div class="callout-label">${customLabel || label}</div>`
+ const labelHtml = label
+ ? `<div class="callout-label">${label}</div>`
: "";
- let contentHtml =
+ const contentHtml =
(content || "").trim().length > 0
? `<div class="callout-content">${content}</div>`
: "";
-
- return `<div class="callout${
- level ? ` callout-${level}` : ""
+ return `<div class="callout${level
+ ? ` callout-${level}`
+ : ""
}">${labelHtml}${contentHtml}</div>`;
}
);
},
metadata: globalMetadata,
});
- eleventyConfig.addPlugin(feedPlugin, {
- type: "atom",
- outputPath: "/feeds/articles.xml",
- inputPath: "eleventy-plugin-feed-cameron-otsuka-articles-atom.njk",
- collection: {
- name: "articles",
- limit: 10,
- },
- metadata: {
- language: globalMetadata['language'],
- title: globalMetadata['title'].concat(" - Articles"),
- subtitle: globalMetadata['subtitle'],
- base: globalMetadata['base'],
- author: globalMetadata['author'],
- },
- });
- eleventyConfig.addPlugin(feedPlugin, {
- type: "atom",
- outputPath: "/feeds/links.xml",
- inputPath: "eleventy-plugin-feed-cameron-otsuka-links-atom.njk",
- collection: {
- name: "links",
- limit: 10,
- },
- metadata: {
- language: globalMetadata['language'],
- title: globalMetadata['title'].concat(" - Links"),
- subtitle: globalMetadata['subtitle'],
- base: globalMetadata['base'],
- author: globalMetadata['author'],
- },
- });
- eleventyConfig.addPlugin(feedPlugin, {
- type: "atom",
- outputPath: "/feeds/reviews.xml",
- inputPath: "eleventy-plugin-feed-cameron-otsuka-reviews-atom.njk",
- collection: {
- name: "reviews",
- limit: 10,
- },
- metadata: {
- language: globalMetadata['language'],
- title: globalMetadata['title'].concat(" - Reviews"),
- subtitle: globalMetadata['subtitle'],
- base: globalMetadata['base'],
- author: globalMetadata['author'],
- },
- });
+ for (category in globalMetadata['categories']) {
+ eleventyConfig.addPlugin(feedPlugin, {
+ type: "atom",
+ outputPath: `/feeds/${category}.xml`,
+ inputPath: `eleventy-plugin-feed-cameron-otsuka-${category}-atom.njk`,
+ collection: {
+ name: `${category}`,
+ limit: 10,
+ },
+ metadata: {
+ ...globalMetadata,
+ title: globalMetadata['title'].concat(
+ ` - ${category.charAt(0).toUpperCase()}`
+ ),
+ },
+ });
+ }
eleventyConfig.addPlugin(eleventySyntaxHighlightPlugin);
eleventyConfig.addShortcode("image", async function (src, alt) {
let input;
} else {
input = relativeToInputPath(this.page.inputPath, src);
}
-
- let metadata = await eleventyImagePlugin(input, {
+ const metadata = await eleventyImagePlugin(input, {
widths: [360, 720],
formats: ["svg", "avif", "jpeg", "gif"],
sharpOptions: {
urlPath: "/img/",
outputDir: path.join(eleventyConfig.dir.output, "img"),
});
-
- let imageAttributes = {
+ const imageAttributes = {
alt,
sizes: "360w, 720w",
loading: "lazy",
decoding: "async",
"eleventy:ignore": "",
};
-
- let options = {
+ const options = {
pictureAttributes: {},
whitespaceMode: "inline",
};