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
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
44 changes: 44 additions & 0 deletions src/plugins/preload-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 cssFile = fs.readdirSync(cssDir).find(
(f) => f.startsWith("styles.") && f.endsWith(".css"),
)
if (!cssFile) return

const baseUrl = siteConfig.baseUrl.replace(/\/$/, "")
const href = `${baseUrl}/assets/css/${cssFile}`
const preloadTag = `<link rel="preload" as="style" href="${href}">`

function walk(dir) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name)
if (entry.isDirectory()) {
walk(full)
} else if (entry.name.endsWith(".html")) {
inject(full)
}
}
}

function inject(filePath) {
let html = fs.readFileSync(filePath, "utf8")
if (html.includes(preloadTag)) return
html = html.replace("<head>", `<head>${preloadTag}`)
fs.writeFileSync(filePath, html)
}

walk(outDir)
},
}
}
Loading