-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Moved tyoedic-plugin-frontmatter into repo
- Loading branch information
Showing
37 changed files
with
3,847 additions
and
32 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
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,13 @@ | ||
# typedoc-plugin-frontmatter | ||
|
||
## 0.0.2 | ||
|
||
### Patch Changes | ||
|
||
- 4cc0ff9: - Ignore if no frontmatter data found | ||
|
||
## 0.0.1 | ||
|
||
### Patch Changes | ||
|
||
- db8d673: - Initial plugin release. |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Tom Grey | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,169 @@ | ||
# typedoc-plugin-frontmatter | ||
|
||
![npm](https://img.shields.io/npm/v/typedoc-plugin-frontmatter%2Fnext?&logo=npm) [![Build Status](https://github.com/tgreyuk/typedoc-plugin-markdown/actions/workflows/ci.yml/badge.svg?branch=next)](https://github.com/tgreyuk/typedoc-plugin-markdown/actions/workflows/ci.yml) | ||
|
||
A plugin for [TypeDoc](https://typedoc.org) that prepends configurable frontmatter to page content. | ||
|
||
## What does it do? | ||
|
||
Exposes a set of options to generate frontmatter on TypeDoc generated pages. | ||
|
||
The primary motivation of this plugin is to enable configurable frontmatter on pages generated by [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown), but can also be used with HTML themes if applicable. | ||
|
||
Frontmatter can be configured through [options](#options) and writing a [local plugin](#configuring-using-a-local-plugin). | ||
|
||
## Installation | ||
|
||
```shell | ||
npm install typedoc-plugin-frontmatter --save-dev | ||
``` | ||
|
||
## Usage | ||
|
||
Please visit [TypeDoc](https://typedoc.org/options/configuration/#configuration-options) for general configuation usage, but typically configuration is set with a `typedoc.json` file. | ||
|
||
```shell | ||
typedoc --plugin typedoc-plugin-frontmatter | ||
``` | ||
|
||
## Options | ||
|
||
The following options are exposed by the plugin: | ||
|
||
- `--frontmatterGlobals` (`object`)<br> | ||
Specify global static variables as JSON to be added to all frontmatter blocks. | ||
- `--frontmatterTags` (`array`)<br> | ||
Specify the names of the comment @ [block tags](https://typedoc.org/guides/tags/#block-tags) that should be added to frontmatter variables. | ||
- `--frontmatterTagsToSnakeCase` (`boolean`)<br> | ||
Converts the variable names of comment tags to snake case. | ||
|
||
### Setting global variables | ||
|
||
Global variables can be added to all frontmatter blocks by passing a JSON object to the `--frontmatterGlobals` option. | ||
|
||
**typedoc.json** | ||
|
||
```json | ||
{ | ||
"frontmatterGlobals": { | ||
"layout": "docs", | ||
"sidebar": true | ||
} | ||
} | ||
``` | ||
|
||
**Frontmatter** | ||
|
||
```yaml | ||
--- | ||
layout: docs | ||
sidebar: true | ||
--- | ||
``` | ||
|
||
## Using comment tags | ||
|
||
Frontmatter variables can be added by extracting comments from block tags defined with the `--frontmatterTags` option. | ||
|
||
Please note tags must be added to the comment blocks of the symbol exported to a page. | ||
|
||
For example, the following will mark "author" and "description" tags as frontmatter. | ||
|
||
**typedoc.json** | ||
|
||
```json | ||
{ | ||
"frontmatterTags": ["author", "description"] | ||
} | ||
``` | ||
|
||
**Comment block** | ||
|
||
```ts | ||
/** | ||
* @module SomeModule | ||
* | ||
* @author Joe Bloggs | ||
* | ||
* @description A description that will be added to 'frontmatter'. | ||
* | ||
**/ | ||
``` | ||
|
||
**Frontmatter** | ||
|
||
```yaml | ||
--- | ||
author: Joe Bloggs | ||
description: "A description that will be added to 'frontmatter'." | ||
--- | ||
``` | ||
|
||
### Snake case variable names | ||
|
||
Tag that are written using snake case tag format will be ignored by the compiler. If snake case format for variable names are required then the option `--frontmatterTagsToSnakeCase` should be set. | ||
|
||
```json | ||
{ | ||
"frontmatterTagsToSnakeCase": true | ||
} | ||
``` | ||
|
||
**Comment block** | ||
|
||
```ts | ||
/** | ||
* @moreData Something | ||
* | ||
**/ | ||
``` | ||
|
||
**Frontmatter** | ||
|
||
```yaml | ||
--- | ||
more_data: 'Something' | ||
--- | ||
``` | ||
|
||
## Configuring using a local plugin | ||
|
||
For advanced use a local plugin can be written to listen for the emitted frontmatter event (`FrontmatterEvent.PREPARE_FRONTMATTER`) and then update the frontmatter config before it is written the page. | ||
|
||
The event returns: | ||
|
||
- `event.frontmatter` - The current frontmatter JSON object that will be paresed and written to the page. This can be updated with the spread operator additional items. | ||
- `event.page` - The current page that is being written. | ||
|
||
**typedoc.json** | ||
|
||
```json | ||
{ | ||
"plugin": ["typedoc-plugin-frontmatter", "./dist/custom-plugin.js"] | ||
} | ||
``` | ||
|
||
**custom-plugin.ts** | ||
|
||
```ts | ||
import { Application } from 'typedoc'; | ||
import { FrontmatterEvent } from 'typedoc-plugin-frontmatter'; | ||
|
||
// All plugins should export a `load()` function | ||
export function load(app: Application) { | ||
// Listen to PREPARE_FRONTMATTER event | ||
app.renderer.on(FrontmatterEvent.PREPARE_FRONTMATTER, (event: FrontmatterEvent) => { | ||
// Update event.frontmatter object using information from the page model as JSON | ||
event.frontmatter = { | ||
// e.g add a title | ||
title: event.page.model?.name, | ||
// spread the existing frontmatter | ||
...event.frontmatter, | ||
}; | ||
}); | ||
} | ||
``` | ||
|
||
## License | ||
|
||
[MIT](https://github.com/tgreyuk/typedoc-plugin-frontmatter/blob/master/LICENSE) |
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 @@ | ||
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. |
22 changes: 22 additions & 0 deletions
22
packages/typedoc-plugin-frontmatter/docs/no-data/assets/highlight.css
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,22 @@ | ||
:root { | ||
--light-code-background: #FFFFFF; | ||
--dark-code-background: #1E1E1E; | ||
} | ||
|
||
@media (prefers-color-scheme: light) { :root { | ||
--code-background: var(--light-code-background); | ||
} } | ||
|
||
@media (prefers-color-scheme: dark) { :root { | ||
--code-background: var(--dark-code-background); | ||
} } | ||
|
||
:root[data-theme='light'] { | ||
--code-background: var(--light-code-background); | ||
} | ||
|
||
:root[data-theme='dark'] { | ||
--code-background: var(--dark-code-background); | ||
} | ||
|
||
pre, code { background: var(--code-background); } |
58 changes: 58 additions & 0 deletions
58
packages/typedoc-plugin-frontmatter/docs/no-data/assets/main.js
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/typedoc-plugin-frontmatter/docs/no-data/assets/search.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.