-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
21 changed files
with
597 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 2 | ||
indent_style = tab | ||
tab_width = 2 | ||
trim_trailing_whitespace = true | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
[*.{md,mdx}] | ||
indent_style = space |
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,3 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [roydukkey] |
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,19 @@ | ||
# User-specific files | ||
.DS_Store | ||
*.vs | ||
*.user | ||
|
||
# Package Managers | ||
node_modules | ||
npm-debug.log | ||
|
||
# Build Artifacts | ||
*.lock.json | ||
*-lock.json | ||
*.lock | ||
*.backup | ||
*.cache | ||
*.jest | ||
*.tgz | ||
dist | ||
package |
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 @@ | ||
# User-specific files | ||
.DS_Store | ||
*.editorconfig | ||
*.env | ||
*.user | ||
*.vs | ||
*.vscode | ||
*.github | ||
|
||
# Package Managers | ||
node_modules | ||
npm-debug.log | ||
|
||
# Build Artifacts | ||
*.lock.json | ||
*-lock.json | ||
*.backup | ||
*.cache | ||
*.tgz | ||
|
||
# Source Code | ||
tsconfig* |
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,26 @@ | ||
{ | ||
"version": "0.2", | ||
"ignorePaths": [ | ||
"node_modules", | ||
".git", | ||
".jest", | ||
".docusaurus", | ||
"**/.DS_Store", | ||
"*.lock.json", | ||
"*-lock.json", | ||
"*.lock", | ||
"*.tgz", | ||
"*.svg" | ||
], | ||
"dictionaries": [ | ||
"fullstack" | ||
], | ||
// Before adding a word, see if there is already a dictionary in which it is contained. | ||
// http://github.com/streetsidesoftware/cspell-dicts | ||
"words": [ | ||
"graymatter", | ||
"roydukkey", | ||
"streetsidesoftware", | ||
"tsdoc" | ||
] | ||
} |
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,8 @@ | ||
{ | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
// for the documentation about the extensions.json format | ||
"recommendations": [ | ||
"editorconfig.editorconfig", | ||
"streetsidesoftware.code-spell-checker" | ||
] | ||
} |
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 @@ | ||
{ | ||
"files.exclude": { | ||
"**/node_modules": true, | ||
"package-lock.json": true, | ||
"yarn.lock": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changelog | ||
|
||
<!-- The order of list items should be: Critical/Fixes, New, Update, Remove, Underpinnings --> | ||
<!-- ## [UNRELEASED](https://github.com/roydukkey/docusaurus-theme-frontmatter/compare/v1.0.0...master) --> | ||
|
||
## 1.0.0 | ||
|
||
* Initial 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
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,128 @@ | ||
# docusaurus-theme-frontmatter | ||
|
||
This package enhances the Docusaurus classic theme by exposing the [docs](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#markdown-frontmatter), [blog](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-blog#markdown-frontmatter), and [pages](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-pages) front matter to the following components and their children: | ||
|
||
* [BlogPostItem](https://github.com/facebook/docusaurus/tree/main/packages/docusaurus-theme-classic/src/theme/BlogPostItem) | ||
* [DocItem](https://github.com/facebook/docusaurus/tree/main/packages/docusaurus-theme-classic/src/theme/DocItem) | ||
* [MDXPage](https://github.com/facebook/docusaurus/tree/main/packages/docusaurus-theme-classic/src/theme/MDXPage) | ||
|
||
Furthermore, this allows you to define and access ***custom*** front matter. | ||
|
||
## Install | ||
|
||
```sh | ||
yarn add docusaurus-theme-frontmatter | ||
``` | ||
|
||
Then, include the plugin in your `docusaurus.config.js` file. | ||
|
||
```diff | ||
// docusaurus.config.js | ||
module.exports = { | ||
... | ||
+ themes: ['docusaurus-theme-frontmatter'], | ||
... | ||
} | ||
``` | ||
|
||
### TypeScript support | ||
|
||
To enable TypeScript support, the TypeScript configuration should be updated to add the `docusaurus-theme-frontmatter` type definitions. This can be done in the `tsconfig.json` file: | ||
|
||
```diff | ||
{ | ||
"extends": "@tsconfig/docusaurus/tsconfig.json", | ||
"compilerOptions": { | ||
... | ||
+ "types": ["docusaurus-theme-frontmatter"] | ||
} | ||
} | ||
``` | ||
|
||
## How to use | ||
|
||
The `useFrontMatter()` hook is made available to any of your components through the `@theme/useFrontMatter` import. For example, you might have a component that creates a gallery of images. | ||
|
||
```mdx | ||
--- | ||
title: Miniature fairy doors of NYC | ||
hide_table_of_contents: true | ||
gallery: | ||
- /images/117-first-avenue.jpg | ||
- /images/lower-east-side.jpg | ||
- /images/my-guinness.jpg | ||
- /images/hundred-years.jpg | ||
--- | ||
import Galley from '@theme/Galley'; | ||
|
||
<Galley /> | ||
``` | ||
|
||
```jsx | ||
import React from 'react'; | ||
import ImageGallery from 'react-image-gallery'; | ||
import useFrontMatter from '@theme/useFrontMatter'; | ||
|
||
export default function GalleyComponent () { | ||
const { gallery } = useFrontMatter(); | ||
|
||
if (Array.isArray(gallery)) { | ||
const images = gallery.map((image) => ({ | ||
original: image | ||
})); | ||
|
||
return <ImageGallery items={images} />; | ||
} | ||
|
||
return null; | ||
} | ||
``` | ||
|
||
## Public API | ||
|
||
### `useFrontMatter<T extends FrontMatter>()` | ||
|
||
Returns the front matter for the current context. | ||
|
||
```ts | ||
import useFrontMatter from '@theme/useFrontMatter'; | ||
|
||
interface CustomFrontMatter { | ||
gallery?: string[]; | ||
} | ||
|
||
const MyComponent = () => { | ||
const { gallery } = useFrontMatter<CustomFrontMatter>(); | ||
return (<... />); | ||
} | ||
``` | ||
|
||
### `Context` | ||
|
||
The current front matter context. | ||
|
||
Generally, this is something to be left alone and operates behind the scenes. This is how it is used to [enhance DocItem](https://github.com/roydukkey/docusaurus-theme-frontmatter/blob/master/src/theme/DocItem.tsx) scaffolding the hook: | ||
|
||
```js | ||
import { Context } from '@theme/useFrontMatter'; | ||
import DocItem from '@theme-init/DocItem'; | ||
import React from 'react'; | ||
|
||
export default (props) => <Context.Provider value={props.content.frontMatter}> | ||
<DocItem {...props} /> | ||
</Context.Provider>; | ||
``` | ||
|
||
### `FrontMatter`, `DocItemFrontMatter`, `BlogPostItemFrontMatter`, `MDXPageFrontMatter` | ||
|
||
These types are provided to assist in describing the values returned by the `useFrontMatter()` hook. | ||
|
||
```ts | ||
import useFrontMatter from '@theme/useFrontMatter'; | ||
import type { DocItemFrontMatter } from '@theme/useFrontMatter'; | ||
|
||
const MyComponent = () => { | ||
const { id, title, keywords } = useFrontMatter<DocItemFrontMatter>(); | ||
return (<... />); | ||
} | ||
``` |
Oops, something went wrong.