mirror of
https://github.com/helenclx/leilukin-site.git
synced 2025-04-01 19:50:52 +00:00
Improve shortcode and filter comments
This commit is contained in:
parent
8663ab10c5
commit
98fc3201d8
@ -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, ",");
|
||||
});
|
||||
|
@ -2,10 +2,10 @@ import slugify from "slugify";
|
||||
import { markdownLibrary } from "./markdown-it.js";
|
||||
|
||||
export default function(eleventyConfig) {
|
||||
// <cite> tag
|
||||
// Shortcode: <cite> tag
|
||||
eleventyConfig.addShortcode('cite', (str) => `<cite>${str}</cite>`);
|
||||
|
||||
// Manual heading anchor
|
||||
// Shortcode: Manual heading anchor
|
||||
eleventyConfig.addPairedShortcode('headingAnchor', (title, hLevel, id=slugify(title)) => {
|
||||
return `<div class="heading-wrapper h${hLevel}">
|
||||
<h${hLevel} id="${id}">${title}</h${hLevel}>
|
||||
@ -13,14 +13,14 @@ export default function(eleventyConfig) {
|
||||
</div>`;
|
||||
});
|
||||
|
||||
// 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}</${el}>`;
|
||||
});
|
||||
|
||||
// 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) {
|
||||
</figure>`;
|
||||
});
|
||||
|
||||
// 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) {
|
||||
</details>`;
|
||||
});
|
||||
|
||||
// Paired shorcode: Content warning disclosure
|
||||
// Shortcode: Content warning disclosure
|
||||
eleventyConfig.addPairedShortcode('contentWarning', (content, warning) => {
|
||||
const warningMarkup = markdownLibrary.renderInline(warning);
|
||||
const contentMarkup = markdownLibrary.render(content);
|
||||
|
Loading…
x
Reference in New Issue
Block a user