| 1 |
|
| 2 |
import {defineConfig} from "astro/config"; |
| 3 |
import tailwindcss from "@tailwindcss/vite"; |
| 4 |
import rehypeSlug from "rehype-slug"; |
| 5 |
import rehypeAutolinkHeadings from "rehype-autolink-headings"; |
| 6 |
import rehypeExternalLinks from "rehype-external-links"; |
| 7 |
import {rehypeSections} from "./src/lib/rehype-sections.js"; |
| 8 |
import {remarkCdnVersion} from "./src/lib/remark-cdn-version.js"; |
| 9 |
import {codeBlockTransformer} from "./src/lib/shiki-transformers.js"; |
| 10 |
import {readdirSync, readFileSync} from "node:fs"; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
const {version} = JSON.parse(readFileSync("./src/data/integrity.json", "utf8")); |
| 15 |
|
| 16 |
import mdx from "@astrojs/mdx"; |
| 17 |
import sitemap from "@astrojs/sitemap"; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
function buildCategoryRedirects() { |
| 22 |
const redirects = {}; |
| 23 |
for (const collection of ['reference', 'patterns']) { |
| 24 |
const base = `./src/content/${collection}`; |
| 25 |
let subfolders; |
| 26 |
try { subfolders = readdirSync(base, {withFileTypes: true}).filter(d => d.isDirectory() && d.name !== 'index'); } catch { continue; } |
| 27 |
for (const dir of subfolders.sort((a, b) => a.name.localeCompare(b.name))) { |
| 28 |
const files = readdirSync(`${base}/${dir.name}`).filter(f => /\.(md|mdx)$/.test(f) && !f.startsWith('index')).sort(); |
| 29 |
if (files.length === 0) continue; |
| 30 |
const hasIndexFile = readdirSync(`${base}/${dir.name}`).some(f => f === 'index.md' || f === 'index.mdx'); |
| 31 |
if (hasIndexFile) continue; |
| 32 |
const catSlug = dir.name.replace(/^\d+-/, ''); |
| 33 |
const firstSlug = files[0].replace(/\.(md|mdx)$/, '').replace(/^\d+-/, ''); |
| 34 |
redirects[`/${collection}/${catSlug}`] = `/${collection}/${catSlug}/${firstSlug}`; |
| 35 |
} |
| 36 |
} |
| 37 |
return redirects; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
export default defineConfig({ |
| 42 |
site: "https://four.htmx.org", |
| 43 |
|
| 44 |
server: { |
| 45 |
host: true, |
| 46 |
}, |
| 47 |
|
| 48 |
vite: { |
| 49 |
plugins: [tailwindcss()], |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
optimizeDeps: { force: true }, |
| 55 |
}, |
| 56 |
|
| 57 |
markdown: { |
| 58 |
remarkPlugins: [ |
| 59 |
[remarkCdnVersion, {version}], |
| 60 |
], |
| 61 |
rehypePlugins: [ |
| 62 |
rehypeSlug, |
| 63 |
[rehypeSections, {split: 'h2'}], |
| 64 |
[ |
| 65 |
rehypeAutolinkHeadings, |
| 66 |
{ |
| 67 |
behavior: "wrap", |
| 68 |
test: (node) => node.tagName !== 'h1', |
| 69 |
}, |
| 70 |
], |
| 71 |
[ |
| 72 |
rehypeExternalLinks, |
| 73 |
{ |
| 74 |
target: "_blank", |
| 75 |
rel: ["noopener", "noreferrer"], |
| 76 |
}, |
| 77 |
], |
| 78 |
], |
| 79 |
shikiConfig: { |
| 80 |
theme: "css-variables", |
| 81 |
transformers: [codeBlockTransformer] |
| 82 |
}, |
| 83 |
}, |
| 84 |
|
| 85 |
redirects: { |
| 86 |
"/sitemap.xml": "/sitemap-index.xml", |
| 87 |
|
| 88 |
|
| 89 |
...buildCategoryRedirects(), |
| 90 |
|
| 91 |
|
| 92 |
"/docs/get-started": "/docs#installation", |
| 93 |
"/docs/get-started/installation": "/docs#installation", |
| 94 |
"/docs/get-started/migration": "/docs#migration", |
| 95 |
"/docs/core-concepts": "/docs#mental-model", |
| 96 |
"/docs/core-concepts/mental-model": "/docs#mental-model", |
| 97 |
"/docs/core-concepts/hypermedia-controls": "/docs#hypermedia-controls", |
| 98 |
"/docs/core-concepts/requests-and-responses": "/docs#requests--responses", |
| 99 |
"/docs/core-concepts/client-scripting": "/docs#client-side-scripting", |
| 100 |
"/docs/core-concepts/multi-target-updates": "/docs#multi-target-updates", |
| 101 |
"/docs/core-concepts/hcon": "/docs#hcon", |
| 102 |
"/docs/features": "/docs#css-transitions", |
| 103 |
"/docs/features/css-transitions": "/docs#css-transitions", |
| 104 |
"/docs/features/synchronization": "/docs#synchronization", |
| 105 |
"/docs/features/confirmations": "/docs#confirmations", |
| 106 |
"/docs/features/boosting": "/docs#boosting", |
| 107 |
"/docs/features/history": "/docs#history", |
| 108 |
"/docs/features/validation": "/docs#validation", |
| 109 |
"/docs/features/web-components": "/docs#web-components", |
| 110 |
"/docs/features/attribute-inheritance": "/docs#attribute-inheritance", |
| 111 |
"/docs/features/extended-selectors": "/docs#extended-selectors-1", |
| 112 |
"/docs/features/extensions": "/docs#extensions", |
| 113 |
"/docs/security": "/docs#best-practices", |
| 114 |
"/docs/security/best-practices": "/docs#best-practices", |
| 115 |
"/docs/security/caching": "/docs#caching", |
| 116 |
"/docs/troubleshoot": "/docs#debugging", |
| 117 |
"/docs/troubleshoot/debugging": "/docs#debugging", |
| 118 |
"/docs/troubleshoot/configuration": "/docs#configuration", |
| 119 |
"/docs/editors": "/docs#vs-code", |
| 120 |
"/docs/editors/vscode": "/docs#vs-code", |
| 121 |
"/docs/full": "/docs", |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
"/migration-guide-hotwire-turbo": "/docs/get-started/migration-turbo", |
| 129 |
"/migration-guide-htmx-1": "/docs/get-started/migration-htmx-1", |
| 130 |
"/migration-guide-htmx-2": "/docs/get-started/migration", |
| 131 |
"/migration-guide-htmx-4": "/docs/get-started/migration", |
| 132 |
"/migration-guide-intercooler": "/docs/get-started/migration-intercooler", |
| 133 |
"/htmx-4": "/docs/get-started/migration", |
| 134 |
"/whats-new-in-htmx-4": "/docs/get-started/migration", |
| 135 |
|
| 136 |
|
| 137 |
"/discord": "https://htmx.org/discord", |
| 138 |
"/events": "/reference", |
| 139 |
|
| 140 |
|
| 141 |
"/reference/attributes": "/reference", |
| 142 |
"/reference/headers": "/reference", |
| 143 |
"/reference/events": "/reference", |
| 144 |
"/reference/config": "/reference", |
| 145 |
"/reference/methods": "/reference", |
| 146 |
"/help": "/about", |
| 147 |
"/server-examples": "/about", |
| 148 |
|
| 149 |
/* |
| 150 |
"/examples": "/patterns", |
| 151 |
"/examples/click-to-load": "/patterns/loading/click-to-load", |
| 152 |
"/examples/infinite-scroll": "/patterns/loading/infinite-scroll", |
| 153 |
"/examples/lazy-load": "/patterns/loading/lazy-load", |
| 154 |
"/examples/progress-bar": "/patterns/loading/progress-bar", |
| 155 |
"/examples/active-search": "/patterns/forms/active-search", |
| 156 |
"/examples/inline-validation": "/patterns/forms/active-validation", |
| 157 |
"/examples/file-upload": "/patterns/forms/file-upload", |
| 158 |
"/examples/file-upload-input": "/patterns/forms/file-upload", |
| 159 |
"/examples/value-select": "/patterns/forms/linked-selects", |
| 160 |
"/examples/reset-user-input": "/patterns/forms/reset-on-submit", |
| 161 |
"/examples/bulk-update": "/patterns/records/bulk-actions", |
| 162 |
"/examples/delete-row": "/patterns/records/delete-in-place", |
| 163 |
"/examples/sortable": "/patterns/records/drag-to-reorder", |
| 164 |
"/examples/click-to-edit": "/patterns/records/edit-in-place", |
| 165 |
"/examples/edit-row": "/patterns/records/edit-in-place", |
| 166 |
"/examples/animations": "/patterns/display/animations", |
| 167 |
"/examples/dialogs": "/patterns/display/dialogs", |
| 168 |
"/examples/modal-uikit": "/patterns/display/dialogs", |
| 169 |
"/examples/modal-bootstrap": "/patterns/display/dialogs", |
| 170 |
"/examples/modal-custom": "/patterns/display/dialogs", |
| 171 |
"/examples/tabs-hateoas": "/patterns", |
| 172 |
"/examples/tabs-javascript": "/patterns", |
| 173 |
"/examples/keyboard-shortcuts": "/patterns/advanced/keyboard-shortcuts", |
| 174 |
"/examples/update-other-content": "/patterns", |
| 175 |
"/examples/confirm": "/patterns", |
| 176 |
"/examples/async-auth": "/patterns", |
| 177 |
"/examples/web-components": "/patterns", |
| 178 |
"/examples/move-before": "/patterns", |
| 179 |
|
| 180 |
s. |
| 181 |
"/extensions/sse": "/extensions/hx-sse", |
| 182 |
"/extensions/ws": "/extensions/hx-ws", |
| 183 |
"/extensions/head-support": "/extensions/hx-head", |
| 184 |
"/extensions/preload": "/extensions/hx-preload", |
| 185 |
"/extensions/browser-indicator": "/extensions/hx-browser-indicator", |
| 186 |
"/extensions/alpine-compat": "/extensions/hx-alpine-compat", |
| 187 |
"/extensions/optimistic": "/extensions/hx-optimistic", |
| 188 |
"/extensions/upsert": "/extensions/hx-upsert", |
| 189 |
"/extensions/building": "/docs/features/extensions", |
| 190 |
|
| 191 |
s. |
| 192 |
"/docs/extensions": "/extensions", |
| 193 |
"/docs/extensions/using-extensions": "/docs/features/extensions", |
| 194 |
"/docs/extensions/extension-migration": "/docs/get-started/migration", |
| 195 |
"/docs/extensions/htmx-2-compat": "/extensions/htmx-2-compat", |
| 196 |
"/docs/extensions/sse": "/extensions/hx-sse", |
| 197 |
"/docs/extensions/ws": "/extensions/hx-ws", |
| 198 |
"/docs/extensions/head-support": "/extensions/hx-head", |
| 199 |
"/docs/extensions/preload": "/extensions/hx-preload", |
| 200 |
"/docs/extensions/optimistic": "/extensions/hx-optimistic", |
| 201 |
"/docs/extensions/download": "/extensions/hx-download", |
| 202 |
"/docs/extensions/upsert": "/extensions/hx-upsert", |
| 203 |
"/docs/extensions/targets": "/extensions/hx-targets", |
| 204 |
"/docs/extensions/ptag": "/extensions/hx-ptag", |
| 205 |
"/docs/extensions/browser-indicator": "/extensions/hx-browser-indicator", |
| 206 |
"/docs/extensions/alpine-compat": "/extensions/hx-alpine-compat", |
| 207 |
"/docs/extensions/history-cache": "/extensions/hx-history-cache", |
| 208 |
|
| 209 |
|
| 210 |
"/essays/interviews/henning-koch": "/interviews/henning-koch", |
| 211 |
"/essays/interviews/makinde-adeagbo": "/interviews/makinde-adeagbo", |
| 212 |
"/essays/interviews/chris-wanstrath": "/interviews/chris-wanstrath", |
| 213 |
"/essays/interviews/mike-amundsen": "/interviews/mike-amundsen", |
| 214 |
"/essays/interviews/leonard-richardson": "/interviews/leonard-richardson", |
| 215 |
}, |
| 216 |
|
| 217 |
integrations: [ |
| 218 |
mdx(), |
| 219 |
sitemap({ |
| 220 |
filter(page) { |
| 221 |
const { pathname } = new URL(page); |
| 222 |
|
| 223 |
|
| 224 |
if (pathname === '/reference/headers/HX-Push') { |
| 225 |
return false; |
| 226 |
} |
| 227 |
|
| 228 |
return true; |
| 229 |
}, |
| 230 |
}), |
| 231 |
], |
| 232 |
|
| 233 |
trailingSlash: "never", |
| 234 |
}); |