Skip to content

Commit 86dcda5

Browse files
committed
Initial commit
0 parents  commit 86dcda5

27 files changed

+3775
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
max_line_length = 100
10+
trim_trailing_whitespace = true
11+
12+
[COMMIT_EDITMSG]
13+
max_line_length = 72

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.jsx

.eslintrc.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root: true
2+
extends:
3+
- remcohaszing
4+
rules:
5+
import/no-extraneous-dependencies: off

.github/workflows/ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
on:
2+
- pull_request
3+
- push
4+
5+
jobs:
6+
eslint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
- uses: actions/setup-node@v1
11+
with:
12+
node-version: 14
13+
- name: ESLint
14+
run: |
15+
yarn --frozen-lockfile
16+
yarn eslint .
17+
18+
jest:
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
node-version: [12, 14]
23+
steps:
24+
- uses: actions/checkout@v1
25+
- uses: actions/setup-node@v1
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
- name: Test
29+
run: |
30+
yarn --frozen-lockfile
31+
yarn test
32+
33+
prettier:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v1
37+
- uses: actions/setup-node@v1
38+
with:
39+
node-version: 14
40+
- name: Prettier
41+
run: |
42+
yarn --frozen-lockfile
43+
yarn prettier .
44+
45+
tsc:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v1
49+
- uses: actions/setup-node@v1
50+
with:
51+
node-version: 14
52+
- name: TypeScript
53+
run: |
54+
yarn --frozen-lockfile
55+
yarn tsc

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coverage/
2+
dist/
3+
node_modules/
4+
*.log
5+
*.tgz

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage/
2+
dist/
3+
node_modules/
4+
*.jsx

.prettierrc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
proseWrap: always
2+
singleQuote: true
3+
trailingComma: all

LICENSE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# MIT License
2+
3+
Copyright © 2021 Remco Haszing
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6+
associated documentation files (the "Software"), to deal in the Software without restriction,
7+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
8+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all copies or substantial
12+
portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
17+
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# remark-mdx-frontmatter
2+
3+
[![github actions][github actions badge]][github actions] [![codecov][codecov badge]][codecov]
4+
[![npm][npm badge]][npm] [![prettier][prettier badge]][prettier]
5+
6+
> A [remark][] plugin for converting frontmatter metadata into MDX exports
7+
8+
## Installation
9+
10+
This package depends on the AST output by [remark-frontmatter][]
11+
12+
```sh
13+
npm install remark-frontmatter remark-mdx-frontmatter
14+
```
15+
16+
## Usage
17+
18+
This remark plugin takes frontmatter content, and outputs it as JavaScript exports. Both YAML and
19+
TOML frontmatter data are supported.
20+
21+
For example, given a file named `example.mdx` with the following contents:
22+
23+
```mdx
24+
---
25+
hello: frontmatter
26+
---
27+
28+
Rest of document
29+
```
30+
31+
The following script:
32+
33+
```js
34+
import { readFileSync } from 'fs';
35+
36+
import remarkFrontmatter from 'remark-frontmatter';
37+
import { remarkMdxFrontmatter } from 'remark-mdx-frontmatter';
38+
import { compileSync } from 'xdm';
39+
40+
const { contents } = compileSync(readFileSync('example.mdx'), {
41+
jsx: true,
42+
remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter],
43+
});
44+
console.log(contents);
45+
```
46+
47+
Roughly yields:
48+
49+
```jsx
50+
export const hello = 'frontmatter';
51+
52+
export default function MDXContent() {
53+
return <p>Rest of document</p>;
54+
}
55+
```
56+
57+
### Options
58+
59+
#### `name`
60+
61+
By default, every frontmatter object key is turned into a JavaScript export. If `name` is specified,
62+
the YAML content is exported as one single export using this name. This is useful if you wish to use
63+
top-level frontmatter nodes other than objects, or if the frontmatter content contains keys which
64+
aren’t valid JavaScript identifiers.
65+
66+
[github actions badge]:
67+
https://github.com/remcohaszing/remark-mdx-frontmatter/workflows/ci/badge.svg
68+
[github actions]: https://github.com/remcohaszing/remark-mdx-frontmatter/actions
69+
[npm badge]: https://img.shields.io/npm/v/remark-mdx-frontmatter
70+
[npm]: https://www.npmjs.com/package/remark-mdx-frontmatter
71+
[prettier badge]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg
72+
[prettier]: https://prettier.io
73+
[remark]: https://remark.js.org
74+
[remark-frontmatter]: https://github.com/remarkjs/remark-frontmatter

__fixtures__/default/expected.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*@jsxRuntime automatic @jsxImportSource react*/
2+
export const title = "Hello frontmatter", index = 1, nested = {
3+
"data": {
4+
"structure": {
5+
"including": {
6+
"numbers": 42,
7+
"booleans": true,
8+
"null": null,
9+
"dates": new Date(1444435200000),
10+
"datetimes": new Date(1444471200000),
11+
"timezones": new Date(1444438800000),
12+
"arrays": ["of", "items"]
13+
}
14+
}
15+
}
16+
};
17+
function MDXContent(_props) {
18+
const _components = Object.assign({}, _props.components), {wrapper: MDXLayout} = _components;
19+
const _content = <></>;
20+
return MDXLayout ? <MDXLayout {..._props}>{_content}</MDXLayout> : _content;
21+
}
22+
export default MDXContent;

0 commit comments

Comments
 (0)