From 166f3fc9af6e6c829dafaec656cd5278ea42337d Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 3 Jun 2022 16:26:31 +0200 Subject: [PATCH] RSS --- .../home-tab/src/lib/components/rssFeed.css | 12 ++++++ .../home-tab/src/lib/components/rssFeed.tsx | 42 +++++++++++++++++++ .../home-tab/src/lib/remix-ui-home-tab.tsx | 20 +-------- package.json | 1 + 4 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 libs/remix-ui/home-tab/src/lib/components/rssFeed.css create mode 100644 libs/remix-ui/home-tab/src/lib/components/rssFeed.tsx diff --git a/libs/remix-ui/home-tab/src/lib/components/rssFeed.css b/libs/remix-ui/home-tab/src/lib/components/rssFeed.css new file mode 100644 index 0000000000..22e231c0e0 --- /dev/null +++ b/libs/remix-ui/home-tab/src/lib/components/rssFeed.css @@ -0,0 +1,12 @@ +.RSSFeed-item img { + width: 100%; +} + +.RSSFeed-item .truncate { + max-height: 500px; + overflow: hidden; +} + +.RSSFeed-item .more-button { + +} \ No newline at end of file diff --git a/libs/remix-ui/home-tab/src/lib/components/rssFeed.tsx b/libs/remix-ui/home-tab/src/lib/components/rssFeed.tsx new file mode 100644 index 0000000000..d616f1e915 --- /dev/null +++ b/libs/remix-ui/home-tab/src/lib/components/rssFeed.tsx @@ -0,0 +1,42 @@ +import React, { useState, useEffect } from "react"; +import Parser from "rss-parser"; +import './RssFeed.css'; + +interface RSSFeedProps { + feedUrl: string, + maxItems: number, +} + +export function RSSFeed({ feedUrl, maxItems }: RSSFeedProps) { + const [feed, setFeed] = useState(null); + + useEffect(() => { + const fetchData = async () => { + let parser = new Parser() + let feed = await parser.parseURL(feedUrl); + for (const item of feed.items) { + item.content = item['content:encoded'] + item.date = new Date(item.pubDate).toLocaleDateString('en-US', { + month: 'short', + day: 'numeric' + }) + } + setFeed(feed); + }; + fetchData(); + }, [feedUrl]); + + + return (<> + {feed && feed.items.slice(0, maxItems).map((item: any, index: any) => ( +
+

{item.title}

+

Author: {item.creator}

+

{item.date}

+
+ READ MORE +
+
+ ))} + ) +} \ No newline at end of file diff --git a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx index a35f1f1b7e..ba1e10e1a5 100644 --- a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx +++ b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx @@ -5,6 +5,7 @@ import { ModalDialog } from '@remix-ui/modal-dialog' // eslint-disable-line import { Toaster } from '@remix-ui/toaster' // eslint-disable-line import PluginButton from './components/pluginButton' // eslint-disable-line import { ThemeContext, themes } from './themeContext' +import { RSSFeed } from './components/rssFeed' declare global { interface Window { _paq: any @@ -107,15 +108,8 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => { scriptTwitter.src = 'https://platform.twitter.com/widgets.js' scriptTwitter.async = true document.body.appendChild(scriptTwitter) - // to retrieve medium publications - const scriptMedium = document.createElement('script') - scriptMedium.src = 'https://www.twilik.com/assets/retainable/rss-embed/retainable-rss-embed.js' - scriptMedium.async = true - // script causes a bug in the editor and prevents syntax error detection - // document.body.appendChild(scriptMedium) return () => { document.body.removeChild(scriptTwitter) - document.body.removeChild(scriptMedium) } }, []) @@ -342,17 +336,7 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => { >