diff --git a/website/README.md b/website/README.md index 849cf25..d35d53c 100644 --- a/website/README.md +++ b/website/README.md @@ -5,6 +5,8 @@ The SQLClean website: the homepage at `/` and the documentation at `/docs/`, bui - `public/index.html` and `public/styles.css`: the homepage, plain static HTML and CSS. Its terminal examples are real `sqlclean` output from small example projects, trimmed to the relevant lines. + The build versions the homepage's `styles.css` link by its content, so a changed stylesheet is + never served from a stale cache. - `src/content/docs/docs/`: the documentation pages (MDX). `src/sidebar.json` holds the sidebar and `src/navigation.mjs` the redirects. `STYLE.md` is the style guide for these pages. - `src/components/`: the page layout, header and page title, replacing Starlight's defaults. diff --git a/website/astro.config.mjs b/website/astro.config.mjs index a451579..54a7409 100644 --- a/website/astro.config.mjs +++ b/website/astro.config.mjs @@ -1,13 +1,31 @@ +import { createHash } from 'node:crypto'; +import { readFile, writeFile } from 'node:fs/promises'; import { defineConfig } from 'astro/config'; import starlight from '@astrojs/starlight'; import starlightLlmsTxt from 'starlight-llms-txt'; import { sqlcleanDark, sqlcleanLight } from './src/code-themes.mjs'; import { redirects, sidebar } from './src/navigation.mjs'; +// The homepage links public/styles.css, which keeps its name; a version from its content makes +// browsers fetch it again whenever it changes. +const versionHomepageStyles = { + name: 'version-homepage-styles', + hooks: { + 'astro:build:done': async ({ dir }) => { + const version = createHash('sha256').update(await readFile(new URL('styles.css', dir))).digest('hex').slice(0, 8); + const page = new URL('index.html', dir); + const html = await readFile(page, 'utf8'); + if (!html.includes('href="styles.css"')) throw new Error('index.html no longer links href="styles.css"'); + await writeFile(page, html.replace('href="styles.css"', `href="/styles.css?v=${version}"`)); + }, + }, +}; + export default defineConfig({ site: 'https://sqlclean.io', redirects, integrations: [ + versionHomepageStyles, starlight({ title: 'SQLClean', description: 'Fast SQL linting, safe fixes and one canonical format.', diff --git a/website/public/index.html b/website/public/index.html index 77d9695..e10fdb0 100644 --- a/website/public/index.html +++ b/website/public/index.html @@ -63,11 +63,7 @@
Rust-powered · Free and open source · Apache-2.0
A SQL linter and formatter, 50× faster than sqruff.
-
- SQLClean spots SQL patterns that look right but quietly misbehave, such as = NULL or a
- NOT IN list with a NULL, applies safe fixes, and formats every file one way.
- Custom Rules are plain Python functions, backed by a Rust API that keeps them fast.
-
Catch SQL that looks right but quietly misbehaves, apply safe fixes, and format every file one way.