Compare commits

...

2 commits

5 changed files with 74 additions and 1 deletions

10
src/blogs/hello_world.md Normal file
View file

@ -0,0 +1,10 @@
---
title: 'Наш первый блог'
thumbnail: 'wasd_perelesoq_game_jam_2025.png'
date: '2025-09-19'
description: 'Немного о самом сайте'
---
# ПРИВЕТ !
Добро пожаловать на наш первый блог-пост!

30
src/lib/util/Blogs.ts Normal file
View file

@ -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;
};

View file

@ -45,7 +45,7 @@ function getIconFromUrl(url: URL): string | undefined {
const href = url.href; const href = url.href;
if (href.startsWith('mailto:')) if (href.startsWith('mailto:'))
return 'email'; return 'email';
if (href.endsWith('/rss.xml')) if (href.endsWith('/rss.xml') || href.endsWith('/atom.rss'))
return 'rss'; return 'rss';
const hostname = url.hostname; const hostname = url.hostname;

View file

@ -0,0 +1,33 @@
import { fetchPostsSorted } from "$src/lib/util/Blogs";
function escapeXml(unsafe: string): string {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&apos;");
}
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(`<?xml version="1.0" encoding="UTF-8" ?>
<rss xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:atom="https://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>Блог Tea Sanctuary</title>
<link>https://teasanctuary.ru/blog</link>
<ttl>1800</ttl>
${posts.map((post) => `<item>
<title>${escapeXml(post.title)}</title>
<description>${escapeXml(post.description)}</description>
<guid isPermaLink="true">https://teasanctuary.ru/blog/${post.slug}</guid>
<link>https://teasanctuary.ru/blog/${post.slug}</link>
<pubDate>${(new Date(post.date)).toUTCString()}</pubDate>
</item>`).join("\n")}
</channel>
</rss>`))
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 KiB