From bdec50ff3b5853b4d4ac0b7221e01743857335a5 Mon Sep 17 00:00:00 2001 From: EveSunMaple Date: Fri, 29 Nov 2024 19:38:29 +0800 Subject: [PATCH] feat: test rss.xml.js --- package.json | 2 +- pnpm-lock.yaml | 6 +++--- src/pages/rss.xml.js | 35 +++++++++++++++++++++++++++++------ src/styles/global.scss | 13 +++---------- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 3445957..291796b 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,6 @@ "rehype-katex": "^7.0.1", "remark-directive": "^3.0.0", "remark-math": "^6.0.0", - "sass": "^1.81.0", "shiki": "^1.23.0", "swup": "^4.8.1", "typescript": "^5.6.3", @@ -62,6 +61,7 @@ "daisyui": "^4.12.14", "prettier": "^3.3.3", "prettier-plugin-astro": "^0.14.1", + "sass": "^1.81.0", "tailwindcss": "^3.4.15" }, "pnpm": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1258f01..92b542b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -131,9 +131,6 @@ importers: remark-math: specifier: ^6.0.0 version: 6.0.0 - sass: - specifier: ^1.81.0 - version: 1.81.0 shiki: specifier: ^1.23.0 version: 1.23.0 @@ -162,6 +159,9 @@ importers: prettier-plugin-astro: specifier: ^0.14.1 version: 0.14.1 + sass: + specifier: ^1.81.0 + version: 1.81.0 tailwindcss: specifier: ^3.4.15 version: 3.4.15 diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 5a781b6..7fe8ca0 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -1,16 +1,39 @@ import rss from "@astrojs/rss"; import { getCollection } from "astro:content"; -import { SITE_TITLE, SITE_DESCRIPTION } from "../consts"; +import { SITE_TITLE, SITE_DESCRIPTION, SITE_LANG } from "../consts"; +import { marked } from "marked"; export async function GET(context) { const posts = await getCollection("blog"); + const siteUrl = context.site; + + function replacePath(content, siteUrl) { + return content.replace(/(src|img|r|l)="([^"]+)"/g, (match, attr, src) => { + if (!src.startsWith("http") && !src.startsWith("//") && !src.startsWith("data:")) { + return `${attr}="${new URL(src, siteUrl).toString()}"`; + } + return match; + }); + } + return rss({ title: SITE_TITLE, description: SITE_DESCRIPTION, - site: context.site, - items: posts.map((post) => ({ - ...post.data, - link: `/blog/${post.slug}/`, - })), + site: siteUrl, + language: SITE_LANG, + generator: "Astro RSS Generator", + items: posts.map((post) => { + const { body, data, slug } = post; + const content = body + ? `` + : "No content available."; + return { + title: data.title || "Untitled", + pubDate: new Date(data.pubDate).toUTCString(), + link: `/blog/${slug}/`, + description: data.description || "No description provided.", + content, + }; + }), }); } diff --git a/src/styles/global.scss b/src/styles/global.scss index 1a6a2ed..3a5a983 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -98,13 +98,6 @@ summary { list-style: none; } -@font-face { - font-family: "Cascadia"; - src: url("/fonts/CascadiaCode.woff2") format("woff2"); - font-style: normal; - font-display: swap; -} - a { svg { @apply inline-block; @@ -220,12 +213,12 @@ table tr { } code { - font-family: "Cascadia"; + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace; @apply text-xl p-[2px_5px] rounded-sm; } pre { - font-family: "Cascadia"; + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace; padding: 10px; } @@ -293,7 +286,7 @@ thead th { } .highlight .code-lang { - font-family: "Cascadia"; + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace; user-select: none; }