diff --git a/src/lib/Commit.svelte b/src/lib/Commit.svelte index bd88201..67f8c26 100644 --- a/src/lib/Commit.svelte +++ b/src/lib/Commit.svelte @@ -1,24 +1,21 @@ -
-
- {@html title} + + {@html title} - {pubAgo} +
+ {#if description} +

with the message:

+ {description} + {/if} + view commit
-
- {@html description} -
-
commited {pubAgo} by {@html author}
- view commit -
guid:{guid}
-
+ diff --git a/src/lib/RssContainer.svelte b/src/lib/RssContainer.svelte index 929b585..9eda466 100644 --- a/src/lib/RssContainer.svelte +++ b/src/lib/RssContainer.svelte @@ -4,6 +4,6 @@
-

Here are the last 5 commits:

+

Here are the 5 most recent commits

diff --git a/src/lib/RssFeed.svelte b/src/lib/RssFeed.svelte index c34ee93..ca2807c 100644 --- a/src/lib/RssFeed.svelte +++ b/src/lib/RssFeed.svelte @@ -2,13 +2,14 @@ import { onMount } from 'svelte'; import Spinner from './Spinner.svelte'; import Commit from './Commit.svelte'; + import { Accordion } from 'flowbite-svelte'; export let url; let feed = null; let error = null; - async function fetchFeed() { + async function fetchFeed(url) { try { const response = await fetch(url); if (!response.ok) { @@ -17,14 +18,32 @@ 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, - published: item.querySelector('pubDate')?.textContent, - author: item.querySelector('author')?.textContent, - guid: item.querySelector('guid')?.textContent - })); + + const items = Array.from(xml.querySelectorAll('item')).map((item) => { + // Parse description + const descriptionElement = item.querySelector('description'); + const descriptionContent = descriptionElement ? descriptionElement.textContent : ''; + const tempDivDescription = document.createElement('div'); + tempDivDescription.innerHTML = descriptionContent; + const firstLinkDescription = tempDivDescription.querySelector('a') + ? tempDivDescription.querySelector('a').href + : ''; + if (tempDivDescription.querySelector('a')) { + tempDivDescription.querySelector('a').remove(); + } + const cleanedDescription = tempDivDescription.innerHTML.trim(); + + return { + title: item.querySelector('title')?.textContent, + description: cleanedDescription, + commit: firstLinkDescription, + link: item.querySelector('link')?.textContent, + published: item.querySelector('pubDate')?.textContent, + author: item.querySelector('author')?.textContent, + guid: item.querySelector('guid')?.textContent + }; + }); + feed = items; } catch (err) { error = err.message; @@ -32,7 +51,7 @@ } onMount(() => { - fetchFeed(); + fetchFeed(url); }); @@ -43,9 +62,15 @@ {:else}
- {#each feed.slice(0, 5) as commit} - - {/each} + + {#each feed.slice(0, 5) as commit, i} + {#if i === 0} + + {:else} + + {/if} + {/each} +
{/if}