|
1 | | -import { base } from '$app/paths'; |
2 | | -import type { AuthorData } from '$markdoc/layouts/Author.svelte'; |
3 | | -import type { CategoryData } from '$markdoc/layouts/Category.svelte'; |
4 | | -import type { PostsData } from '$markdoc/layouts/Post.svelte'; |
| 1 | +import { posts, authors, categories } from './content'; |
5 | 2 |
|
6 | 3 | export function load() { |
7 | | - const postsGlob = import.meta.glob('./post/**/*.markdoc', { |
8 | | - eager: true |
9 | | - }); |
10 | | - const authorsGlob = import.meta.glob('./author/**/*.markdoc', { |
11 | | - eager: true |
12 | | - }); |
13 | | - const categoriesGlob = import.meta.glob('./category/**/*.markdoc', { |
14 | | - eager: true |
15 | | - }); |
16 | | - |
17 | | - const posts = Object.entries(postsGlob) |
18 | | - .map(([filepath, postList]) => { |
19 | | - const { frontmatter } = postList as { |
20 | | - frontmatter: PostsData; |
21 | | - }; |
22 | | - const slug = filepath.replace('./', '').replace('/+page.markdoc', ''); |
23 | | - const postName = slug.slice(slug.lastIndexOf('/') + 1); |
24 | | - |
25 | | - return { |
26 | | - title: frontmatter.title, |
27 | | - description: frontmatter.description, |
28 | | - date: new Date(frontmatter.date), |
29 | | - cover: frontmatter.cover, |
30 | | - timeToRead: frontmatter.timeToRead, |
31 | | - author: frontmatter.author, |
32 | | - category: frontmatter.category, |
33 | | - href: `${base}/blog/post/${postName}` |
34 | | - }; |
35 | | - }) |
36 | | - .sort((a, b) => { |
37 | | - return b.date.getTime() - a.date.getTime(); |
38 | | - }); |
39 | | - |
40 | | - const authors = Object.values(authorsGlob).map((authorList) => { |
41 | | - const { frontmatter } = authorList as { |
42 | | - frontmatter: AuthorData; |
43 | | - }; |
44 | | - |
45 | | - return { |
46 | | - name: frontmatter.name, |
47 | | - slug: frontmatter.slug, |
48 | | - role: frontmatter.role, |
49 | | - avatar: frontmatter.avatar, |
50 | | - bio: frontmatter.bio, |
51 | | - twitter: frontmatter.twitter, |
52 | | - linkedin: frontmatter.linkedin, |
53 | | - github: frontmatter.github, |
54 | | - href: `${base}/blog/author/${frontmatter.slug}` |
55 | | - }; |
56 | | - }); |
57 | | - |
58 | | - const categories = Object.values(categoriesGlob).map((categoryList) => { |
59 | | - const { frontmatter } = categoryList as { |
60 | | - frontmatter: CategoryData; |
61 | | - }; |
62 | | - |
63 | | - return { |
64 | | - name: frontmatter.name, |
65 | | - description: frontmatter.description, |
66 | | - href: `${base}/blog/category/${frontmatter.name.toLowerCase()}` |
67 | | - }; |
68 | | - }); |
69 | | - |
70 | | - return { |
71 | | - posts, |
72 | | - authors, |
73 | | - categories |
74 | | - }; |
| 4 | + return { |
| 5 | + posts, |
| 6 | + authors, |
| 7 | + categories |
| 8 | + }; |
75 | 9 | } |
0 commit comments