Decode HTML entities in RSS episode descriptions; v2.0.20
Publish Container / docker (push) Successful in 15m27s
Publish Container / docker (push) Successful in 15m27s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
ac65db796a
commit
4607532440
2 files changed
+15
-2
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "siteforge",
|
"name": "siteforge",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "2.0.19",
|
"version": "2.0.20",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
+14
-1
@@ -6,6 +6,19 @@ export function extractCdata(raw) {
|
|||||||
return cdata ? cdata[1].trim() : raw.trim()
|
return cdata ? cdata[1].trim() : raw.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function decodeEntities(str) {
|
||||||
|
return str
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, "'")
|
||||||
|
.replace(/'/g, "'")
|
||||||
|
.replace(/&#(\d+);/g, (_, n) => String.fromCharCode(Number(n)))
|
||||||
|
.replace(/&#x([0-9a-fA-F]+);/g, (_, h) => String.fromCharCode(parseInt(h, 16)))
|
||||||
|
.replace(/ /g, ' ')
|
||||||
|
}
|
||||||
|
|
||||||
export function parseRssItems(xml, limit = Infinity) {
|
export function parseRssItems(xml, limit = Infinity) {
|
||||||
const items = []
|
const items = []
|
||||||
const itemRegex = /<item>([\s\S]*?)<\/item>/g
|
const itemRegex = /<item>([\s\S]*?)<\/item>/g
|
||||||
@@ -22,7 +35,7 @@ export function parseRssItems(xml, limit = Infinity) {
|
|||||||
const enclosureUrl = /<enclosure[^>]+url="([^"]+)"/.exec(block)?.[1] ?? ''
|
const enclosureUrl = /<enclosure[^>]+url="([^"]+)"/.exec(block)?.[1] ?? ''
|
||||||
const link = guid.startsWith('http') ? guid : enclosureUrl
|
const link = guid.startsWith('http') ? guid : enclosureUrl
|
||||||
const descRaw = /<description>([\s\S]*?)<\/description>/.exec(block)?.[1] ?? ''
|
const descRaw = /<description>([\s\S]*?)<\/description>/.exec(block)?.[1] ?? ''
|
||||||
const descText = extractCdata(descRaw).replace(/<[^>]+>/g, '').replace(/\s+/g, ' ').trim()
|
const descText = decodeEntities(extractCdata(descRaw).replace(/<[^>]+>/g, '')).replace(/\s+/g, ' ').trim()
|
||||||
const duration = (/<itunes:duration>([\s\S]*?)<\/itunes:duration>/.exec(block)?.[1] ?? '').trim()
|
const duration = (/<itunes:duration>([\s\S]*?)<\/itunes:duration>/.exec(block)?.[1] ?? '').trim()
|
||||||
const episode = (/<itunes:episode>([\s\S]*?)<\/itunes:episode>/.exec(block)?.[1] ?? '').trim()
|
const episode = (/<itunes:episode>([\s\S]*?)<\/itunes:episode>/.exec(block)?.[1] ?? '').trim()
|
||||||
const season = (/<itunes:season>([\s\S]*?)<\/itunes:season>/.exec(block)?.[1] ?? '').trim()
|
const season = (/<itunes:season>([\s\S]*?)<\/itunes:season>/.exec(block)?.[1] ?? '').trim()
|
||||||
|
|||||||
Reference in new issue
Block a user