feat: add RSS feed beautification option

Introduces a new RSS_BEAUTIFY configuration flag to enable RSS feed styling
- Adds XSL styling support for RSS feeds when enabled
- Updates documentation in both English and Chinese
- Modifies RSS generation to support the new styling option

Migration from rss to getRssString for enhanced customization
This commit is contained in:
ccbikai
2025-01-01 18:07:00 +08:00
parent 668b70df1d
commit 0dbec343b4
5 changed files with 25 additions and 3 deletions

View File

@@ -23,4 +23,5 @@ GOOGLE_SEARCH_SITE=""
TAGS=""
COMMENTS=""
LINKS=""
NAVS=""
NAVS=""
RSS_BEAUTIFY=false

View File

@@ -133,6 +133,9 @@ LINKS=Title1,URL1;Title2,URL3;Title3,URL3;
## Sidebar Navigation Item, Separate using commas and semicolons
NAVS=Title1,URL1;Title2,URL3;Title3,URL3;
## Enable RSS beautify
RSS_BEAUTIFY=true
```
## 🙋🏻 FAQs

View File

@@ -131,6 +131,9 @@ LINKS=Title1,URL1;Title2,URL3;Title3,URL3;
## 侧边栏导航项, 使用英文逗号和分号分割
NAVS=Title1,URL1;Title2,URL3;Title3,URL3;
## 启用 RSS 美化
RSS_BEAUTIFY=true
```
## 🙋🏻 常问问题

1
src/assets/rss.xsl Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,8 @@
import rss from '@astrojs/rss'
import { getRssString } from '@astrojs/rss'
import sanitizeHtml from 'sanitize-html'
import { getChannelInfo } from '../lib/telegram'
import { getEnv } from '../lib/env'
import style from '../assets/rss.xsl?raw'
export async function GET(Astro) {
const { SITE_URL } = Astro.locals
@@ -15,7 +17,7 @@ export async function GET(Astro) {
url.pathname = SITE_URL
url.search = ''
return rss({
let rssString = await getRssString({
title: `${tag ? `${tag} | ` : ''}${channel.title}`,
description: channel.description,
site: url.origin,
@@ -39,4 +41,16 @@ export async function GET(Astro) {
}),
})),
})
const enableBeautify = getEnv(import.meta.env, Astro, 'RSS_BEAUTIFY')
if (enableBeautify) {
rssString = rssString.replace(/^(<\?xml .*\?>)/i, style)
}
return new Response(rssString, {
headers: {
'Content-Type': 'text/xml',
'Cache-Control': 'public, max-age=3600',
},
})
}