-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathastro.config.ts
More file actions
144 lines (137 loc) · 4.23 KB
/
Copy pathastro.config.ts
File metadata and controls
144 lines (137 loc) · 4.23 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import fs from 'node:fs'
import path from 'node:path'
import mdx from '@astrojs/mdx'
import preact from '@astrojs/preact'
import sitemap from '@astrojs/sitemap'
import { defineConfig } from 'astro/config'
import { h } from 'hastscript'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeKatex from 'rehype-katex'
import rehypeSlug from 'rehype-slug'
import remarkMath from 'remark-math'
// netlify - build vars https://docs.netlify.com/build/configure-builds/environment-variables/
const PRODUCTION_SITE_URL = 'https://juxt.pro'
function getSiteUrl() {
if (process.env.NODE_ENV === 'development') {
return 'http://localhost:4321'
}
if (process.env.CONTEXT === 'deploy-preview') {
return process.env.DEPLOY_URL
}
if (process.env.CONTEXT === 'production') {
// https://juxt.pro
return process.env.URL
}
return PRODUCTION_SITE_URL
}
// Build a set of draft career page slugs to exclude from the sitemap
const draftCareerSlugs = new Set<string>()
const careersDir = path.resolve('src/pages/careers')
if (fs.existsSync(careersDir)) {
for (const file of fs.readdirSync(careersDir)) {
if (file.endsWith('.md') || file.endsWith('.mdx')) {
const content = fs.readFileSync(path.join(careersDir, file), 'utf-8')
if (/^draft:\s*true/m.test(content)) {
const slug = file.replace(/\.mdx?$/, '')
draftCareerSlugs.add(`/careers/${slug}/`)
}
}
}
}
// Inline rehype plugin: add target="_blank" to external links
function rehypeExternalLinks() {
return (tree) => {
function visit(node) {
if (node.type === 'element' && node.tagName === 'a' && node.properties?.href) {
const href = node.properties.href
if (typeof href === 'string' && !href.startsWith('#')) {
try {
const url = new URL(href, PRODUCTION_SITE_URL)
if (url.host !== 'juxt.pro') {
node.properties.target = '_blank'
node.properties.rel = 'noopener noreferrer'
}
} catch {}
}
}
if (node.children) node.children.forEach(visit)
}
visit(tree)
}
}
// https://astro.build/config
export default defineConfig({
integrations: [
mdx(),
preact(),
sitemap({
filter: (page) => {
if (page.includes('?')) return false
// Exclude draft blog posts
if (page.includes('/blog/drafts/')) return false
// Exclude draft career pages
const url = new URL(page)
if (draftCareerSlugs.has(url.pathname)) return false
return true
}
})
],
site: getSiteUrl(),
redirects: {
'/careers/senior-kotlin-engineer': '/careers/kotlin-engineer/',
'/careers/senior-kotlin-engineer/': '/careers/kotlin-engineer/',
'/team/mal': '/team/hga',
'/team/mal/': '/team/hga',
'/knowb4ugoxt26': '/documents/xt26-delegate-guide.pdf',
'/knowb4ugoxt26/': '/documents/xt26-delegate-guide.pdf'
},
markdown: {
shikiConfig: {
theme: 'css-variables'
},
remarkPlugins: [remarkMath],
rehypePlugins: [
rehypeSlug,
rehypeKatex,
rehypeAutolinkHeadings,
[
rehypeAutolinkHeadings,
{
behavior: 'prepend',
properties: {
ariaHidden: true,
tabIndex: -1,
class: 'slug-a'
},
// Add svg for heading links
content: () => [
h(
'svg',
{
class: 'slug-svg',
viewBox: '0 0 16 16',
version: '1.1',
width: '1.5rem',
height: '1.5rem'
},
[
h('path', {
fillRule: 'evenodd',
d: 'M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'
})
]
)
]
}
],
rehypeExternalLinks
]
},
vite: {
build: {
rollupOptions: {
external: ['/pagefind/pagefind.js']
}
}
}
})