gram/packages/docs/astro.config.mjs

292 lines
13 KiB
JavaScript

// @ts-check
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import starlightThemeNova from 'starlight-theme-nova';
import starlightLinksValidator from 'starlight-links-validator';
import vue from '@astrojs/vue';
import mdx from '@astrojs/mdx';
import { unified } from '@astrojs/markdown-remark';
import { remarkMermaid } from './src/plugins/remark-mermaid.ts';
import { remarkFrenchTypography } from './src/plugins/remark-french-typography.ts';
import gramGrammar from '@gram-lang/parser/textmate';
import { parse as parseYaml } from 'yaml';
import { UMAMI_WEBSITE_ID, UMAMI_SCRIPT_SRC, FR_REDIRECT_SCRIPT, GLOBAL_TRACKING_SCRIPT } from './src/lib/head-scripts.ts';
const isProd = process.env.NODE_ENV === 'production';
// `import data from './x.yaml'` gives the parsed data, read at build time, so
// the YAML parser never ships to the browser. Bun's own loader does the same
// for the tests. `./x.yaml?raw` (the text, for showing it) is left to Vite.
/** @returns {import('vite').Plugin} */
function yamlData() {
return {
name: 'gram-yaml-data',
enforce: 'pre',
/** @param {string} code @param {string} id */
transform(code, id) {
if (!/\.ya?ml$/.test(id)) return;
return { code: `export default ${JSON.stringify(parseYaml(code))};`, map: null };
}
};
}
// https://astro.build/config
export default defineConfig({
site: 'https://gram-lang.org',
redirects: {
'/docs/explanation/mise-en-place-and-planning': '/docs/explanation/planning',
'/docs/explanation/planning-in-real-time': '/docs/explanation/planning',
'/fr/docs/explanation/mise-en-place-and-planning': '/fr/docs/explanation/planning',
'/fr/docs/explanation/planning-in-real-time': '/fr/docs/explanation/planning'
},
devToolbar: {
enabled: false
},
markdown: {
processor: unified({ remarkPlugins: [remarkMermaid, remarkFrenchTypography] }),
shikiConfig: {
langs: [{ ...gramGrammar, name: 'gram' }]
}
},
integrations: [
vue(),
starlight({
plugins: [
starlightThemeNova(),
starlightLinksValidator({
errorOnFallbackPages: false,
errorOnInconsistentLocale: true,
exclude: [
'/play', '/play/', '/fr/play', '/fr/play/',
'/en/docs', '/en/docs/',
'/blog', '/blog/', '/blog/**', '/fr/blog', '/fr/blog/', '/fr/blog/**',
'/changelog', '/changelog/', '/changelog/**', '/fr/changelog', '/fr/changelog/', '/fr/changelog/**'
]
})
],
title: 'Gram',
disable404Route: true,
customCss: [
'./src/styles/global.css',
],
components: {
Footer: './src/components/Footer.astro',
Head: './src/components/Head.astro',
Sidebar: './src/components/Sidebar.astro',
SiteTitle: './src/components/SiteTitle.astro',
ThemeSelect: './src/components/ThemeSelect.astro'
},
locales: {
root: { label: 'English', lang: 'en' },
fr: { label: 'Français', lang: 'fr' }
},
sidebar: [
{
label: 'Guides',
translations: { fr: 'Guides' },
items: [
{
label: 'Introduction',
collapsed: false,
items: [
{ label: 'Overview', translations: { fr: "Vue d'ensemble" }, slug: 'docs' },
{ label: 'What is Gram?', translations: { fr: "C'est quoi Gram ?" }, slug: 'docs/explanation/philosophy' },
{ label: 'Getting started', translations: { fr: 'Premiers pas' }, slug: 'docs/tutorials/getting-started' },
{ label: 'Your first recipe', translations: { fr: 'Votre première recette' }, slug: 'docs/tutorials/first-recipe' }
]
},
{
label: 'How-to guides',
translations: { fr: 'Guides pratiques' },
collapsed: false,
items: [
{ label: 'Organize modular recipes', translations: { fr: 'Organiser des recettes modulaires' }, slug: 'docs/how-to/organize-modular-recipes' },
{ label: 'Scale recipes dynamically', translations: { fr: 'Ajuster les proportions' }, slug: 'docs/how-to/scale-recipes' },
{ label: 'Plan a meal', translations: { fr: 'Planifier un repas' }, slug: 'docs/how-to/plan-a-meal' },
{ label: 'Generate shopping list', translations: { fr: 'Générer la liste de courses' }, slug: 'docs/how-to/weekly-shopping-list' },
{ label: 'Manage database', translations: { fr: 'Gérer la base de données' }, slug: 'docs/how-to/manage-database' },
{ label: 'Configure AI provider', translations: { fr: "Configurer l'IA" }, slug: 'docs/how-to/configure-ai' }
]
}
]
},
{
label: 'Language',
translations: { fr: 'Syntaxe' },
items: [
{
label: 'Basics',
translations: { fr: 'Bases' },
collapsed: false,
items: [
{ label: 'Cheatsheet', translations: { fr: 'Antisèche' }, slug: 'docs/reference/syntax/cheatsheet' },
{ label: 'Document structure', translations: { fr: 'Structure du document' }, slug: 'docs/reference/syntax/document-structure' },
{ label: 'Ingredients', translations: { fr: 'Ingrédients' }, slug: 'docs/reference/syntax/ingredients' },
{ label: 'Cookware', translations: { fr: 'Matériel' }, slug: 'docs/reference/syntax/cookware' },
{ label: 'Times & scheduling', translations: { fr: 'Temps & planification' }, slug: 'docs/reference/syntax/times' },
{ label: 'Temperatures', translations: { fr: 'Températures' }, slug: 'docs/reference/syntax/temperatures' },
{ label: 'Target states', translations: { fr: 'États attendus' }, slug: 'docs/reference/syntax/target-states', badge: { text: 'v1.5.0', variant: 'default' } }
]
},
{
label: 'Advanced',
translations: { fr: 'Avancé' },
collapsed: true,
items: [
{ label: 'Relative quantities & ratios', translations: { fr: 'Quantités relatives & proportions' }, slug: 'docs/reference/syntax/relative-quantities' },
{ label: 'Intermediate variables', translations: { fr: 'Variables intermédiaires' }, slug: 'docs/reference/syntax/intermediate-variables' },
{ label: 'Composite ingredients', translations: { fr: 'Ingrédients composites' }, slug: 'docs/reference/syntax/composite-ingredients' },
{ label: 'Module imports', translations: { fr: 'Imports de modules' }, slug: 'docs/reference/syntax/modules' }
]
}
]
},
{
label: 'Tooling',
translations: { fr: 'Outils' },
items: [
{
label: 'CLI & editors',
translations: { fr: 'CLI & éditeurs' },
collapsed: false,
items: [
{ label: 'CLI commands', translations: { fr: 'Commandes CLI' }, slug: 'docs/reference/tooling/cli' },
{ label: 'VS Code extension', translations: { fr: 'Extension VS Code' }, slug: 'docs/reference/tooling/vscode-extension' },
{ label: 'Language server', slug: 'docs/reference/tooling/language-server' }
]
},
{
label: 'Integration & AI',
translations: { fr: 'Intégration & IA' },
collapsed: false,
items: [
{ label: 'Writing Gram programmatically', translations: { fr: 'Génération automatisée de Gram' }, slug: 'docs/reference/syntax/ai-generation-notes' },
{ label: 'How to build a custom UI', translations: { fr: 'Créer une UI personnalisée' }, slug: 'docs/how-to/build-custom-ui' }
]
}
]
},
{
label: 'Engine & API',
translations: { fr: 'Moteur & API' },
items: [
{
label: 'API reference',
translations: { fr: 'Référence API' },
collapsed: false,
items: [
{ label: 'Overview', translations: { fr: "Vue d'ensemble" }, slug: 'docs/reference/api' },
{ label: '@gram-lang/parser', slug: 'docs/reference/api/parser' },
{ label: '@gram-lang/modules', slug: 'docs/reference/api/modules' },
{ label: '@gram-lang/kitchen', slug: 'docs/reference/api/kitchen' },
{ label: '@gram-lang/scheduler', slug: 'docs/reference/api/scheduler' },
{ label: '@gram-lang/analyzer', slug: 'docs/reference/api/analyzer' },
{ label: '@gram-lang/renderer', slug: 'docs/reference/api/renderer' },
{ label: '@gram-lang/format', slug: 'docs/reference/api/format' },
{ label: '@gram-lang/i18n', slug: 'docs/reference/api/i18n' },
{ label: 'Data formats', translations: { fr: 'Formats de données' }, slug: 'docs/reference/api/data-formats' },
{ label: 'Warnings', translations: { fr: 'Avertissements' }, slug: 'docs/reference/api/warnings' },
{ label: 'Deprecated features', translations: { fr: 'Fonctionnalités dépréciées' }, slug: 'docs/how-to/deprecations' }
]
},
{
label: 'Gram engine',
translations: { fr: 'Moteur Gram' },
collapsed: true,
items: [
{ label: 'The Gram lifecycle', translations: { fr: 'Cycle de vie' }, slug: 'docs/explanation/engine/lifecycle' },
{ label: 'Parsing & AST', slug: 'docs/explanation/engine/parser' },
{ label: 'Module resolution & composition', translations: { fr: 'Résolution & composition' }, slug: 'docs/explanation/engine/modules' },
{ label: 'Compilation & structure', translations: { fr: 'Compilation & structure' }, slug: 'docs/explanation/engine/kitchen' },
{ label: 'The scheduling engine', translations: { fr: "Le moteur d'ordonnancement" }, slug: 'docs/explanation/engine/scheduler' },
{ label: 'Semantic analysis', translations: { fr: 'Analyse sémantique' }, slug: 'docs/explanation/engine/analyzer' },
{ label: 'Rendering & output', translations: { fr: 'Rendu & sortie' }, slug: 'docs/explanation/engine/renderer' }
]
},
{
label: 'Deep dives',
translations: { fr: 'Analyses approfondies' },
collapsed: true,
items: [
{ label: 'ALAP scheduling', translations: { fr: 'Ordonnancement ALAP' }, slug: 'docs/explanation/alap-scheduling' },
{ label: 'Mass & yield', translations: { fr: 'Masse & rendement' }, slug: 'docs/explanation/mass-and-yield' },
{ label: 'Nutrition', slug: 'docs/explanation/nutrition' },
{ label: 'Shopping lists', translations: { fr: 'Liste de courses' }, slug: 'docs/explanation/shopping-list-aggregation' },
{ label: 'Scaling', translations: { fr: "Ajustement des proportions" }, slug: 'docs/explanation/scaling' },
{ label: 'Planning & run sheet', translations: { fr: 'Planification & plan de marche' }, slug: 'docs/explanation/planning' }
]
}
]
}
],
head: [
...(isProd ? [{
tag: /** @type {'script'} */ ('script'),
attrs: {
defer: true,
src: UMAMI_SCRIPT_SRC,
'data-website-id': UMAMI_WEBSITE_ID
}
}, {
tag: /** @type {'script'} */ ('script'),
content: GLOBAL_TRACKING_SCRIPT
}] : []),
{
tag: 'script',
content: FR_REDIRECT_SCRIPT
}
],
social: [
{
label: 'Forgejo (Primary repository)',
icon: 'seti:git',
href: 'https://git.gram-lang.org/gram-lang/gram'
},
{
label: 'Codeberg Mirror',
icon: 'codeberg',
href: 'https://codeberg.org/gram-lang/gram'
},
{
label: 'GitHub Mirror',
icon: 'github',
href: 'https://github.com/gram-lang/gram'
}
]
}),
mdx(),
{
name: 'override-shiki-themes',
hooks: {
'astro:config:setup': ({ updateConfig }) => {
updateConfig({
markdown: {
shikiConfig: {
themes: {
light: 'github-light',
dark: 'github-dark'
}
}
}
});
}
}
}
],
vite: {
plugins: [yamlData()],
build: {
target: 'esnext'
},
esbuild: {
target: 'esnext'
},
optimizeDeps: {
rolldownOptions: {
transform: {
target: 'esnext'
}
}
}
}
});