π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
β Remove rss-parser, wrote own with native DOMParser
Alicia Sykes15d836048742
diff --git a/package.json b/package.jsonindex e4a8099a..1191a646 100644--- a/package.json+++ b/package.json@@ -50,7 +50,6 @@"oidc-client-ts": "^3.0.1","register-service-worker": "^1.7.2","remedial": "^1.0.8",- "rss-parser": "3.13.0","rsup-progress": "^3.2.0","simple-icons": "^16.6.0","vue": "^3.5.0",diff --git a/src/components/Widgets/RssFeed.vue b/src/components/Widgets/RssFeed.vueindex 0923c463..b25925f2 100644--- a/src/components/Widgets/RssFeed.vue+++ b/src/components/Widgets/RssFeed.vue@@ -51,9 +51,9 @@</template><script>-import * as Parser from 'rss-parser';import WidgetMixin from '@/mixins/WidgetMixin';import { widgetApiEndpoints } from '@/utils/config/defaults';+import { parseRssFeed } from '@/utils/RssParser';import { sanitizeRssItem, sanitizeRssMeta } from '@/utils/Sanitizer';export default {@@ -124,12 +124,18 @@ export default {this.makeRequest(this.endpoint).then(this.processData);},/* Assign data variables to the returned data */- async processData(data) {+ processData(data) {if (this.parseLocally) {- const parser = new Parser();+ let parsed;+ try {+ parsed = parseRssFeed(data);+ } catch (err) {+ this.error('Failed to parse RSS feed', err);+ return;+ }const {link, title, items, author, description, image,- } = await parser.parseString(data);+ } = parsed;this.meta = sanitizeRssMeta({title,link,@@ -221,7 +227,7 @@ export default {}img.post-img {border-radius: var(--curve-factor);- width: 2rem;+ max-width: 8rem;height: 2rem;margin-right: 0.5rem;}@@ -231,6 +237,7 @@ export default {color: var(--widget-text-color);max-height: 400px;overflow: hidden;+ margin-top: 0.5rem;:deep(p) {margin: 0.5rem 0;}diff --git a/src/utils/RssParser.js b/src/utils/RssParser.jsnew file mode 100644index 00000000..f4d04913--- /dev/null+++ b/src/utils/RssParser.js@@ -0,0 +1,86 @@+/**+ * Minimal RSS 2.0 / Atom 1.0 parser using the browser's native DOMParser.+ * Returns `{ title, link, description, image, author, items }` in a shape+ * compatible with `sanitizeRssMeta` and `sanitizeRssItem`.+ */++const childByName = (el, name) => (+ el ? Array.from(el.children).find((c) => c.localName === name) : null+);++const childrenByName = (el, name) => (+ el ? Array.from(el.children).filter((c) => c.localName === name) : []+);++const childText = (el, name) => childByName(el, name)?.textContent?.trim() || '';++const atomLink = (el) => {+ const links = childrenByName(el, 'link');+ const alt = links.find((l) => l.getAttribute('rel') === 'alternate') || links[0];+ return alt?.getAttribute('href') || '';+};++const parseAtomItem = (el) => {+ const author = childByName(el, 'author');+ const thumb = childByName(el, 'thumbnail') || childByName(el, 'content');+ return {+ title: childText(el, 'title'),+ link: atomLink(el),+ description: childText(el, 'content') || childText(el, 'summary'),+ pubDate: childText(el, 'published') || childText(el, 'updated'),+ author: author ? childText(author, 'name') : '',+ thumbnail: thumb?.getAttribute('url') || '',+ };+};++const parseRssItem = (el) => {+ const enclosure = childByName(el, 'enclosure');+ const thumb = childByName(el, 'thumbnail');+ return {+ title: childText(el, 'title'),+ link: childText(el, 'link'),+ description: childText(el, 'encoded') || childText(el, 'description'),+ pubDate: childText(el, 'pubDate'),+ author: childText(el, 'creator') || childText(el, 'author'),+ thumbnail: thumb?.getAttribute('url') || enclosure?.getAttribute('url') || '',+ };+};++export const parseRssFeed = (xml) => {+ if (!xml || typeof xml !== 'string') throw new Error('Empty feed response');++ const doc = new DOMParser().parseFromString(xml, 'text/xml');+ if (doc.querySelector('parsererror')) throw new Error('Invalid feed XML');++ const root = doc.documentElement;+ const isAtom = root.localName === 'feed';+ const channel = isAtom ? root : childByName(root, 'channel');+ if (!channel) throw new Error('Unrecognized feed format');++ const meta = isAtom+ ? {+ title: childText(channel, 'title'),+ link: atomLink(channel),+ description: childText(channel, 'subtitle'),+ image: childText(channel, 'logo') || childText(channel, 'icon'),+ author: (() => {+ const a = childByName(channel, 'author');+ return a ? childText(a, 'name') : '';+ })(),+ }+ : {+ title: childText(channel, 'title'),+ link: childText(channel, 'link'),+ description: childText(channel, 'description'),+ image: (() => {+ const img = childByName(channel, 'image');+ return img ? childText(img, 'url') : '';+ })(),+ author: childText(channel, 'managingEditor') || childText(channel, 'author'),+ };++ const itemEls = childrenByName(channel, isAtom ? 'entry' : 'item');+ const items = itemEls.map(isAtom ? parseAtomItem : parseRssItem);++ return { ...meta, items };+};diff --git a/yarn.lock b/yarn.lockindex 889e11d8..8b940663 100644--- a/yarn.lock+++ b/yarn.lock@@ -2633,11 +2633,6 @@ encodeurl@~2.0.0:resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-2.0.0.tgz#7b8ea898077d7e409d3ac45474ea38eaf0857a58"integrity sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==-entities@^2.0.3:- version "2.2.0"- resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"- integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==-entities@^4.2.0:version "4.5.0"resolved "https://registry.yarnpkg.com/entities/-/entities-4.5.0.tgz#5d268ea5e7113ec74c4d033b79ea5a35a488fb48"@@ -4535,14 +4530,6 @@ rollup@^4.34.9:"@rollup/rollup-win32-x64-msvc" "4.60.1"fsevents "~2.3.2"- version "3.13.0"- resolved "https://registry.yarnpkg.com/rss-parser/-/rss-parser-3.13.0.tgz#f1f83b0a85166b8310ec531da6fbaa53ff0f50f0"- integrity sha512-7jWUBV5yGN3rqMMj7CZufl/291QAhvrrGpDNE4k/02ZchL0npisiYYqULF71jCEKoIiHvK/Q2e6IkDwPziT7+w==- dependencies:- entities "^2.0.3"- xml2js "^0.5.0"-rsup-progress@^3.2.0:version "3.2.0"resolved "https://registry.yarnpkg.com/rsup-progress/-/rsup-progress-3.2.0.tgz#f9f3fa3158b8ced9dace14f33f4e9157717b5837"@@ -4609,7 +4596,7 @@ sass@^1.77.0:optionalDependencies:"@parcel/watcher" "^2.4.1"-sax@>=0.6.0, sax@^1.5.0:+sax@^1.5.0:version "1.6.0"resolved "https://registry.yarnpkg.com/sax/-/sax-1.6.0.tgz#da59637629307b97e7c4cb28e080a7bc38560d5b"integrity sha512-6R3J5M4AcbtLUdZmRv2SygeVaM7IhrLXu9BmnOGmmACak8fiUtOsYNWUS4uK7upbmHIBbLBeFeI//477BKLBzA==@@ -5743,19 +5730,6 @@ xml-name-validator@^4.0.0:resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-4.0.0.tgz#79a006e2e63149a8600f15430f0a4725d1524835"integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==-xml2js@^0.5.0:- version "0.5.0"- resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.5.0.tgz#d9440631fbb2ed800203fad106f2724f62c493b7"- integrity sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==- dependencies:- sax ">=0.6.0"- xmlbuilder "~11.0.0"--xmlbuilder@~11.0.0:- version "11.0.1"- resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"- integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==-yallist@^3.0.2:version "3.1.1"resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"