Skip to content

Commit 707d93f

Browse files
committed
wip: basic blog
1 parent fcc2b1a commit 707d93f

File tree

16 files changed

+234
-40
lines changed

16 files changed

+234
-40
lines changed

src/app.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// See https://kit.svelte.dev/docs/types#app
22
// for information about these interfaces
33
// and what to do when importing types
4-
declare namespace App {
4+
export declare namespace App {
55
// interface Locals {}
66
// interface PageData {}
77
// interface Error {}

src/app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="en" class="dark">
33
<!--suppress HtmlRequiredTitleElement -->
44
<head>
55
<meta charset="utf-8" />

src/components/base/NavBar.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
mode?: 'startswith' | 'exact';
1111
}[] = [
1212
{ label: 'Home', to: '/', mode: 'exact' },
13-
{ label: 'Art', to: '/art' }
13+
{ label: 'Art', to: '/art' },
14+
{ label: 'Blog', to: '/blog' }
1415
];
1516
</script>
1617

src/lib/data/blog/tests.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: Test
3+
description: This is a test post, there's nothing to see here.
4+
date: 2019-01-01
5+
---
6+
7+
# Hey!
8+
9+
This is a test!
10+
11+
**This is bold!**
12+
*This is italic!*
13+
14+
This is a link to [Google](https://google.com)
15+
16+
This is a code block:
17+
18+
```js
19+
console.log('Hello World!');
20+
```
21+
22+
This is a list:
23+
24+
- Item 1
25+
- Item 2
26+
- Item 3
27+
28+
This is a numbered list:
29+
30+
1. Item 1
31+
2. Item 2
32+
3. Item 3
33+
34+
This is a table:
35+
36+
| Column 1 | Column 2 | Column 3 |
37+
| -------- | -------- | -------- |
38+
| Item 1 | Item 2 | Item 3 |
39+
| Item 4 | Item 5 | Item 6 |
40+
41+
This is a quote:
42+
43+
> This is a quote!
44+
45+
This is an image:
46+
47+
![Image](https://i.imgur.com/1Q9ZQ9A.png)
48+
49+
This is a horizontal rule:
50+
51+
---

src/lib/types/blog.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { SvelteComponent } from 'svelte';
2+
3+
/**
4+
* A post which has been imported from a file using import.meta.glob.
5+
*/
6+
export interface PostFile {
7+
default: SvelteComponent;
8+
metadata: {
9+
title: string;
10+
description?: string;
11+
date: string;
12+
tags?: string[];
13+
};
14+
}
15+
16+
/**
17+
* GET /api/blog/posts
18+
*/
19+
export type BlogPostsGet = {
20+
slug: string;
21+
metadata: PostFile['metadata'];
22+
}[];

src/lib/util/blog.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Returns the slug from a path
3+
*
4+
* @param path The path to get the slug from
5+
* @returns The slug
6+
*/
7+
export const getSlug = (path: string): string | undefined => path.split('/').pop()?.split('.').shift();

src/lib/util/notion.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/routes/+layout.svelte

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<script lang="ts">
2-
// Layout
2+
import { navigating } from '$app/stores';
33
import Footer from '$components/base/Footer.svelte';
44
import GradientCanvas from '$components/base/GradientCanvas.svelte';
55
import NavBar from '$components/base/NavBar.svelte';
6-
7-
// Styling
8-
import '../app.postcss';
9-
10-
// Navigation
11-
import { navigating } from '$app/stores';
126
import NProgress from 'nprogress';
137
import 'nprogress/nprogress.css';
8+
import { fade } from 'svelte/transition';
9+
import '../app.postcss';
10+
import type { PageData } from './$types';
11+
12+
export let data: PageData;
1413
1514
NProgress.configure({
1615
showSpinner: false,
@@ -35,7 +34,11 @@
3534
<GradientCanvas />
3635
</div>
3736

38-
<slot />
37+
{#key data.pathname}
38+
<div in:fade={{ duration: 250, delay: 250 }} out:fade={{ duration: 250 }}>
39+
<slot />
40+
</div>
41+
{/key}
3942
</div>
4043

4144
<div class="px-8 pb-8">

src/routes/+layout.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { LayoutLoad } from './$types';
22

3+
/*
4+
* Always provide the pathname to the layout, so that it can
5+
* be used to determine which page is active
6+
*/
37
export const load: LayoutLoad = async ({ url: { pathname } }) => {
48
return { pathname };
59
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { PostFile } from '$lib/types/blog';
2+
import { getSlug } from '$lib/util/blog';
3+
import { json } from '@sveltejs/kit';
4+
import type { RequestHandler } from './$types';
5+
6+
export const GET: RequestHandler = async () => {
7+
// List all posts
8+
const posts = import.meta.glob<PostFile>('/src/lib/data/blog/*.md');
9+
10+
// Map the posts
11+
const postList = Object.entries(posts).map(async ([path, resolver]) => {
12+
// Get the slug
13+
const slug = getSlug(path);
14+
15+
// Load the post
16+
const post = await resolver();
17+
18+
// Return the post
19+
return {
20+
slug,
21+
metadata: post.metadata
22+
};
23+
});
24+
25+
// Return the list of posts
26+
return json(await Promise.all(postList));
27+
};

0 commit comments

Comments
 (0)