Skip to content
Closed
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
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ jobs:
- run: npm install
- name: Test Build
run: npm run build
- name: Commit updated vercel.json
if: github.event_name == 'pull_request'
run: |
git diff --quiet vercel.json && exit 0
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add vercel.json
git commit -m "chore: update CSS preload headers in vercel.json"
git push origin HEAD:${{ github.head_ref }}
1 change: 1 addition & 0 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const config: Config = {
// buttonPosition: "center-right",
// },
// ],
"./src/plugins/preload-css",
async function tailwindcss(context, options) {
return {
name: "docusaurus-tailwindcss",
Expand Down
54 changes: 54 additions & 0 deletions src/plugins/preload-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright © 2026 Ory Corp
// SPDX-License-Identifier: Apache-2.0

const fs = require("fs")
const path = require("path")

module.exports = function preloadCssPlugin() {
return {
name: "preload-css",
async postBuild({ outDir, siteConfig }) {
const cssDir = path.join(outDir, "assets", "css")
if (!fs.existsSync(cssDir)) return

const cssFiles = fs.readdirSync(cssDir).filter((f) => f.endsWith(".css"))
if (cssFiles.length === 0) return

const baseUrl = siteConfig.baseUrl.replace(/\/$/, "")
const linkValue = cssFiles
.map((f) => `<${baseUrl}/assets/css/${f}>; rel=preload; as=style`)
.join(", ")

const vercelJsonPath = path.join(__dirname, "..", "..", "vercel.json")
const vercelJson = JSON.parse(fs.readFileSync(vercelJsonPath, "utf-8"))

// Remove any existing preload header entries we previously added
vercelJson.headers = vercelJson.headers.filter(
(h) =>
h.source !== "/docs/:path*" ||
!h.headers.some((hh) => hh.key === "Link"),
)

// Add Link preload header for all doc pages
vercelJson.headers.push({
source: "/docs/:path*",
headers: [
{
key: "Link",
value: linkValue,
},
],
})

fs.writeFileSync(
vercelJsonPath,
JSON.stringify(vercelJson, null, 2) + "\n",
)

console.log(
"[preload-css] Updated vercel.json with %d CSS preload links",
cssFiles.length,
)
},
}
}
Loading