diff --git a/src/app.d.ts b/src/app.d.ts index f9281b5..98a2aa9 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -23,6 +23,7 @@ declare global { title: string; thumbnail?: string; date?: string; + dateChanged?: string; description: string; publisher: string; published?: boolean; diff --git a/src/blogs/test_unpublished.md b/src/blogs/test_unpublished.md index c932b19..a70c772 100644 --- a/src/blogs/test_unpublished.md +++ b/src/blogs/test_unpublished.md @@ -1,9 +1,13 @@ --- title: 'Тестовый блог' date: +dateChanged: '2025-09-29' description: 'Немного о самом сайте' +projects: ['ts-hldm'] --- # ПРИВЕТ ! -Добро пожаловать на наш первый блог-пост! \ No newline at end of file +Добро пожаловать на наш первый блог-пост! + + diff --git a/src/lib/components/Img.svelte b/src/lib/components/Img.svelte new file mode 100644 index 0000000..fd7de17 --- /dev/null +++ b/src/lib/components/Img.svelte @@ -0,0 +1,20 @@ + + +
+ {alt + {#if caption} +

{caption}

+ {/if} +
diff --git a/src/lib/components/InfoBlock.svelte b/src/lib/components/InfoBlock.svelte new file mode 100644 index 0000000..b93a76b --- /dev/null +++ b/src/lib/components/InfoBlock.svelte @@ -0,0 +1,13 @@ + + +
+
+ + Обратите внимание +
+
+ +
+
diff --git a/src/lib/util/Blogs.ts b/src/lib/util/Blogs.ts index 2e00ced..ad2d430 100644 --- a/src/lib/util/Blogs.ts +++ b/src/lib/util/Blogs.ts @@ -1,5 +1,7 @@ import path from 'path'; +export const THUMBNAIL_DEFAULT = "https://teasanctuary.ru/common/background-day.webp"; + export async function fetchPostsSorted() { const allPosts = await fetchPosts(); @@ -8,7 +10,7 @@ export async function fetchPostsSorted() { .filter((a) => !!a.date) .sort((a, b) => { return new Date(b.date!).valueOf() - new Date(a.date!).valueOf(); - }); + }); return sortedPosts; }; @@ -31,3 +33,11 @@ export async function fetchPosts() { return allPosts; }; + +export function resolveBlogPath(slug?: string, src?: string) { + if (!src) return null; + + return src.startsWith('http://') || src.startsWith('https://') + ? src + : `/blog/${slug}/${src}`; +} \ No newline at end of file diff --git a/src/routes/blog/+page.server.ts b/src/routes/blog/+page.server.ts new file mode 100644 index 0000000..c5653b5 --- /dev/null +++ b/src/routes/blog/+page.server.ts @@ -0,0 +1,5 @@ +import { fetchPostsSorted } from "$src/lib/util/Blogs"; + +export async function load() { + return { title: "Блог", description: "Новости и заметки проектов Tea Sanctuary", posts: await fetchPostsSorted() }; +} \ No newline at end of file diff --git a/src/routes/blog/+page.svelte b/src/routes/blog/+page.svelte index befbbfd..8156cdd 100644 --- a/src/routes/blog/+page.svelte +++ b/src/routes/blog/+page.svelte @@ -1,5 +1,25 @@
@@ -14,6 +34,63 @@
+ + Подпишитесь на нашу RSS ленту, чтобы не + пропускать новые посты! + + +
+ {#each groupedPosts.entries() as [monthYear, postsInMonthYear]} +

+ {monthYear} +

+
+ {#each postsInMonthYear as post, i} + +
+ {#if post.thumbnail} + thumbnail + {/if} +
+
+
+
+ +

+ {new Date(post.date!).toLocaleString('default', { + month: 'short', + day: 'numeric', + year: 'numeric' + })} +

+
+
+ +

{post.title}

+ + {#if post.description} +

{post.description}

+ {/if} +
+
+ {/each} +
+ {/each} +
+ diff --git a/src/routes/blog/[slug]/+page.svelte b/src/routes/blog/[slug]/+page.svelte new file mode 100644 index 0000000..f9a3fc8 --- /dev/null +++ b/src/routes/blog/[slug]/+page.svelte @@ -0,0 +1,90 @@ + + + + + + + + +
+
+
+

{data.blogPost.title}

+ {#if data.blogPost.description} +

{data.blogPost.description}

+ {/if} +
+
+
+
+
+ +

+ {data.blogPost.date + ? new Date(data.blogPost.date).toLocaleString(undefined, { + month: 'short', + day: 'numeric', + year: 'numeric' + }) + : 'Не опубликован!'} +

+
+ {#if data.blogPost.dateChanged} +
+ +

+ {new Date(data.blogPost.dateChanged).toLocaleString(undefined, { + month: 'short', + day: 'numeric', + year: 'numeric' + })} +

+
+ {/if} +
+ +{#if page.data.blogPost.projects?.length > 0} + +

В данной заметке упоминаются наши проекты:

+ +
+{/if} + +
+ +
+ + diff --git a/src/routes/blog/[slug]/+page.ts b/src/routes/blog/[slug]/+page.ts new file mode 100644 index 0000000..46b041c --- /dev/null +++ b/src/routes/blog/[slug]/+page.ts @@ -0,0 +1,23 @@ +import { resolveBlogPath, THUMBNAIL_DEFAULT } from "$src/lib/util/Blogs.js"; +import { error } from "@sveltejs/kit"; + +export async function load({ params }) { + let post: any + try { + post = await import(`$src/blogs/${params.slug}.md`); + } catch (ex) { + error(404); + } + const blogPost: App.BlogPost = post.metadata; + const thumbnail = resolveBlogPath(params.slug, blogPost.thumbnail ?? THUMBNAIL_DEFAULT); + + return { + title: `${blogPost.title} — Блог`, + description: blogPost.description, + thumbnail: thumbnail, + content: post.default, + blogPost: { + ...blogPost + } + }; +}; diff --git a/static/blogs/hello_world/wasd_perelesoq_game_jam_2025.png b/static/blog/hello_world/wasd_perelesoq_game_jam_2025.png similarity index 100% rename from static/blogs/hello_world/wasd_perelesoq_game_jam_2025.png rename to static/blog/hello_world/wasd_perelesoq_game_jam_2025.png diff --git a/static/blog/test_unpublished/wasd_perelesoq_game_jam_2025.png b/static/blog/test_unpublished/wasd_perelesoq_game_jam_2025.png new file mode 100644 index 0000000..dd59dc2 Binary files /dev/null and b/static/blog/test_unpublished/wasd_perelesoq_game_jam_2025.png differ diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..6d27e04 Binary files /dev/null and b/static/favicon.ico differ