Skip to content

Commit

Permalink
feat: add RSS feed beautification option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ccbikai committed Jan 1, 2025
1 parent 668b70d commit 0dbec34
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ GOOGLE_SEARCH_SITE=""
TAGS=""
COMMENTS=""
LINKS=""
NAVS=""
NAVS=""
RSS_BEAUTIFY=false
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ LINKS=Title1,URL1;Title2,URL3;Title3,URL3;
## 侧边栏导航项, 使用英文逗号和分号分割
NAVS=Title1,URL1;Title2,URL3;Title3,URL3;
## 启用 RSS 美化
RSS_BEAUTIFY=true
```

## 🙋🏻 常问问题
Expand Down
1 change: 1 addition & 0 deletions src/assets/rss.xsl

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions src/pages/rss.xml.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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',
},
})
}

0 comments on commit 0dbec34

Please sign in to comment.