diff options
author | João Augusto Costa Branco Marado Torres <torres.dev@disroot.org> | 2025-06-24 12:08:41 -0300 |
---|---|---|
committer | João Augusto Costa Branco Marado Torres <torres.dev@disroot.org> | 2025-06-24 12:50:43 -0300 |
commit | f9a77c5c27aede4e5978eb55d9b7af781b680a1d (patch) | |
tree | d545e325ba1ae756fc2eac66fac1001b6753c40d /astro.config.ts |
feat!: initial commit
Signed-off-by: João Augusto Costa Branco Marado Torres <torres.dev@disroot.org>
Diffstat (limited to 'astro.config.ts')
-rw-r--r-- | astro.config.ts | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/astro.config.ts b/astro.config.ts new file mode 100644 index 0000000..499b7ec --- /dev/null +++ b/astro.config.ts @@ -0,0 +1,98 @@ +// @ts-check +import { defineConfig } from "astro/config"; +import sitemap from "@astrojs/sitemap"; +import { parseFrontmatter } from "@astrojs/markdown-remark"; +import remarkGfm from "remark-gfm"; +import remarkSmartypants from "remark-smartypants"; +import rehypeExternalLinks from "rehype-external-links"; +import type { Root } from "mdast"; +import type { VFile } from "vfile"; +import type { Plugin } from "unified"; +import type { Options } from "retext-smartypants"; +import { visit } from "unist-util-visit"; +import rehypeSanitize from "rehype-sanitize"; +import remarkToc from "remark-toc"; +import { get } from "./src/utils/anonymous.ts"; + +// https://astro.build/config +export default defineConfig({ + site: "https://cravodeabril.pt", + integrations: [sitemap({ + serialize: async (item) => { + const match = item.url.match(/\/blog\/read\/([^/]+)\/$/); + if (match === null) { + return item; + } + const slug = match[1]; + + let frontmatter; + try { + frontmatter = await Deno.readTextFile( + `${Deno.cwd()}/public/blog/${slug}.md`, + ).then(parseFrontmatter).then(get("frontmatter")); + } catch { + return item; + } + + item.lastmod = (frontmatter.dateUpdated ?? frontmatter.dateCreated) + .toISOString(); + for await ( + const { name, isFile } of Deno.readDir(`${Deno.cwd()}/public/blog/`) + ) { + if (!name.endsWith(".md") || !isFile || name === `${slug}.md`) { + continue; + } + + let frontmatter; + try { + frontmatter = await Deno.readTextFile( + `${Deno.cwd()}/public/blog/${name}`, + ).then(parseFrontmatter).then(get("frontmatter")); + } catch { + continue; + } + + if (frontmatter.translationOf !== slug) { + continue; + } + + item.links ??= []; + item.links.push({ + url: `https://cravodeabril.pt/blog/${name}`, + lang: frontmatter.lang, + hreflang: frontmatter.lang, + }); + } + return item; + }, + xslURL: "/sitemap.xsl", + })], + server: ({ command }) => ({ + host: command === "dev", + }), + prefetch: true, + markdown: { + remarkPlugins: [ + remarkGfm, + remarkSmartypants as Plugin<[(Options | undefined)?], Root>, + [remarkToc, { ordered: true }], + () => (tree: Root, _file: VFile): void => { + visit(tree, function (node) { + if (node.type === "heading") { + node.depth++; + } + }); + }, + ], + rehypePlugins: [ + [ + rehypeExternalLinks, + { + target: "_blank", + }, + ], + rehypeSanitize, + ], + remarkRehype: { clobberPrefix: "" }, + }, +}); |