-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme-demo): first draft implementation of pages plugin support
Related to #109
- Loading branch information
Showing
9 changed files
with
118 additions
and
4 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,7 +1,7 @@ | ||
import { Theme } from 'typedoc'; | ||
|
||
export interface IReadmePluginTheme extends Theme { | ||
monorepoReadmesPlugin: true; | ||
monorepoReadmesPlugin: boolean; | ||
} | ||
|
||
export const isMonorepoReadmesPluginTheme = ( theme: Theme ): theme is IReadmePluginTheme => 'monorepoReadmesPlugin' in theme && ( theme as any ).monorepoReadmesPlugin; | ||
export const isMonorepoReadmesPluginTheme = ( theme: Theme ): theme is IReadmePluginTheme => 'monorepoReadmesPlugin' in theme && ( theme as any ).monorepoReadmesPlugin === true; |
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 +1,7 @@ | ||
export const STUB = ''; | ||
import { Application } from 'typedoc'; | ||
|
||
import { KnodesPluginsDemoTheme } from './thene/knodes-plugins-demo-theme'; | ||
|
||
export const load = ( application: Application ) => { | ||
application.renderer.defineTheme( 'knodes-plugins-theme-demo', KnodesPluginsDemoTheme ); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/theme-demo/src/thene/knodes-plugins-demo-theme-context.ts
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DefaultThemeRenderContext, Options } from 'typedoc'; | ||
|
||
import type { KnodesPluginsDemoTheme } from './knodes-plugins-demo-theme'; | ||
import { navigation } from './partials/navigation'; | ||
import { renderPageLink } from './partials/plugin-pages/page-link'; | ||
import { pagesNavigation } from './partials/plugin-pages/pages-navigation'; | ||
|
||
export class KnodesPluginsDemoThemeContext extends DefaultThemeRenderContext { | ||
public pagesPlugin = { | ||
pagesNavigation: pagesNavigation( this ), | ||
renderPageLink: renderPageLink( this ), | ||
}; | ||
|
||
// public codeBlocksPlugin: ICodeBlocksPluginThemeMethods = {}; | ||
|
||
public constructor( theme: KnodesPluginsDemoTheme, options: Options ) { | ||
super( theme, options ); | ||
|
||
this.navigation = navigation( this ); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/theme-demo/src/thene/knodes-plugins-demo-theme.ts
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { DefaultTheme, Renderer, RendererEvent } from 'typedoc'; | ||
|
||
import type { ICodeBlocksPluginTheme, ICodeBlocksPluginThemeMethods } from '@knodes/typedoc-plugin-code-blocks'; | ||
import type { IReadmePluginTheme } from '@knodes/typedoc-plugin-monorepo-readmes'; | ||
import type { IPagesPluginTheme, IPagesPluginThemeMethods } from '@knodes/typedoc-plugin-pages'; | ||
|
||
import { KnodesPluginsDemoThemeContext } from './knodes-plugins-demo-theme-context'; | ||
|
||
export class KnodesPluginsDemoTheme extends DefaultTheme implements IPagesPluginTheme, ICodeBlocksPluginTheme, IReadmePluginTheme { | ||
public readonly monorepoReadmesPlugin = true as const; | ||
private _contextCache?: KnodesPluginsDemoThemeContext; | ||
|
||
public constructor( renderer: Renderer ) { | ||
super( renderer ); | ||
} | ||
|
||
/** | ||
* Return the plugin methods. | ||
* This method is called when `@knodes/typedoc-plugin=pages` will start rendering. | ||
* You might do some initialization here, like copying specific assets, or post-processing the pages tree. | ||
* | ||
* @param _event - The renderer event. | ||
* @returns the plugin rendering methods for this theme. | ||
*/ | ||
public pagesPlugin( _event: RendererEvent ): IPagesPluginThemeMethods { | ||
return this.getRenderContext().pagesPlugin; | ||
} | ||
|
||
/** | ||
* Return the plugin methods. | ||
* | ||
* @param _event - The renderer event. | ||
* @returns the plugin rendering methods for this theme. | ||
*/ | ||
public codeBlocksPlugin( _event: RendererEvent ): ICodeBlocksPluginThemeMethods { | ||
throw new Error( 'Method not implemented.' ); | ||
return {} as any; | ||
} | ||
|
||
/** | ||
* Obtain the stored instance of context. | ||
* | ||
* @returns the theme context. | ||
*/ | ||
public override getRenderContext(): KnodesPluginsDemoThemeContext { | ||
this._contextCache = this._contextCache ?? | ||
new KnodesPluginsDemoThemeContext( this, this.application.options ) ; | ||
|
||
return this._contextCache; | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { JSX, PageEvent, Reflection } from 'typedoc'; | ||
|
||
import type { KnodesPluginsDemoThemeContext } from '../knodes-plugins-demo-theme-context'; | ||
|
||
export const navigation = ( context: KnodesPluginsDemoThemeContext ) => ( props: PageEvent<Reflection> ): JSX.Element => | ||
<> | ||
{context.settings()} | ||
{context.pagesPlugin.pagesNavigation( props )} | ||
{context.primaryNavigation( props )} | ||
{context.secondaryNavigation( props )} | ||
</>; |
9 changes: 9 additions & 0 deletions
9
packages/theme-demo/src/thene/partials/plugin-pages/page-link.tsx
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { JSX } from 'typedoc'; | ||
|
||
import type { RenderPageLinkProps } from '@knodes/typedoc-plugin-pages'; | ||
|
||
import type { KnodesPluginsDemoThemeContext } from '../../knodes-plugins-demo-theme-context'; | ||
|
||
export const renderPageLink = ( _ctx: KnodesPluginsDemoThemeContext ) => ( _props: RenderPageLinkProps ): JSX.Element => <> | ||
TODO | ||
</>; |
Empty file.
7 changes: 7 additions & 0 deletions
7
packages/theme-demo/src/thene/partials/plugin-pages/pages-navigation.tsx
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { JSX, PageEvent, Reflection } from 'typedoc'; | ||
|
||
import type { KnodesPluginsDemoThemeContext } from '../../knodes-plugins-demo-theme-context'; | ||
|
||
export const pagesNavigation = ( _ctx: KnodesPluginsDemoThemeContext ) => ( _props: PageEvent<Reflection> ): JSX.Element => <> | ||
TODO | ||
</>; |