Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesrussell committed Jul 14, 2024
1 parent f0f3270 commit 6652b1b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
25 changes: 16 additions & 9 deletions src/routes/sections/WinBlog.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<script lang="ts">
import { onMount } from 'svelte';
import { blogPosts, fetchFeed } from '../../services/blogService';
import { onMount } from 'svelte';
import { blogPosts, fetchFeed } from '../../services/blogService';
import AppWindow from '../../components/AppWindow/AppWindow.svelte';
onMount(async () => {
const posts = await fetchFeed();
blogPosts.set(posts);
});
export let x: number;
export let y: number;
Expand All @@ -17,8 +12,20 @@
description: string;
}[] = [];
onMount(async () => {
posts = $blogPosts;
onMount(() => {
console.log('in onMount')
fetchFeed().then(fetchedPosts => {
posts = fetchedPosts;
});
let unsubscribe: () => void | undefined;
return () => {
console.log('in onMount return')
if (unsubscribe) {
console.log('unsubscribe')
unsubscribe();
}
};
});
</script>

Expand Down
28 changes: 18 additions & 10 deletions src/services/blogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ type Post = {
};

export async function fetchFeed() {
const response = await fetch('https://jonesrussell.github.io/blog/feed.xml');
const text = await response.text();
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'application/xml');
const items = Array.from(doc.querySelectorAll('item')).map((item) => ({
title: item.querySelector('title')?.textContent || '',
link: item.querySelector('link')?.textContent || '',
description: item.querySelector('description')?.textContent || ''
}));
return items;
console.log('Fetching feed...');
const response = await fetch('https://jonesrussell.github.io/blog/feed.xml');
console.log('Feed fetched:', response);
const text = await response.text();
console.log('Feed text:', text);
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'application/xml');
console.log('Parsed XML document:', doc);
const items = Array.from(doc.querySelectorAll('entry')).map((entry) => {
const title = entry.querySelector('title')?.textContent || '';
const link = entry.querySelector('link')?.getAttribute('href') || '';
const description = entry.querySelector('content,summary')?.textContent || '';
console.log('Processed entry:', { title, link, description });
return { title, link, description };
});
console.log('All entries processed:', items);
return items;
}


export const blogPosts = writable<Post[]>([]);

0 comments on commit 6652b1b

Please sign in to comment.