From 98d470c72d1bab3a4ae126a44dde24ab367b8eba Mon Sep 17 00:00:00 2001 From: Princesseuh <3019731+Princesseuh@users.noreply.github.com> Date: Mon, 30 Mar 2026 17:21:06 +0200 Subject: [PATCH 01/12] feat: use real packages --- astro.config.ts | 16 +- config/plugins/tryckeri-fallback-lang.ts | 73 +++++ config/plugins/tryckeri-tasklist-enhancer.ts | 105 +++++++ package.json | 9 +- pnpm-lock.yaml | 304 ++++++++++++------- 5 files changed, 389 insertions(+), 118 deletions(-) create mode 100644 config/plugins/tryckeri-fallback-lang.ts create mode 100644 config/plugins/tryckeri-tasklist-enhancer.ts diff --git a/astro.config.ts b/astro.config.ts index ad4a04eecf5e1..c90102d897b99 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -1,5 +1,4 @@ import starlight from '@astrojs/starlight'; -import { pluginCollapsibleSections } from '@expressive-code/plugin-collapsible-sections'; import { defineConfig, sharpImageService } from 'astro/config'; import rehypeSlug from 'rehype-slug'; import remarkSmartypants from 'remark-smartypants'; @@ -11,6 +10,9 @@ import { starlightPluginLlmsTxt } from './config/plugins/llms-txt'; import { starlightPluginSmokeTest } from './config/plugins/smoke-test'; import { rehypeTasklistEnhancer } from './config/plugins/rehype-tasklist-enhancer'; import { remarkFallbackLang } from './config/plugins/remark-fallback-lang'; +import { tasklistEnhancerPlugin } from './config/plugins/tryckeri-tasklist-enhancer'; +import { fallbackLangPlugin } from './config/plugins/tryckeri-fallback-lang'; +import mdx from '@astrojs/mdx'; /* https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables */ const NETLIFY_PREVIEW_SITE = process.env.CONTEXT !== 'production' && process.env.DEPLOY_PRIME_URL; @@ -28,9 +30,7 @@ export default defineConfig({ ]), starlight({ title: 'Docs', - expressiveCode: { - plugins: [pluginCollapsibleSections()], - }, + expressiveCode: false, components: { EditLink: './src/components/starlight/EditLink.astro', Hero: './src/components/starlight/Hero.astro', @@ -72,6 +72,11 @@ export default defineConfig({ plugins: [starlightPluginSmokeTest(), starlightPluginLlmsTxt()], }), sitemap(), + mdx({ + optimize: true, + mdastPlugins: [fallbackLangPlugin()], + hastPlugins: [tasklistEnhancerPlugin()], + }), ], trailingSlash: 'always', scopedStyleStrategy: 'where', @@ -91,6 +96,9 @@ export default defineConfig({ rehypeTasklistEnhancer(), ], }, + experimental: { + rustCompiler: true, + }, image: { domains: ['avatars.githubusercontent.com'], service: sharpImageService(), diff --git a/config/plugins/tryckeri-fallback-lang.ts b/config/plugins/tryckeri-fallback-lang.ts new file mode 100644 index 0000000000000..1288198829cc9 --- /dev/null +++ b/config/plugins/tryckeri-fallback-lang.ts @@ -0,0 +1,73 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { defineMdastPlugin } from 'tryckeri'; +import type { MdastNode } from 'tryckeri'; + +const pageSourceDir = path.resolve('./src/content/docs'); +const baseUrl = 'https://docs.astro.build/'; + +export function fallbackLangPlugin() { + return defineMdastPlugin({ + name: 'fallback-lang', + createOnce() { + let currentFilename: string; + + return { + // At runtime, wrapInstance calls before(fileContext, visitorContext) + before(fileContext: any) { + currentFilename = fileContext.filename; + }, + + link(node: MdastNode, context: any) { + const pageUrl = mdFilePathToUrl(currentFilename, pageSourceDir, baseUrl); + const pageLang = getLanguageCodeFromPathname(pageUrl.pathname); + + // Ignore pages without language prefix and English pages + if (!pageLang || pageLang === 'en') return; + + const linkUrl = new URL(node.url!, pageUrl); + + // Ignore external links + if (pageUrl.host !== linkUrl.host) return; + + // Ignore link targets without language prefix + const linkLang = getLanguageCodeFromPathname(linkUrl.pathname); + if (!linkLang) return; + + // Ignore link targets that have a valid source file + const linkSourceFileName = tryFindSourceFileForPathname( + linkUrl.pathname, + pageSourceDir + ); + if (linkSourceFileName) return; + + context.appendChild(node, { + type: 'text', + value: '\u00A0(EN)', + } as MdastNode); + }, + }; + }, + }); +} + +function mdFilePathToUrl(mdFilePath: string, pageSourceDir: string, baseUrl: string) { + const pathBelowRoot = path.relative(pageSourceDir, mdFilePath); + const pathname = pathBelowRoot.replace(/\\/g, '/').replace(/\.mdx?$/i, '/'); + return new URL(pathname, baseUrl); +} + +function getLanguageCodeFromPathname(pathname: string) { + const firstPathPart = pathname.split('/')[1]; + if (firstPathPart?.match(/^[a-z]{2}(-[a-zA-Z]{2})?$/)) return firstPathPart; +} + +function tryFindSourceFileForPathname(pathname: string, pageSourceDir: string) { + const possibleSourceFilePaths = [ + path.join(pageSourceDir, pathname, '.') + '.md', + path.join(pageSourceDir, pathname, 'index.md'), + path.join(pageSourceDir, pathname, '.') + '.mdx', + path.join(pageSourceDir, pathname, 'index.mdx'), + ]; + return possibleSourceFilePaths.find((possiblePath) => fs.existsSync(possiblePath)); +} diff --git a/config/plugins/tryckeri-tasklist-enhancer.ts b/config/plugins/tryckeri-tasklist-enhancer.ts new file mode 100644 index 0000000000000..1976017aed00c --- /dev/null +++ b/config/plugins/tryckeri-tasklist-enhancer.ts @@ -0,0 +1,105 @@ +import { defineHastPlugin } from 'tryckeri'; +import type { HastNode } from 'tryckeri'; + +/** + * Tryckeri HAST plugin to enhance the output of GitHub-Flavored Markdown's task lists. + * This improves possibilities for our `` component. + * + * 1. Wraps checkboxes and siblings in a `