mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-02 16:29:47 +02:00
wip routeContext
This commit is contained in:
parent
7e417aa77d
commit
8ad074773a
6 changed files with 63 additions and 98 deletions
|
@ -13,10 +13,12 @@ import {
|
|||
useQueryStringList,
|
||||
type ListUpdateFunction,
|
||||
} from '@docusaurus/theme-common';
|
||||
import useRouteContext from '@docusaurus/useRouteContext';
|
||||
import type {
|
||||
TagType,
|
||||
Operator,
|
||||
ShowcaseItem,
|
||||
TagsOption,
|
||||
} from '@docusaurus/plugin-content-showcase';
|
||||
|
||||
export function filterItems({
|
||||
|
@ -130,3 +132,34 @@ export function sortItems(params: ShowcaseItem[]): ShowcaseItem[] {
|
|||
result = sortBy(result, (user) => !user.tags.includes('favorite'));
|
||||
return result;
|
||||
}
|
||||
|
||||
export interface ShowcaseContextType {
|
||||
items: ShowcaseItem[];
|
||||
tags: TagsOption;
|
||||
screenshotApi: string;
|
||||
}
|
||||
|
||||
function useShowcase() {
|
||||
const routeContext = useRouteContext();
|
||||
console.log('routeContext:', routeContext);
|
||||
const showcase = routeContext?.data?.showcase;
|
||||
console.log('showcase:', showcase);
|
||||
if (!showcase) {
|
||||
throw new Error(
|
||||
'showcase-related hooks can only be called on the showcase page',
|
||||
);
|
||||
}
|
||||
return showcase as ShowcaseContextType;
|
||||
}
|
||||
|
||||
export function useShowcaseItems(): ShowcaseItem[] {
|
||||
return useShowcase().items;
|
||||
}
|
||||
|
||||
export function useShowcaseApiScreenshot(): string {
|
||||
return useShowcase().screenshotApi;
|
||||
}
|
||||
|
||||
export function useShowcaseTags(): TagsOption {
|
||||
return useShowcase().tags;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue