Skip to content

Commit

Permalink
Merge pull request #54 from EveSunMaple/dev
Browse files Browse the repository at this point in the history
✨ Add RSS Full Text
  • Loading branch information
EveSunMaple authored Nov 29, 2024
2 parents 13d8ebc + bdec50f commit f43546d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 29 additions & 6 deletions src/pages/rss.xml.js
Original file line number Diff line number Diff line change
@@ -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
? `<![CDATA[${replacePath(marked(body), siteUrl)}]]>`
: "No content available.";
return {
title: data.title || "Untitled",
pubDate: new Date(data.pubDate).toUTCString(),
link: `/blog/${slug}/`,
description: data.description || "No description provided.",
content,
};
}),
});
}
13 changes: 3 additions & 10 deletions src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f43546d

Please sign in to comment.