Skip to content

Commit

Permalink
Initial release!
Browse files Browse the repository at this point in the history
  • Loading branch information
roydukkey committed Jan 12, 2022
1 parent 3e4b546 commit e1af64b
Show file tree
Hide file tree
Showing 21 changed files with 597 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .editorconfig
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
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [roydukkey]
19 changes: 19 additions & 0 deletions .gitignore
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
22 changes: 22 additions & 0 deletions .npmignore
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*
26 changes: 26 additions & 0 deletions .vscode/cSpell.json
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"
]
}
8 changes: 8 additions & 0 deletions .vscode/extensions.json
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"
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
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
}
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
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!
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 trent
Copyright (c) 2022 roydukkey

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
128 changes: 128 additions & 0 deletions README.md
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 (<... />);
}
```
Loading

0 comments on commit e1af64b

Please sign in to comment.