-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fea2a2c
commit 2bd9a49
Showing
3 changed files
with
8 additions
and
31 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,15 @@ | ||
import { getCollection } from "astro:content"; | ||
|
||
export const getCategories = async () => { | ||
const posts = await getCollection("blog"); | ||
const categories = [ | ||
...new Set(posts.map((post) => post.data.category).flat()), | ||
]; | ||
|
||
return categories; | ||
}; | ||
|
||
export const getPosts = async () => { | ||
const posts = (await getCollection("blog")).sort( | ||
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf(), | ||
); | ||
|
||
return posts; | ||
}; | ||
|
||
export const getPostsByCategory = async (category: string) => { | ||
const posts = (await getCollection("blog")) | ||
.filter((post) => post.data.category.includes(category)) | ||
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()); | ||
|
||
return posts; | ||
}; | ||
|
||
export const getGuides = async () => { | ||
const guides = (await getCollection("guides")) | ||
.filter((guide) => guide.data.published) | ||
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()); | ||
|
||
return guides; | ||
}; |