summaryrefslogtreecommitdiff
path: root/src/lib/utils/posts.server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/utils/posts.server.ts')
-rw-r--r--src/lib/utils/posts.server.ts32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/lib/utils/posts.server.ts b/src/lib/utils/posts.server.ts
index a9b7bb9..9f34c1c 100644
--- a/src/lib/utils/posts.server.ts
+++ b/src/lib/utils/posts.server.ts
@@ -1,26 +1,28 @@
-import type { Post, PostMetadata } from './posts';
+import type { Post, PostMetadata } from "./posts";
-const postMetadataFiles = import.meta.glob<PostMetadata>('/src/posts/*.svx', {
- eager: true,
- import: 'metadata'
+const postMetadataFiles = import.meta.glob<PostMetadata>("/src/posts/*.svx", {
+ eager: true,
+ import: "metadata",
});
function getSlugFromPath(path: string): string {
- return path.split('/').pop()?.replace('.svx', '') ?? '';
+ return path.split("/").pop()?.replace(".svx", "") ?? "";
}
export function getPosts(): Post[] {
- const posts: Post[] = [];
+ const posts: Post[] = [];
- for (const path in postMetadataFiles) {
- const metadata = postMetadataFiles[path];
- const slug = getSlugFromPath(path);
+ for (const path in postMetadataFiles) {
+ const metadata = postMetadataFiles[path];
+ const slug = getSlugFromPath(path);
- posts.push({
- ...metadata,
- slug
- });
- }
+ posts.push({
+ ...metadata,
+ slug,
+ });
+ }
- return posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
+ return posts.sort(
+ (a, b) => new Date(b.date).getTime() - new Date(a.date).getTime(),
+ );
}