diff options
| author | Valentin Popov <valentin@popov.link> | 2026-04-22 20:53:21 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-04-22 20:53:21 +0300 |
| commit | 933d6874b1fe1dbb113e9de39425f2d713a72408 (patch) | |
| tree | 44278a4088a2144ac08fb72fd4abe86ab60a55e8 /astro.config.mjs | |
| parent | 5e818d804d5d38beff0f3754a006333752fd5082 (diff) | |
| download | popov.link-933d6874b1fe1dbb113e9de39425f2d713a72408.tar.xz popov.link-933d6874b1fe1dbb113e9de39425f2d713a72408.zip | |
feat: enhance blog and SEO features with new plugins and metadata
- Introduced rehypeLazyImages plugin for lazy loading images in blog posts.
- Updated sitemap integration to include last modified dates for blog posts.
- Enhanced Head and BaseLayout components to support additional Open Graph metadata.
- Improved RSS feed generation with sanitized content and author information.
- Updated manifest.json for a darker theme and standalone display mode.
- Added support for language-specific attributes in various components.
- Refactored blog post handling to include modified and published timestamps.
Diffstat (limited to 'astro.config.mjs')
| -rw-r--r-- | astro.config.mjs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/astro.config.mjs b/astro.config.mjs index bbf2ac0..fab0838 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,17 +1,54 @@ 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 sitemap from "@astrojs/sitemap"; +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(), ogImages()], + 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", }, |
