-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(core): expose dedicated async jobs to renderer
- Loading branch information
Showing
11 changed files
with
147 additions
and
134 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
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
* @module | ||
*/ | ||
export * from './locales/index.js'; | ||
export * from './translatable.js'; | ||
export * from './setup.js'; |
35 changes: 35 additions & 0 deletions
35
packages/typedoc-plugin-markdown/src/internationalization/setup.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,35 @@ | ||
import { en, jp, ko, zh } from '@plugin/internationalization/index.js'; | ||
import { Application, Converter } from 'typedoc'; | ||
|
||
export function setupInternationalization(app: Application): void { | ||
app.converter.on(Converter.EVENT_BEGIN, () => { | ||
app.internationalization.addTranslations( | ||
app.options.getValue('lang'), | ||
{ ...getTranslatable(app) }, | ||
true, | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* Returns subset of translatable strings for the plugin. | ||
* | ||
* These will then be merged with the main set of TypeDoc string. | ||
* | ||
* @category Functions | ||
*/ | ||
function getTranslatable(app: Application) { | ||
const LOCALES = { | ||
en, | ||
jp, | ||
ko, | ||
zh, | ||
}; | ||
return { | ||
...LOCALES['en'], | ||
...(app.lang !== 'en' && Object.keys(LOCALES).includes(app.lang) | ||
? { ...LOCALES[app.lang] } | ||
: {}), | ||
...app.options.getValue('locales')[app.lang], | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
* @module | ||
*/ | ||
|
||
export * from './packages.js'; | ||
export * from './render.js'; | ||
export * from './setup.js'; |
This file was deleted.
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,66 @@ | ||
import { MarkdownTheme } from '@plugin/theme/index.js'; | ||
import { | ||
MarkdownRenderer, | ||
MarkdownRendererHooks, | ||
} from '@plugin/types/index.js'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { Application, Context, Converter, EventHooks } from 'typedoc'; | ||
|
||
/** | ||
* Create dedicated hooks and async job collections for markdown rendering. | ||
*/ | ||
export function setupRenderer(app: Application) { | ||
app.renderer.defineTheme('markdown', MarkdownTheme); | ||
|
||
Object.defineProperty(app.renderer, 'markdownHooks', { | ||
value: new EventHooks<MarkdownRendererHooks, string>(), | ||
}); | ||
|
||
Object.defineProperty(app.renderer, 'preMarkdownRenderAsyncJobs', { | ||
value: [], | ||
}); | ||
|
||
Object.defineProperty(app.renderer, 'postMarkdownRenderAsyncJobs', { | ||
value: [], | ||
}); | ||
|
||
app.converter.on(Converter.EVENT_RESOLVE_END, (context: Context) => { | ||
if (app.options.packageDir) { | ||
resolvePackages(app, context, app.options.packageDir); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Resolves packages meta data for the project. | ||
* | ||
* @remarks | ||
* | ||
* Currently options set for packages are only stored on the converter and are destroyed before being passed to the Renderer. | ||
* | ||
* By intercepting the package options set in the converter and storing them on the renderer we can use them later in the theme. | ||
*/ | ||
function resolvePackages( | ||
app: Application, | ||
context: Context, | ||
packageDir: string, | ||
) { | ||
const packageJsonContents = fs | ||
.readFileSync(path.join(packageDir, 'package.json')) | ||
.toString(); | ||
|
||
const packageJson = packageJsonContents | ||
? JSON.parse(packageJsonContents) | ||
: {}; | ||
|
||
const renderer = app.renderer as unknown as MarkdownRenderer; | ||
|
||
renderer.packagesMeta = { | ||
...(renderer.packagesMeta || {}), | ||
[context.project.name]: { | ||
description: packageJson.description, | ||
options: app.options, | ||
}, | ||
}; | ||
} |
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
Oops, something went wrong.