chore: update dependencies and improve Eleventy configuration (#2581)

This commit is contained in:
Paweł Kuna
2026-01-06 16:12:56 +01:00
committed by GitHub
parent 41fd82b388
commit 84c31d1383
4 changed files with 464 additions and 731 deletions

View File

@@ -1,16 +1,13 @@
import { appFilters } from "../shared/e11ty/filters.mjs"
import { appData } from "../shared/e11ty/data.mjs";
import { appConfig } from "../shared/e11ty/config.mjs";
import { readFileSync, existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url'
import { join, dirname } from 'node:path';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import beautify from 'js-beautify';
const shiki = await import('shiki');
import { createCssVariablesTheme } from 'shiki/core'
const __dirname = dirname(fileURLToPath(import.meta.url))
export default function (eleventyConfig) {
const environment = process.env.NODE_ENV || "production";
@@ -34,43 +31,6 @@ export default function (eleventyConfig) {
eleventyConfig.amendLibrary('md', () => { });
eleventyConfig.addShortcode('scss-docs', function (name, filename) {
const file = join(__dirname, `../core/scss/${filename}`)
if (existsSync(file)) {
const content = readFileSync(file, 'utf8');
const regex = new RegExp(`\/\/\\sscss-docs-start\\s${name}\\n(.+?)\/\/\\sscss-docs-end`, 'gs')
const m = content.matchAll(regex)
if (m) {
const matches = [...m]
if (matches[0] && matches[0][1]) {
const lines = matches[0][1].split('\n');
// Find minimum number of leading spaces in non-empty lines
const minIndent = lines
.filter(line => line.trim().length > 0)
.reduce((min, line) => {
const match = line.match(/^(\s*)/);
const leadingSpaces = match ? match[1].length : 0;
return Math.min(min, leadingSpaces);
}, Infinity);
// Remove that many spaces from the start of each line
const result = lines.map(line => line.startsWith(' '.repeat(minIndent))
? line.slice(minIndent)
: line).join('\n');
return "\n```scss\n" + result.trimRight() + "\n```\n"
}
}
}
return ''
})
// Shiki
eleventyConfig.on('eleventy.before', async () => {
const myTheme = createCssVariablesTheme({
@@ -120,146 +80,6 @@ export default function (eleventyConfig) {
}
);
});
/**
* Filters
*/
function buildCollectionTree(flatData) {
const tree = [];
const lookup = {};
flatData
.filter(item => item.url !== '/')
.forEach(item => {
lookup[item.url] = { ...item, children: [] };
});
flatData.forEach(item => {
const parts = item.url.split('/').filter(Boolean);
if (parts.length === 1) {
tree.push(lookup[item.url]);
} else {
const parentUrl = '/' + parts.slice(0, -1).join('/') + '/';
if (lookup[parentUrl]) {
lookup[parentUrl].children.push(lookup[item.url]);
} else {
tree.push(lookup[item.url]);
}
}
});
return tree;
}
eleventyConfig.addFilter("collection-tree", function (collection) {
const a = collection.map(item => {
return {
data: item.data,
page: item.page,
url: item.url,
children: []
}
}).sort((a, b) => {
const orderA = a.data.order ?? 999;
const orderB = b.data.order ?? 999;
if (orderA !== orderB) {
return orderA - orderB;
}
const titleA = a.data.title ?? '';
const titleB = b.data.title ?? '';
return titleA.localeCompare(titleB);
});
return buildCollectionTree(a);
});
eleventyConfig.addFilter("collection-children", function (collection, page) {
const url = page.url.split('/').filter(Boolean).join('/');
const filteredCollection = collection.filter(item => {
const parts = item.url.split('/').filter(Boolean);
return parts.length > 1 && parts.slice(0, -1).join('/') === url;
});
return filteredCollection.sort((a, b) => {
return (a.data?.order || 999) - (b.data?.order || 999);
});
});
eleventyConfig.addFilter("next-prev", function (collection, page) {
const items = collection
.filter(item => {
const parts = item.url.split('/').filter(Boolean);
return parts.length > 1 && parts.slice(0, -1).join('/') === page.url.split('/').filter(Boolean).slice(0, -1).join('/');
})
.sort((a, b) => {
return a.data.title.localeCompare(b.data.title);
})
.sort((a, b) => {
return (a.data?.order || 999) - (b.data?.order || 999);
});
const index = items.findIndex(item => item.url === page.url);
const prevPost = index > 0 ? items[index - 1] : null;
const nextPost = index < items.length - 1 ? items[index + 1] : null;
return {
prev: prevPost ? prevPost : null,
next: nextPost ? nextPost : null,
};
});
const generateUniqueId = (text) => {
let id = text
.replace(/<[^>]+>/g, "")
.replace(/\s/g, "-")
.replace(/[^\w-]+/g, "")
.replace(/--+/g, "-")
.replace(/^-+|-+$/g, "")
.toLowerCase();
// Ensure ID doesn't start with a number (invalid HTML)
if (/^[0-9]/.test(id)) {
id = "h" + id;
}
return id;
}
eleventyConfig.addFilter("headings-id", function (content) {
return content.replace(/<h([1-6])>([^<]+)<\/h\1>/g, (match, level, text) => {
const headingId = generateUniqueId(text);
return `<h${level} id="${headingId}">${text}</h${level}>`;
});
})
eleventyConfig.addFilter("toc", function (name) {
const toc = [];
const contentWithoutExamples = name.replace(/<!--EXAMPLE-->[\s\S]*?<!--\/EXAMPLE-->/g, '');
const headings = contentWithoutExamples.match(/<h([23])>([^<]+)<\/h\1>/g);
if (headings) {
headings.forEach(heading => {
const level = parseInt(heading.match(/<h([1-6])>/)[1]);
const text = heading.replace(/<[^>]+>/g, "");
const id = generateUniqueId(text);
toc.push({ level, text, id });
});
}
return toc;
})
eleventyConfig.addFilter("remove-href", function (content) {
return content.replace(/href="#"/g, 'href="javascript:void(0)"');
})
/**
* Data
*/

View File

@@ -14,34 +14,34 @@
"zip-package": "node .build/zip-package.mjs",
"start": "pnpm dev"
},
"packageManager": "pnpm@10.19.0",
"packageManager": "pnpm@10.27.0",
"dependencies": {
"shx": "^0.4.0"
},
"devDependencies": {
"@argos-ci/playwright": "^5.0.5",
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.29.7",
"@playwright/test": "^1.53.2",
"@argos-ci/playwright": "^6.3.8",
"@changesets/changelog-github": "^0.5.2",
"@changesets/cli": "^2.29.8",
"@playwright/test": "^1.57.0",
"adm-zip": "^0.5.16",
"autoprefixer": "^10.4.21",
"autoprefixer": "^10.4.23",
"bundlewatch": "^0.4.1",
"clean-css-cli": "^5.6.3",
"concurrently": "^9.2.0",
"cross-env": "^7.0.3",
"fs-extra": "^11.3.2",
"glob": "^11.0.3",
"concurrently": "^9.2.1",
"cross-env": "^10.1.0",
"fs-extra": "^11.3.3",
"glob": "^13.0.0",
"js-beautify": "^1.15.4",
"nodemon": "^3.1.10",
"nodemon": "^3.1.11",
"pnpm": "^10.6.5",
"postcss": "^8.5.6",
"postcss-cli": "^11.0.1",
"prettier": "^3.6.2",
"prettier": "^3.7.4",
"vite": "^7.3.0",
"rtlcss": "^4.3.0",
"sass": "1.89.2",
"sass": "1.97.2",
"shelljs": "^0.10.0",
"terser": "^5.44.0",
"turbo": "^2.5.8"
"terser": "^5.44.1",
"turbo": "^2.7.3"
}
}

802
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,9 @@
import { readFileSync, existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { join, dirname } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
export function appFilters(eleventyConfig) {
/**
* Filters
@@ -195,10 +201,183 @@ export function appFilters(eleventyConfig) {
return "now";
})
function buildCollectionTree(flatData) {
const tree = [];
const lookup = {};
flatData
.filter(item => item.url !== '/')
.forEach(item => {
lookup[item.url] = { ...item, children: [] };
});
flatData.forEach(item => {
const parts = item.url.split('/').filter(Boolean);
if (parts.length === 1) {
tree.push(lookup[item.url]);
} else {
const parentUrl = '/' + parts.slice(0, -1).join('/') + '/';
if (lookup[parentUrl]) {
lookup[parentUrl].children.push(lookup[item.url]);
} else {
tree.push(lookup[item.url]);
}
}
});
return tree;
}
eleventyConfig.addFilter("collection-tree", function (collection) {
const a = collection.map(item => {
return {
data: item.data,
page: item.page,
url: item.url,
children: []
}
}).sort((a, b) => {
const orderA = a.data.order ?? 999;
const orderB = b.data.order ?? 999;
if (orderA !== orderB) {
return orderA - orderB;
}
const titleA = a.data.title ?? '';
const titleB = b.data.title ?? '';
return titleA.localeCompare(titleB);
});
return buildCollectionTree(a);
});
eleventyConfig.addFilter("collection-children", function (collection, page) {
const url = page.url.split('/').filter(Boolean).join('/');
const filteredCollection = collection.filter(item => {
const parts = item.url.split('/').filter(Boolean);
return parts.length > 1 && parts.slice(0, -1).join('/') === url;
});
return filteredCollection.sort((a, b) => {
return (a.data?.order || 999) - (b.data?.order || 999);
});
});
eleventyConfig.addFilter("next-prev", function (collection, page) {
const items = collection
.filter(item => {
const parts = item.url.split('/').filter(Boolean);
return parts.length > 1 && parts.slice(0, -1).join('/') === page.url.split('/').filter(Boolean).slice(0, -1).join('/');
})
.sort((a, b) => {
return a.data.title.localeCompare(b.data.title);
})
.sort((a, b) => {
return (a.data?.order || 999) - (b.data?.order || 999);
});
const index = items.findIndex(item => item.url === page.url);
const prevPost = index > 0 ? items[index - 1] : null;
const nextPost = index < items.length - 1 ? items[index + 1] : null;
return {
prev: prevPost ? prevPost : null,
next: nextPost ? nextPost : null,
};
});
const generateUniqueId = (text) => {
let id = text
.replace(/<[^>]+>/g, "")
.replace(/\s/g, "-")
.replace(/[^\w-]+/g, "")
.replace(/--+/g, "-")
.replace(/^-+|-+$/g, "")
.toLowerCase();
// Ensure ID doesn't start with a number (invalid HTML)
if (/^[0-9]/.test(id)) {
id = "h" + id;
}
return id;
}
eleventyConfig.addFilter("headings-id", function (content) {
return content.replace(/<h([1-6])>([^<]+)<\/h\1>/g, (match, level, text) => {
const headingId = generateUniqueId(text);
return `<h${level} id="${headingId}">${text}</h${level}>`;
});
})
eleventyConfig.addFilter("toc", function (name) {
const toc = [];
const contentWithoutExamples = name.replace(/<!--EXAMPLE-->[\s\S]*?<!--\/EXAMPLE-->/g, '');
const headings = contentWithoutExamples.match(/<h([23])>([^<]+)<\/h\1>/g);
if (headings) {
headings.forEach(heading => {
const level = parseInt(heading.match(/<h([1-6])>/)[1]);
const text = heading.replace(/<[^>]+>/g, "");
const id = generateUniqueId(text);
toc.push({ level, text, id });
});
}
return toc;
})
eleventyConfig.addFilter("remove-href", function (content) {
return content.replace(/href="#"/g, 'href="javascript:void(0)"');
})
/**
* Shortcodes
*/
eleventyConfig.addShortcode('scss-docs', function (name, filename) {
const file = join(__dirname, `../../core/scss/${filename}`)
if (existsSync(file)) {
const content = readFileSync(file, 'utf8');
const regex = new RegExp(`\/\/\\sscss-docs-start\\s${name}\\n(.+?)\/\/\\sscss-docs-end`, 'gs')
const m = content.matchAll(regex)
if (m) {
const matches = [...m]
if (matches[0] && matches[0][1]) {
const lines = matches[0][1].split('\n');
// Find minimum number of leading spaces in non-empty lines
const minIndent = lines
.filter(line => line.trim().length > 0)
.reduce((min, line) => {
const match = line.match(/^(\s*)/);
const leadingSpaces = match ? match[1].length : 0;
return Math.min(min, leadingSpaces);
}, Infinity);
// Remove that many spaces from the start of each line
const result = lines.map(line => line.startsWith(' '.repeat(minIndent))
? line.slice(minIndent)
: line).join('\n');
return "\n```scss\n" + result.trimRight() + "\n```\n"
}
}
}
return ''
})
const tags = ["capture_global", "endcapture_global", "highlight", "endhighlight"];
tags.forEach(tag => {
eleventyConfig.addLiquidTag(tag, function (liquidEngine) {