forked from harlan-zw/harlanzw.com
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Jan Petry
committed
Oct 6, 2023
1 parent
1b616b7
commit 99e10e0
Showing
3 changed files
with
43 additions
and
38 deletions.
There are no files selected for viewing
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,65 +1,60 @@ | ||
import { fetchContentNavigation, queryContent, useAsyncData } from '#imports' | ||
import { fetchContentNavigation, queryContent, useAsyncData } from "#imports"; | ||
import type { | ||
GeneralList, | ||
JsonParsedContent, | ||
Page, | ||
Post, | ||
ProjectList, | ||
} from '~/types' | ||
import { groupBy } from '~/logic' | ||
} from "~/types"; | ||
import { groupBy } from "~/logic"; | ||
|
||
export function useProjects() { | ||
return useAsyncData('content:projects', () => | ||
queryContent<JsonParsedContent<ProjectList>>('_projects').findOne()) | ||
return useAsyncData("content:projects", () => | ||
queryContent<JsonParsedContent<ProjectList>>("_projects").findOne() | ||
); | ||
} | ||
|
||
export function useGeneralList() { | ||
return useAsyncData('content:entrys', () => | ||
queryContent<JsonParsedContent<GeneralList>>('_partners').findOne()) | ||
} | ||
|
||
export function useGeneralList() { | ||
return useAsyncData('content:entrys', () => | ||
queryContent<JsonParsedContent<GeneralList>>('_partners').findOne(), | ||
) | ||
return useAsyncData("content:entrys", () => | ||
queryContent<JsonParsedContent<GeneralList>>("_partners").findOne() | ||
); | ||
} | ||
|
||
export function useHeaderNav() { | ||
return useAsyncData('content:navigation', () => fetchContentNavigation()) | ||
return useAsyncData("content:navigation", () => fetchContentNavigation()); | ||
} | ||
export function usePostList() { | ||
return useAsyncData( | ||
'content:post-partials', | ||
"content:post-partials", | ||
() => | ||
queryContent<Post>() | ||
.where({ _path: /blog\/*/ }) | ||
.without(['head', 'body', 'excerpt', '_']) | ||
.without(["head", "body", "excerpt", "_"]) | ||
.sort({ | ||
publishedAt: -1, | ||
}) | ||
.find(), | ||
{ | ||
// group posts by the publish year | ||
transform: posts => | ||
groupBy(posts, p => new Date(p.publishedAt).getFullYear()), | ||
}, | ||
) | ||
transform: (posts) => | ||
groupBy(posts, (p) => new Date(p.publishedAt).getFullYear()), | ||
} | ||
); | ||
} | ||
|
||
export function useRoutesContent<T extends Post>(path?: string) { | ||
if (!path) | ||
path = useRoute().path | ||
return useAsyncData(`content:${path}`, () => queryContent<T>() | ||
.where({ path: new RegExp(path) }) | ||
.without(['excerpt']) | ||
.findOne()) | ||
if (!path) path = useRoute().path; | ||
return useAsyncData(`content:${path}`, () => | ||
queryContent<T>() | ||
.where({ path: new RegExp(path) }) | ||
.without(["excerpt"]) | ||
.findOne() | ||
); | ||
} | ||
|
||
export const usePost = async (path?: string) => useRoutesContent<Post>(path) | ||
export const usePage = async (path?: string) => useRoutesContent<Page>(path) | ||
function | ||
// group posts by the publish year | ||
transform(input: Omit<Post, string>[]): {} { | ||
throw new Error('Function not implemented.') | ||
export const usePost = async (path?: string) => useRoutesContent<Post>(path); | ||
export const usePage = async (path?: string) => useRoutesContent<Page>(path); | ||
function // group posts by the publish year | ||
transform(input: Omit<Post, string>[]): {} { | ||
throw new Error("Function not implemented."); | ||
} | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.