From 98fc3201d8959a3128f0e1e0d6a09aa2ef93532c Mon Sep 17 00:00:00 2001 From: Helen Chong <119173961+helenclx@users.noreply.github.com> Date: Thu, 27 Mar 2025 00:20:12 +0800 Subject: [PATCH] Improve shortcode and filter comments --- src/_config/filters.js | 8 ++++---- src/_config/shortcodes.js | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/_config/filters.js b/src/_config/filters.js index cd563f33..d39765bf 100644 --- a/src/_config/filters.js +++ b/src/_config/filters.js @@ -1,7 +1,7 @@ import { DateTime } from "luxon"; export default function(eleventyConfig) { - // Filter contents by category + // Filter: Filter contents by category eleventyConfig.addFilter("filterByCategory", function(contents, cat) { cat = cat.toLowerCase(); let result = contents.filter(item => { @@ -11,7 +11,7 @@ export default function(eleventyConfig) { return result; }); - // Format dates + // Filter: Format dates eleventyConfig.addFilter("formatDate", (date) => { const dateFormat = "d LLLL yyyy"; if (typeof date === "object") { @@ -20,12 +20,12 @@ export default function(eleventyConfig) { return DateTime.fromISO(date, { setZone: true }).toFormat(dateFormat); }); - // Limit number of items displayed + // Filter: Limit number of items displayed eleventyConfig.addFilter("itemLimit", function(array, maximum) { return array.slice(0, maximum); }); - // Thousands separator + // Filter: Thousands separator eleventyConfig.addFilter("thousands", function(num) { return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }); diff --git a/src/_config/shortcodes.js b/src/_config/shortcodes.js index 0badaa91..7e94141d 100644 --- a/src/_config/shortcodes.js +++ b/src/_config/shortcodes.js @@ -2,10 +2,10 @@ import slugify from "slugify"; import { markdownLibrary } from "./markdown-it.js"; export default function(eleventyConfig) { - // tag + // Shortcode: tag eleventyConfig.addShortcode('cite', (str) => `${str}`); - // Manual heading anchor + // Shortcode: Manual heading anchor eleventyConfig.addPairedShortcode('headingAnchor', (title, hLevel, id=slugify(title)) => { return `
${title} @@ -13,14 +13,14 @@ export default function(eleventyConfig) {
`; }); - // Custom container + // Shortcode: Custom container eleventyConfig.addPairedShortcode('container', (children, el, className) => { const classMarkup = className ? ` class="${className}"` : ""; const content = markdownLibrary.render(children); return `<${el}${classMarkup}>${content}`; }); - // Image figure and figcaption + // Shortcode: Image figure and figcaption eleventyConfig.addPairedShortcode('imgFigure', ( caption, img, alt=caption, className, enableLazyLoading=true ) => { @@ -32,7 +32,7 @@ export default function(eleventyConfig) { `; }); - // Content disclosure + // Shortcode: Content disclosure eleventyConfig.addPairedShortcode('disclosure', (content, summary) => { const summaryMarkup = markdownLibrary.renderInline(summary); const contentMarkup = markdownLibrary.render(content); @@ -42,7 +42,7 @@ export default function(eleventyConfig) { `; }); - // Paired shorcode: Content warning disclosure + // Shortcode: Content warning disclosure eleventyConfig.addPairedShortcode('contentWarning', (content, warning) => { const warningMarkup = markdownLibrary.renderInline(warning); const contentMarkup = markdownLibrary.render(content);