Skip to content

Commit

Permalink
feat route context
Browse files Browse the repository at this point in the history
  • Loading branch information
OzakIOne committed May 16, 2024
1 parent 27a57d0 commit dee675c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ export function sortItems(params: ShowcaseItem[]): ShowcaseItem[] {

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',
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-content-showcase/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default async function pluginContentShowcase(
});
},

async contentLoaded({content, actions: {addRoute}}) {
async contentLoaded({content, actions: {addRoute, createData}}) {
if (!content) {
return;
}
Expand All @@ -92,6 +92,7 @@ export default async function pluginContentShowcase(
screenshotApi,
routeBasePath,
addRoute,
createData,
});
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ export async function processContentLoaded({
routeBasePath,
screenshotApi,
addRoute,
createData,
}: {
content: ShowcaseItems;
routeBasePath: string;
tags: TagsOption;
screenshotApi: string;
addRoute: PluginContentLoadedActions['addRoute'];
createData: PluginContentLoadedActions['createData'];
}): Promise<void> {
addRoute({
path: routeBasePath,
component: '@theme/Showcase',
props: {
items: content.items,
tags,
screenshotApi,
context: {
showcase: await createData('showcase.json', {
items: content.items,
tags,
screenshotApi,
}),
},
exact: true,
});
Expand Down
33 changes: 13 additions & 20 deletions packages/docusaurus-theme-classic/src/theme/Showcase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

import Translate, {translate} from '@docusaurus/Translate';
import Link from '@docusaurus/Link';
import {ShowcaseProvider} from '@docusaurus/theme-common/internal';
import Layout from '@theme/Layout';
import Heading from '@theme/Heading';
import ShowcaseSearchBar from '@theme/Showcase/ShowcaseSearchBar';
import ShowcaseCards from '@theme/Showcase/ShowcaseCards';
import ShowcaseFilters from '@theme/Showcase/ShowcaseFilters';
import type {Props} from '@theme/Showcase';

const TITLE = translate({message: 'Docusaurus Site Showcase'});
const DESCRIPTION = translate({
Expand All @@ -35,24 +33,19 @@ function ShowcaseHeader() {
);
}

export default function Showcase(props: Props): JSX.Element {
export default function Showcase(): JSX.Element {
return (
<ShowcaseProvider
items={props.items}
tags={props.tags}
screenshotApi={props.screenshotApi}>
<Layout title={TITLE} description={DESCRIPTION}>
<main className="margin-vert--lg">
<ShowcaseHeader />
<ShowcaseFilters />
<div
style={{display: 'flex', marginLeft: 'auto'}}
className="container">
<ShowcaseSearchBar />
</div>
<ShowcaseCards />
</main>
</Layout>
</ShowcaseProvider>
<Layout title={TITLE} description={DESCRIPTION}>
<main className="margin-vert--lg">
<ShowcaseHeader />
<ShowcaseFilters />
<div
style={{display: 'flex', marginLeft: 'auto'}}
className="container">
<ShowcaseSearchBar />
</div>
<ShowcaseCards />
</main>
</Layout>
);
}
38 changes: 0 additions & 38 deletions packages/docusaurus-theme-common/src/contexts/showcase.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/docusaurus-theme-common/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export {DocsVersionProvider, useDocsVersion} from './contexts/docsVersion';
export {DocsSidebarProvider, useDocsSidebar} from './contexts/docsSidebar';

export {DocProvider, useDoc, type DocContextValue} from './contexts/doc';
export {ShowcaseProvider} from './contexts/showcase';
export {
BlogPostProvider,
useBlogPost,
Expand Down

0 comments on commit dee675c

Please sign in to comment.