Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Check

# Builds the site for every pull request, the same way the deploy workflow does,
# so that a change that breaks the build (a share-image headline that no longer
# fits, a page that fails to render) shows up before it reaches main.

on:
pull_request:
branches: [main]

permissions:
contents: read

concurrency:
group: check-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# The sitemap's <lastmod> and the dates on doc pages come from git history.
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build site
run: pnpm build
env:
GITHUB_TOKEN: ${{ github.token }}
21 changes: 17 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ on:
schedule:
- cron: "41 */3 * * *"

permissions:
contents: read
pages: write
id-token: write
# Each job gets only what it needs (below). The build runs third-party code from
# npm with GITHUB_TOKEN in its environment, so it may only read; the Pages
# permissions belong to the deploy job alone.
permissions: {}

concurrency:
group: pages
Expand All @@ -22,9 +22,15 @@ concurrency:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# The sitemap's <lastmod> and the dates on doc pages come from git
# history; a shallow clone would leave them out.
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v4
Expand All @@ -42,6 +48,10 @@ jobs:

- name: Build site
run: pnpm build
env:
# The build reads versions and releases from the GitHub API; with a
# token the anonymous rate limit does not apply.
GITHUB_TOKEN: ${{ github.token }}

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
Expand All @@ -51,6 +61,9 @@ jobs:
deploy:
needs: build
runs-on: ubuntu-latest
permissions:
pages: write # to deploy to GitHub Pages
id-token: write # to verify that the deployment comes from this workflow
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
Expand Down
36 changes: 26 additions & 10 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// @ts-check
import { defineConfig } from 'astro/config';
import react from '@astrojs/react';
import sitemap from '@astrojs/sitemap';
import sitemap, { ChangeFreqEnum } from '@astrojs/sitemap';
import tailwindcss from '@tailwindcss/vite';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import { lastModified, pageReleases, pageSources } from './src/lib/lastmod.ts';
import { getReleases } from './src/lib/github.ts';

// https://astro.build/config
export default defineConfig({
Expand All @@ -24,7 +26,7 @@ export default defineConfig({
locales: { en: 'en', 'zh-CN': 'zh-CN' },
},
filter: (page) => !page.includes('/404'),
serialize(item) {
async serialize(item) {
const url = new URL(item.url);
const pathname = url.pathname.replace(/\/$/, '') || '/';
const isHome = pathname === '/' || pathname === '/zh-CN';
Expand All @@ -38,29 +40,43 @@ export default defineConfig({

if (isHome) {
item.priority = 1.0;
item.changefreq = 'weekly';
item.changefreq = ChangeFreqEnum.WEEKLY;
} else if (isProduct) {
item.priority = 0.9;
item.changefreq = 'weekly';
item.changefreq = ChangeFreqEnum.WEEKLY;
} else if (isDocsIndex) {
item.priority = 0.9;
item.changefreq = 'weekly';
item.changefreq = ChangeFreqEnum.WEEKLY;
} else if (isDoc) {
// Includes the product doc sets under /docs/lite/ and /docs/core/.
item.priority = 0.8;
item.changefreq = 'monthly';
item.changefreq = ChangeFreqEnum.MONTHLY;
} else if (isChangelog) {
item.priority = 0.7;
item.changefreq = 'weekly';
item.changefreq = ChangeFreqEnum.WEEKLY;
} else if (isLicense) {
item.priority = 0.6;
item.changefreq = 'monthly';
item.changefreq = ChangeFreqEnum.MONTHLY;
} else {
item.priority = 0.5;
item.changefreq = 'monthly';
item.changefreq = ChangeFreqEnum.MONTHLY;
}

item.lastmod = new Date().toISOString();
// When the page's own files last changed in git, or the latest release
// of a product the page shows came out, whichever is later. Left out
// without git history: a release date alone does not say when the
// page itself last changed.
const committed = lastModified(pageSources(pathname));
if (committed) {
let latest = Date.parse(committed);
const products = pageReleases(pathname);
if (products.length) {
// Newest first: the first match is the latest release among them.
const release = (await getReleases()).find((r) => products.includes(r.product));
if (release) latest = Math.max(latest, Date.parse(release.date));
}
item.lastmod = new Date(latest).toISOString();
}
return item;
},
}),
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"prebuild": "node scripts/generate-og.mjs && node scripts/generate-favicons.mjs",
"prebuild": "node scripts/generate-favicons.mjs",
"build": "astro build && pnpm run pagefind",
"pagefind": "pagefind --site dist --output-path dist/pagefind",
"preview": "astro preview",
"og": "node scripts/generate-og.mjs",
"releases": "node scripts/update-releases.mjs",
"favicons": "node scripts/generate-favicons.mjs",
"astro": "astro"
},
Expand All @@ -28,9 +28,13 @@
"three": "^0.183.2"
},
"devDependencies": {
"@fontsource/geist": "^5.3.0",
"@fontsource/geist-mono": "^5.3.0",
"@types/fontkit": "^2.0.9",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@types/three": "^0.183.1",
"fontkit": "^2.0.4",
"pagefind": "^1.5.0",
"rehype-autolink-headings": "^7.1.0",
"rehype-slug": "^6.0.0",
Expand Down
Loading
Loading