Repository navigation
Expand file tree
/
Copy pathastro.config.mjs
More file actions
43 lines (40 loc) · 2.1 KB
/
Copy pathastro.config.mjs
File metadata and controls
43 lines (40 loc) · 2.1 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
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import sitemap from '@astrojs/sitemap';
import { createReadStream, existsSync, statSync } from 'node:fs';
import { join, normalize, extname } from 'node:path';
import remarkMermaid from './src/lib/remark-mermaid.mjs';
import rehypeTableWrap from './src/lib/rehype-table-wrap.mjs';
// Pages that should not appear in the sitemap.
const HIDDEN = /\/(404|search|cv|guide)\/?$/;
// In `npm run dev`, serve ./media at /media so videos and large files work locally.
// In production the web server (Caddy on Hetzner) or a separate media origin serves them.
const TYPES = { '.mp4': 'video/mp4', '.webm': 'video/webm', '.vtt': 'text/vtt', '.pdf': 'application/pdf', '.png': 'image/png', '.jpg': 'image/jpeg', '.webp': 'image/webp', '.zip': 'application/zip' };
const devMedia = {
name: 'dev-media',
hooks: {
'astro:server:setup': ({ server }) => {
server.middlewares.use('/media', (req, res, next) => {
const file = normalize(join(process.cwd(), 'media', decodeURIComponent((req.url || '/').split('?')[0])));
if (!file.startsWith(join(process.cwd(), 'media')) || !existsSync(file) || statSync(file).isDirectory()) return next();
res.setHeader('Content-Type', TYPES[extname(file)] || 'application/octet-stream');
createReadStream(file).pipe(res);
});
},
},
};
export default defineConfig({
site: process.env.SITE_URL
// Cloudflare Pages preview branches get their own URL so canonicals and the sitemap match.
|| (process.env.CF_PAGES && process.env.CF_PAGES_BRANCH !== 'main' ? process.env.CF_PAGES_URL : undefined)
|| 'https://djonko.dev',
trailingSlash: 'always',
prefetch: { prefetchAll: false, defaultStrategy: 'hover' },
integrations: [mdx(), sitemap({ filter: (page) => !HIDDEN.test(new URL(page).pathname) }), devMedia],
markdown: {
remarkPlugins: [remarkMermaid],
rehypePlugins: [rehypeTableWrap],
syntaxHighlight: { type: 'shiki', excludeLangs: ['mermaid'] },
shikiConfig: { themes: { light: 'github-light-high-contrast', dark: 'github-dark-high-contrast' } },
},
});