diff --git a/src/blogs/hello_world.md b/src/blogs/hello_world.md new file mode 100644 index 0000000..0acb57f --- /dev/null +++ b/src/blogs/hello_world.md @@ -0,0 +1,10 @@ +--- +title: 'Наш первый блог' +thumbnail: 'wasd_perelesoq_game_jam_2025.png' +date: '2025-09-19' +description: 'Немного о самом сайте' +--- + +# ПРИВЕТ ! + +Добро пожаловать на наш первый блог-пост! \ No newline at end of file diff --git a/src/lib/util/Blogs.ts b/src/lib/util/Blogs.ts new file mode 100644 index 0000000..851992e --- /dev/null +++ b/src/lib/util/Blogs.ts @@ -0,0 +1,30 @@ +import path from 'path'; + +export async function fetchPostsSorted() { + const allPosts = await fetchPosts(); + + const sortedPosts = allPosts.sort((a, b) => { + return new Date(b.date).valueOf() - new Date(a.date).valueOf(); + }); + + return sortedPosts; +}; + +export async function fetchPosts() { + const allPostFiles = import.meta.glob('/src/blogs/*.md'); + const iterablePostFiles = Object.entries(allPostFiles); + + const allPosts: App.BlogPost[] = await Promise.all( + iterablePostFiles.map(async ([filePath, resolver]) => { + const { metadata }: any = await resolver(); + const { name } = path.parse(filePath); + + return { + slug: name, + ...metadata + }; + }) + ); + + return allPosts; +}; diff --git a/src/lib/util/LinkResolver.ts b/src/lib/util/LinkResolver.ts index 1f9c97d..2c1c796 100644 --- a/src/lib/util/LinkResolver.ts +++ b/src/lib/util/LinkResolver.ts @@ -45,7 +45,7 @@ function getIconFromUrl(url: URL): string | undefined { const href = url.href; if (href.startsWith('mailto:')) return 'email'; - if (href.endsWith('/rss.xml')) + if (href.endsWith('/rss.xml') || href.endsWith('/atom.rss')) return 'rss'; const hostname = url.hostname; diff --git a/src/routes/blog/rss.xml/+server.ts b/src/routes/blog/rss.xml/+server.ts new file mode 100644 index 0000000..0ed51da --- /dev/null +++ b/src/routes/blog/rss.xml/+server.ts @@ -0,0 +1,33 @@ +import { fetchPostsSorted } from "$src/lib/util/Blogs"; + +function escapeXml(unsafe: string): string { + return unsafe + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} + +export async function GET({ setHeaders }) { + setHeaders({ + 'Cache-Control': 'max-age=0, s-maxage=3600', + 'Content-Type': 'application/rss+xml', + }); + const posts = await fetchPostsSorted(); + return new Response(String(` + + +Блог Tea Sanctuary +https://teasanctuary.ru/blog +1800 +${posts.map((post) => ` +${escapeXml(post.title)} +${escapeXml(post.description)} +https://teasanctuary.ru/blog/${post.slug} +https://teasanctuary.ru/blog/${post.slug} +${(new Date(post.date)).toUTCString()} +`).join("\n")} + +`)) +} \ No newline at end of file diff --git a/static/blogs/hello_world/wasd_perelesoq_game_jam_2025.png b/static/blogs/hello_world/wasd_perelesoq_game_jam_2025.png new file mode 100644 index 0000000..dd59dc2 Binary files /dev/null and b/static/blogs/hello_world/wasd_perelesoq_game_jam_2025.png differ