From 761579a09cad97c9aed5fdae911adf7e95b06225 Mon Sep 17 00:00:00 2001 From: DuroCodes Date: Sat, 25 May 2024 03:01:17 -0400 Subject: [PATCH] feat: add `VALIDATE_LINKS` env argument --- .env.example | 4 ++++ astro.config.mjs | 15 +++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..f6b49d4c0 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +# Set this to `true` to enable link validation, useful for development build to make sure all links are valid +# Broken since API routes generate links that are relative, so you can only validate links in development +# (You can ignore any errors that are generated by the API routes) +VALIDATE_LINKS=boolean \ No newline at end of file diff --git a/astro.config.mjs b/astro.config.mjs index 7ec3a67e4..831d15e07 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -4,8 +4,12 @@ import starlightBlog from "starlight-blog"; import tailwind from "@astrojs/tailwind"; import starlightTypeDoc, { typeDocSidebarGroup } from "starlight-typedoc"; import lunaria from "@lunariajs/starlight"; +import { loadEnv } from "vite"; import { GITHUB_URL, DISCORD_URL } from "./src/utils/consts"; -// import starlightLinksValidator from 'starlight-links-validator'; +import starlightLinksValidator from 'starlight-links-validator'; + +const { VALIDATE_LINKS } = loadEnv(process.env.NODE_ENV, process.cwd(), ""); +const validateLinks = VALIDATE_LINKS === "true"; export default defineConfig({ integrations: [ @@ -130,11 +134,10 @@ export default defineConfig({ sidebar: { collapsed: true }, }), lunaria(), - // Uncomment to enable links validation when building locally; netlify crashes for API routes - // starlightLinksValidator({ - // exclude: ['/plugins'], - // }), - ], + validateLinks ? starlightLinksValidator({ + exclude: ['/plugins'], + }) : null, + ].filter(Boolean), }), tailwind(), ],