-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastro.config.mjs
More file actions
77 lines (75 loc) · 3 KB
/
astro.config.mjs
File metadata and controls
77 lines (75 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";
import tailwindcss from "@tailwindcss/vite";
import { transformerNotationDiff, transformerNotationHighlight } from "@shikijs/transformers";
import { defineConfig } from "astro/config";
import remarkRenderMermaid from "./scripts/remark-render-mermaid.mjs";
import remarkRewritePostAssets from "./scripts/remark-rewrite-post-assets.mjs";
function ghPagesConfig() {
const isPages = process.env.GITHUB_PAGES === "true";
const repoFull = process.env.GITHUB_REPOSITORY;
const owner = process.env.GITHUB_REPOSITORY_OWNER;
if (!isPages || !repoFull || !owner) return {};
const repo = repoFull.split("/")[1];
const isUserSite = repo.endsWith(".github.io");
return { site: `https://${owner}.github.io`, base: isUserSite ? "/" : `/${repo}/` };
}
export default defineConfig({
site: "https://clickin.github.io",
integrations: [
mdx({ remarkPlugins: [remarkRenderMermaid, remarkRewritePostAssets] }),
sitemap({
filter: (page) => !page.includes("/blog/tag/"),
}),
],
markdown: {
shikiConfig: {
themes: {
light: "github-light",
dark: "github-dark",
},
transformers: [transformerNotationDiff(), transformerNotationHighlight()],
},
},
build: {
inlineStylesheets: "auto",
},
vite: {
build: {
assetsInlineLimit: 30720, // 30KB - Inline CSS chunks up to 30KB to reduce render-blocking requests
},
plugins: [
tailwindcss(),
{
name: "pagefind-dev",
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url?.startsWith("/pagefind/")) {
const fs = import("node:fs");
const path = import("node:path");
Promise.all([fs, path]).then(([{ existsSync, statSync, createReadStream }, { join }]) => {
const cleanUrl = req.url.split("?")[0];
const file = join(process.cwd(), "dist", cleanUrl.slice(1));
if (existsSync(file) && statSync(file).isFile()) {
if (file.endsWith(".js")) res.setHeader("Content-Type", "text/javascript");
else if (file.endsWith(".css")) res.setHeader("Content-Type", "text/css");
else if (file.endsWith(".json")) res.setHeader("Content-Type", "application/json");
else if (file.endsWith(".pf_meta")) res.setHeader("Content-Type", "application/octet-stream");
else if (file.endsWith(".pf_fragment")) res.setHeader("Content-Type", "application/octet-stream");
else if (file.endsWith(".pf_index")) res.setHeader("Content-Type", "application/octet-stream");
else if (file.endsWith(".wasm")) res.setHeader("Content-Type", "application/wasm");
createReadStream(file).pipe(res);
return;
}
next();
});
return;
}
next();
});
},
},
],
},
...ghPagesConfig(),
});