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
|
import { defineConfig } from "astro/config";
import { globbySync } from "globby";
import fs from "node:fs";
import matter from "gray-matter";
import path from "node:path";
import rehypeExternalLinks from "rehype-external-links";
import sitemap from "@astrojs/sitemap";
import { remarkReadingTime } from "./src/plugins/remarkReadingTime";
import ogImages from "./src/integrations/ogImages";
import rehypeLazyImages from "./src/plugins/rehypeLazyImages";
const blogDir = path.resolve("./src/content/blog");
const lastmodBySlug = Object.fromEntries(
globbySync("*.md", { cwd: blogDir }).map((file) => {
const slug = file.replace(/\.md$/, "");
const { data } = matter(fs.readFileSync(path.join(blogDir, file), "utf8"));
const date = data.dateModified ?? data.datePublished;
return [slug, new Date(date).toISOString()];
})
);
const buildLastmod = new Date().toISOString();
export default defineConfig({
site: "https://popov.link",
output: "static",
integrations: [
sitemap({
serialize(item) {
const url = new URL(item.url);
const match = url.pathname.match(/^\/blog\/([^/]+)\/?$/);
if (match && lastmodBySlug[match[1]]) {
item.lastmod = lastmodBySlug[match[1]];
} else {
item.lastmod = buildLastmod;
}
return item;
},
}),
ogImages(),
],
build: {
inlineStylesheets: "always",
},
markdown: {
remarkPlugins: [remarkReadingTime],
rehypePlugins: [[rehypeExternalLinks, { target: "_blank", rel: ["noopener", "noreferrer"] }], rehypeLazyImages],
shikiConfig: {
theme: "vitesse-dark",
},
},
});
|