@docusaurus/plugin-content-pages 2.0.0-beta.ff31de0ff → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/{src/__tests__/__fixtures__/website/i18n/fr/docusaurus-plugin-content-pages/hello/translatedJs.js → lib/frontMatter.d.ts} +4 -8
  2. package/lib/frontMatter.js +21 -0
  3. package/lib/index.d.ts +4 -3
  4. package/lib/index.js +45 -67
  5. package/lib/markdownLoader.d.ts +2 -6
  6. package/lib/markdownLoader.js +4 -4
  7. package/lib/options.d.ts +10 -0
  8. package/lib/{pluginOptionSchema.js → options.js} +16 -8
  9. package/lib/types.d.ts +0 -22
  10. package/package.json +14 -15
  11. package/src/frontMatter.ts +27 -0
  12. package/src/index.ts +57 -90
  13. package/src/markdownLoader.ts +8 -11
  14. package/src/{pluginOptionSchema.ts → options.ts} +15 -8
  15. package/src/plugin-content-pages.d.ts +59 -18
  16. package/src/types.ts +0 -28
  17. package/lib/.tsbuildinfo +0 -4349
  18. package/lib/pluginOptionSchema.d.ts +0 -10
  19. package/src/__tests__/__fixtures__/website/docusaurus.config.js +0 -14
  20. package/src/__tests__/__fixtures__/website/i18n/fr/docusaurus-plugin-content-pages/hello/translatedMd.md +0 -1
  21. package/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.js +0 -1
  22. package/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.md +0 -1
  23. package/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.mdx +0 -1
  24. package/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.tsx +0 -1
  25. package/src/__tests__/__fixtures__/website/src/pages/hello/index.md +0 -2
  26. package/src/__tests__/__fixtures__/website/src/pages/hello/mdxPage.mdx +0 -5
  27. package/src/__tests__/__fixtures__/website/src/pages/hello/translatedJs.js +0 -14
  28. package/src/__tests__/__fixtures__/website/src/pages/hello/translatedMd.md +0 -1
  29. package/src/__tests__/__fixtures__/website/src/pages/hello/world.js +0 -22
  30. package/src/__tests__/__fixtures__/website/src/pages/index.js +0 -23
  31. package/src/__tests__/__fixtures__/website/src/pages/typescript.tsx +0 -22
  32. package/src/__tests__/index.test.ts +0 -139
  33. package/src/__tests__/pluginOptionSchema.test.ts +0 -54
  34. package/tsconfig.json +0 -9
  35. package/types.d.ts +0 -13
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
- import { PluginOptions } from './types';
8
- import { Joi } from '@docusaurus/utils-validation';
9
- export declare const DEFAULT_OPTIONS: PluginOptions;
10
- export declare const PluginOptionSchema: Joi.ObjectSchema<any>;
@@ -1,14 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- module.exports = {
9
- title: 'My Site',
10
- tagline: 'The tagline of my site',
11
- url: 'https://your-docusaurus-test-site.com',
12
- baseUrl: '/',
13
- favicon: 'img/favicon.ico',
14
- };
@@ -1 +0,0 @@
1
- export default (a,b)=>a+b
@@ -1 +0,0 @@
1
- export default (a:number,b:number)=>a+b;
@@ -1,2 +0,0 @@
1
-
2
- Markdown index page
@@ -1,5 +0,0 @@
1
- ---
2
- title: mdx page
3
- description: my mdx page
4
- ---
5
- MDX page
@@ -1,14 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import React from 'react';
9
-
10
- export default class TranslatedJs extends React.Component {
11
- render() {
12
- return <div>TranslatedJsPage</div>;
13
- }
14
- }
@@ -1 +0,0 @@
1
- translated markdown page
@@ -1,22 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import React from 'react';
9
- import Head from '@docusaurus/Head';
10
-
11
- export default class World extends React.Component {
12
- render() {
13
- return (
14
- <div>
15
- <Head>
16
- <title>World</title>
17
- </Head>
18
- <div>Hello World </div>
19
- </div>
20
- );
21
- }
22
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import React from 'react';
9
- import Head from '@docusaurus/Head';
10
-
11
- export default class Home extends React.Component {
12
- render() {
13
- return (
14
- <div>
15
- <Head>
16
- <title>Home</title>
17
- <link rel="stylesheet" type="text/css" href="/css/basic.css" />
18
- </Head>
19
- <div>Home ... </div>
20
- </div>
21
- );
22
- }
23
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import React from 'react';
9
- import Head from '@docusaurus/Head';
10
-
11
- export default class Home extends React.Component {
12
- render() {
13
- return (
14
- <div>
15
- <Head>
16
- <title>Hello</title>
17
- </Head>
18
- <div>TypeScript...</div>
19
- </div>
20
- );
21
- }
22
- }
@@ -1,139 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import path from 'path';
9
- import {loadContext} from '@docusaurus/core/lib/server';
10
-
11
- import pluginContentPages from '../index';
12
- import normalizePluginOptions from './pluginOptionSchema.test';
13
-
14
- describe('docusaurus-plugin-content-pages', () => {
15
- test('simple pages', async () => {
16
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
17
- const context = await loadContext(siteDir);
18
- const pluginPath = 'src/pages';
19
- const plugin = pluginContentPages(
20
- context,
21
- normalizePluginOptions({
22
- path: pluginPath,
23
- }),
24
- );
25
- const pagesMetadatas = await plugin.loadContent?.();
26
-
27
- expect(pagesMetadatas).toEqual([
28
- {
29
- type: 'jsx',
30
- permalink: '/',
31
- source: path.posix.join('@site', pluginPath, 'index.js'),
32
- },
33
- {
34
- type: 'jsx',
35
- permalink: '/typescript',
36
- source: path.posix.join('@site', pluginPath, 'typescript.tsx'),
37
- },
38
- {
39
- type: 'mdx',
40
- permalink: '/hello/',
41
- source: path.posix.join('@site', pluginPath, 'hello', 'index.md'),
42
- },
43
- {
44
- type: 'mdx',
45
- permalink: '/hello/mdxPage',
46
- source: path.posix.join('@site', pluginPath, 'hello', 'mdxPage.mdx'),
47
- },
48
- {
49
- type: 'jsx',
50
- permalink: '/hello/translatedJs',
51
- source: path.posix.join(
52
- '@site',
53
- pluginPath,
54
- 'hello',
55
- 'translatedJs.js',
56
- ),
57
- },
58
- {
59
- type: 'mdx',
60
- permalink: '/hello/translatedMd',
61
- source: path.posix.join(
62
- '@site',
63
- pluginPath,
64
- 'hello',
65
- 'translatedMd.md',
66
- ),
67
- },
68
- {
69
- type: 'jsx',
70
- permalink: '/hello/world',
71
- source: path.posix.join('@site', pluginPath, 'hello', 'world.js'),
72
- },
73
- ]);
74
- });
75
-
76
- test('simple pages with french translations', async () => {
77
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
78
- const context = await loadContext(siteDir);
79
- const pluginPath = 'src/pages';
80
- const plugin = pluginContentPages(
81
- {
82
- ...context,
83
- i18n: {
84
- ...context.i18n,
85
- currentLocale: 'fr',
86
- },
87
- },
88
- normalizePluginOptions({
89
- path: pluginPath,
90
- }),
91
- );
92
- const pagesMetadatas = await plugin.loadContent?.();
93
-
94
- const frTranslationsPath = path.posix.join(
95
- '@site',
96
- 'i18n',
97
- 'fr',
98
- 'docusaurus-plugin-content-pages',
99
- );
100
-
101
- expect(pagesMetadatas).toEqual([
102
- {
103
- type: 'jsx',
104
- permalink: '/',
105
- source: path.posix.join('@site', pluginPath, 'index.js'),
106
- },
107
- {
108
- type: 'jsx',
109
- permalink: '/typescript',
110
- source: path.posix.join('@site', pluginPath, 'typescript.tsx'),
111
- },
112
- {
113
- type: 'mdx',
114
- permalink: '/hello/',
115
- source: path.posix.join('@site', pluginPath, 'hello', 'index.md'),
116
- },
117
- {
118
- type: 'mdx',
119
- permalink: '/hello/mdxPage',
120
- source: path.posix.join('@site', pluginPath, 'hello', 'mdxPage.mdx'),
121
- },
122
- {
123
- type: 'jsx',
124
- permalink: '/hello/translatedJs',
125
- source: path.posix.join(frTranslationsPath, 'hello', 'translatedJs.js'),
126
- },
127
- {
128
- type: 'mdx',
129
- permalink: '/hello/translatedMd',
130
- source: path.posix.join(frTranslationsPath, 'hello', 'translatedMd.md'),
131
- },
132
- {
133
- type: 'jsx',
134
- permalink: '/hello/world',
135
- source: path.posix.join('@site', pluginPath, 'hello', 'world.js'),
136
- },
137
- ]);
138
- });
139
- });
@@ -1,54 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import {PluginOptionSchema, DEFAULT_OPTIONS} from '../pluginOptionSchema';
9
- import {PluginOptions} from '../types';
10
-
11
- export default function normalizePluginOptions(
12
- options: Partial<PluginOptions>,
13
- ): PluginOptions {
14
- const {value, error} = PluginOptionSchema.validate(options, {
15
- convert: false,
16
- });
17
- if (error) {
18
- throw error;
19
- } else {
20
- return value;
21
- }
22
- }
23
-
24
- describe('normalizePagesPluginOptions', () => {
25
- test('should return default options for undefined user options', () => {
26
- const value = normalizePluginOptions({});
27
- expect(value).toEqual(DEFAULT_OPTIONS);
28
- });
29
-
30
- test('should fill in default options for partially defined user options', () => {
31
- const value = normalizePluginOptions({path: 'src/pages'});
32
- expect(value).toEqual(DEFAULT_OPTIONS);
33
- });
34
-
35
- test('should accept correctly defined user options', () => {
36
- const userOptions = {
37
- path: 'src/my-pages',
38
- routeBasePath: 'my-pages',
39
- include: ['**/*.{js,jsx,ts,tsx}'],
40
- exclude: ['**/$*/'],
41
- };
42
- const value = normalizePluginOptions(userOptions);
43
- expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
44
- });
45
-
46
- test('should reject bad path inputs', () => {
47
- expect(() => {
48
- normalizePluginOptions({
49
- // @ts-expect-error: bad attribute
50
- path: 42,
51
- });
52
- }).toThrowErrorMatchingInlineSnapshot(`"\\"path\\" must be a string"`);
53
- });
54
- });
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "incremental": true,
5
- "tsBuildInfoFile": "./lib/.tsbuildinfo",
6
- "rootDir": "src",
7
- "outDir": "lib"
8
- }
9
- }
package/types.d.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- declare module 'remark-admonitions' {
9
- type Options = Record<string, unknown>;
10
-
11
- const plugin: (options?: Options) => void;
12
- export = plugin;
13
- }