From f9a77c5c27aede4e5978eb55d9b7af781b680a1d Mon Sep 17 00:00:00 2001 From: João Augusto Costa Branco Marado Torres Date: Tue, 24 Jun 2025 12:08:41 -0300 Subject: feat!: initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Augusto Costa Branco Marado Torres --- astro.config.ts | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 astro.config.ts (limited to 'astro.config.ts') 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: "" }, + }, +}); -- cgit v1.2.3