Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Data import issue for RSS in Svelte

$
0
0

novice here, trying to experiment with showing my blog and have managed to get an RSS feed in VS code terminal on a page.server.js however can't figure out how to use it.

Here's the code: In data.js

import fetch from 'node-fetch';import { parseStringPromise } from 'xml2js';export async function fetchRSSFeed(url) {    const response = await fetch(url);    const rssText = await response.text();    const parsedResult = await parseStringPromise(rssText);    const items = parsedResult.rss.channel[0].item;    return items.map(item => ({        title: item.title[0],        link: item.link[0]    }));}

In +page.server.js

import { fetchRSSFeed } from './data.js';export async function load() {        const rssFeedUrl = 'myBlog';        const articles = await fetchRSSFeed(rssFeedUrl);        console.log(articles);    return {        props: {            articles        }    };}

and here's the +page.svelte

<script>        export let articles = [];        console.log("Why are there no articles???", articles);</script><div id="container"><div class="about"><p>thoughts available on substack</p></div><section><h2>recent posts</h2><hr /><div class="posts">        {#each articles as { title, link }}<a href={link} target="_blank"><div class="post"><h3>{title}</h3></div></a>        {/each}</div></section></div>    

Thanks in advance, big love x

I'd like to make an RSS feed in Svelte, I've tried adding the data.js as an extra route


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>