Skip to content

Commit

Permalink
feat: Moved tyoedic-plugin-frontmatter into repo
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Oct 31, 2023
1 parent ba7dac5 commit 2442527
Show file tree
Hide file tree
Showing 37 changed files with 3,847 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"tag": "next",
"initialVersions": {
"typedoc-plugin-markdown": "3.15.1",
"typedoc-plugin-remark": "0.0.0",
"typedoc-plugin-remark": "0.0.1",
"typedoc-plugin-frontmatter": "0.0.2",
"docusaurus-plugin-typedoc": "0.18.0",
"typedoc-vitepress-theme": "0.0.0",
"typedoc-github-wiki-theme": "1.0.1",
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"workspaces": [
"packages/typedoc-plugin-markdown",
"packages/typedoc-plugin-remark",
"packages/typedoc-frontmatter",
"packages/docusaurus-plugin-typedoc",
"packages/typedoc-github-wiki-theme",
"packages/typedoc-gitlab-wiki-theme",
Expand All @@ -11,7 +12,7 @@
"scripts": {
"lint": "npm run lint --workspaces",
"build": "npm run build --workspaces",
"test": "npm run test --workspace=typedoc-plugin-markdown",
"test": "npm run test --workspaces",
"prerelease": "npm run build",
"release": "npx changeset publish"
},
Expand Down
13 changes: 13 additions & 0 deletions packages/typedoc-plugin-frontmatter/CHANGELOG.md
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.
21 changes: 21 additions & 0 deletions packages/typedoc-plugin-frontmatter/LICENSE
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.
169 changes: 169 additions & 0 deletions packages/typedoc-plugin-frontmatter/README.md
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)
1 change: 1 addition & 0 deletions packages/typedoc-plugin-frontmatter/docs/no-data/.nojekyll
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.
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 packages/typedoc-plugin-frontmatter/docs/no-data/assets/main.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2442527

Please sign in to comment.