-
Notifications
You must be signed in to change notification settings - Fork 172
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
Showing
8 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Event, PageEvent, ProjectReflection } from 'typedoc'; | ||
|
||
export class MarkdownPageEvent<out Model = unknown> extends PageEvent { | ||
/** | ||
* The project the renderer is currently processing. | ||
*/ | ||
project!: ProjectReflection; | ||
|
||
/** | ||
* The filename the page will be written to. | ||
*/ | ||
filename!: string; | ||
|
||
/** | ||
* The url this page will be located at. | ||
*/ | ||
url!: string; | ||
|
||
/** | ||
* The model that should be rendered on this page. | ||
*/ | ||
readonly model: Model; | ||
|
||
/** | ||
* The final html content of this page. | ||
* | ||
* Should be rendered by layout templates and can be modified by plugins. | ||
*/ | ||
contents?: string; | ||
|
||
/** | ||
* Front matter of the current page | ||
*/ | ||
frontmatter?: any; | ||
|
||
/** | ||
* Triggered before a document will be rendered. | ||
* @event | ||
*/ | ||
static readonly BEGIN = 'beginPage'; | ||
|
||
/** | ||
* Triggered after a document has been rendered, just before it is written to disc. | ||
* @event | ||
*/ | ||
static readonly END = 'endPage'; | ||
|
||
constructor(name: string, model: Model) { | ||
super(name, model); | ||
} | ||
} | ||
|
||
export class FrontmatterEvent extends Event { | ||
/** | ||
* The page that this markdown is being parsed for. | ||
*/ | ||
readonly page: MarkdownPageEvent; | ||
|
||
/** | ||
* Triggered on the renderer when this plugin parses a markdown string. | ||
* @event | ||
*/ | ||
static readonly PREPARE_FRONTMATTER = 'prepareFrontmatter'; | ||
|
||
constructor(name: string, page: MarkdownPageEvent) { | ||
super(name); | ||
this.page = page; | ||
} | ||
} |
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,30 @@ | ||
import { Application, DeclarationReflection } from 'typedoc'; | ||
import { FrontmatterEvent, MarkdownPageEvent } from './events'; | ||
|
||
export function loadFrontmatter(app: Application) { | ||
app.renderer.on( | ||
MarkdownPageEvent.BEGIN, | ||
(page: MarkdownPageEvent<DeclarationReflection>) => { | ||
const enableFronmatter = app.options.getValue('enableFrontmatter'); | ||
if (enableFronmatter) { | ||
const event = new FrontmatterEvent( | ||
FrontmatterEvent.PREPARE_FRONTMATTER, | ||
page, | ||
); | ||
page.frontmatter = { title: 'HELLO' }; | ||
app.renderer.trigger(event); | ||
} | ||
}, | ||
); | ||
|
||
app.renderer.on(MarkdownPageEvent.END, (page: MarkdownPageEvent) => { | ||
const enableFronmatter = app.options.getValue('enableFrontmatter'); | ||
if (enableFronmatter) { | ||
try { | ||
console.log(page.frontmatter); | ||
} catch { | ||
console.log('Caught'); | ||
} | ||
} | ||
}); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { | ||
FrontmatterEvent, | ||
} = require('../packages/typedoc-plugin-markdown/dist'); | ||
|
||
module.exports = { | ||
load(app) { | ||
app.renderer.on(FrontmatterEvent.PREPARE_FRONTMATTER, (event) => { | ||
event.page.frontmatter = { ...event.page.frontmatter, updated: true }; | ||
}); | ||
}, | ||
}; |