Some checks failed
Vercel Preview Deployment / Deploy-Preview (push) Failing after 1m9s
Todo: - break into components and style - get time of commit - convert time of commit to __time since__
49 lines
1.1 KiB
Svelte
49 lines
1.1 KiB
Svelte
<script>
|
|
import { onMount } from 'svelte';
|
|
|
|
const url = 'https://gitea.rannes.dev/rannes.dev/my-portfolio.rss';
|
|
|
|
let feed = null;
|
|
let error = null;
|
|
|
|
async function fetchFeed() {
|
|
try {
|
|
const response = await fetch(url);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
const text = await response.text();
|
|
const parser = new DOMParser();
|
|
const xml = parser.parseFromString(text, 'application/xml');
|
|
const items = Array.from(xml.querySelectorAll('item')).map((item) => ({
|
|
title: item.querySelector('title')?.textContent,
|
|
link: item.querySelector('link')?.textContent,
|
|
description: item.querySelector('description')?.textContent
|
|
}));
|
|
feed = items;
|
|
} catch (err) {
|
|
error = err.message;
|
|
}
|
|
}
|
|
|
|
onMount(() => {
|
|
fetchFeed();
|
|
});
|
|
</script>
|
|
|
|
{#if error}
|
|
<p>Error: {error}</p>
|
|
{:else if !feed}
|
|
<p>Loading...</p>
|
|
{:else}
|
|
<div>
|
|
{#each feed.slice(0, 5) as item}
|
|
<div>
|
|
<h3>{@html item.title}</h3>
|
|
<p>{@html item.description}</p>
|
|
<a href={item.link} target="_blank">Read more</a>
|
|
</div>
|
|
{/each}
|
|
</div>
|
|
{/if}
|