@md-plugins/md-plugin-frontmatter 0.1.0-alpha.9 → 0.1.0-beta.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.
package/README.md CHANGED
@@ -15,12 +15,12 @@ A **Markdown-It** plugin that extracts and processes frontmatter from Markdown c
15
15
  Install the plugin via your preferred package manager:
16
16
 
17
17
  ```bash
18
- # With npm:
19
- npm install @md-plugins/md-plugin-frontmatter
20
- # Or with Yarn:
21
- yarn add @md-plugins/md-plugin-frontmatter
22
- # Or with pnpm:
18
+ # with pnpm:
23
19
  pnpm add @md-plugins/md-plugin-frontmatter
20
+ # with Yarn:
21
+ yarn add @md-plugins/md-plugin-frontmatter
22
+ # with npm:
23
+ npm install @md-plugins/md-plugin-frontmatter
24
24
  ```
25
25
 
26
26
  ## Usage
@@ -103,6 +103,10 @@ Run the unit tests with `Vitest` to ensure the plugin behaves as expected:
103
103
  pnpm test
104
104
  ```
105
105
 
106
+ ## Documentation
107
+
108
+ In case this README falls out of date, please refer to the [documentation](https://md-plugins.netlify.app/md-plugins/frontmatter/overview) for the latest information.
109
+
106
110
  ## License
107
111
 
108
112
  This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
package/dist/index.d.mts CHANGED
@@ -44,10 +44,10 @@ declare module '@md-plugins/shared' {
44
44
  }
45
45
 
46
46
  /**
47
- * Get markdown frontmatter and excerpt
48
- *
49
- * Extract them into env
47
+ * Get markdown frontmatter and excerpt.
48
+ * Extract them into env.
50
49
  */
51
50
  declare const frontmatterPlugin: PluginWithOptions<FrontmatterPluginOptions>;
52
51
 
53
- export { type FrontmatterPluginOptions, frontmatterPlugin };
52
+ export { frontmatterPlugin };
53
+ export type { FrontmatterPluginOptions };
package/dist/index.d.ts CHANGED
@@ -44,10 +44,10 @@ declare module '@md-plugins/shared' {
44
44
  }
45
45
 
46
46
  /**
47
- * Get markdown frontmatter and excerpt
48
- *
49
- * Extract them into env
47
+ * Get markdown frontmatter and excerpt.
48
+ * Extract them into env.
50
49
  */
51
50
  declare const frontmatterPlugin: PluginWithOptions<FrontmatterPluginOptions>;
52
51
 
53
- export { type FrontmatterPluginOptions, frontmatterPlugin };
52
+ export { frontmatterPlugin };
53
+ export type { FrontmatterPluginOptions };
package/dist/index.mjs CHANGED
@@ -1,6 +1,26 @@
1
1
  import grayMatter from 'gray-matter';
2
2
 
3
- const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = false } = {}) => {
3
+ function resolvePluginOptions(options, key, defaults) {
4
+ if (options && typeof options === "object" && key in options) {
5
+ return { ...defaults, ...options[key] };
6
+ }
7
+ return { ...defaults, ...options };
8
+ }
9
+
10
+ const DEFAULT_FRONTMATTER_PLUGIN_OPTIONS = {
11
+ grayMatterOptions: {},
12
+ renderExcerpt: false
13
+ };
14
+ const frontmatterPlugin = (md, options) => {
15
+ const resolvedOptions = resolvePluginOptions(
16
+ options,
17
+ "frontmatterPlugin",
18
+ DEFAULT_FRONTMATTER_PLUGIN_OPTIONS
19
+ );
20
+ const {
21
+ grayMatterOptions = DEFAULT_FRONTMATTER_PLUGIN_OPTIONS.grayMatterOptions,
22
+ renderExcerpt = DEFAULT_FRONTMATTER_PLUGIN_OPTIONS.renderExcerpt
23
+ } = resolvedOptions;
4
24
  const render = md.render.bind(md);
5
25
  md.render = (src, env = {}) => {
6
26
  let data, content, excerpt;
@@ -15,17 +35,10 @@ const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = false } = {}
15
35
  }
16
36
  env.content = content;
17
37
  env.frontmatter = {
18
- // allow providing default value
19
38
  ...env.frontmatter,
20
39
  ...data
21
40
  };
22
- env.excerpt = renderExcerpt && data.excerpt ? (
23
- // render the excerpt with original markdown-it render method.
24
- render(data.excerpt, env)
25
- ) : (
26
- // use the raw excerpt directly
27
- excerpt
28
- );
41
+ env.excerpt = renderExcerpt && data.excerpt ? render(data.excerpt, env) : excerpt;
29
42
  return render(content, env);
30
43
  };
31
44
  };
package/package.json CHANGED
@@ -1,24 +1,29 @@
1
1
  {
2
2
  "name": "@md-plugins/md-plugin-frontmatter",
3
- "version": "0.1.0-alpha.9",
3
+ "version": "0.1.0-beta.1",
4
4
  "description": "A markdown-it plugin for handling frontmatter in markdown files.",
5
5
  "keywords": [
6
6
  "markdown-it",
7
7
  "quasarframework",
8
- "vue",
9
- "types"
8
+ "types",
9
+ "vue"
10
10
  ],
11
11
  "homepage": "https://github.com/md-plugins",
12
12
  "bugs": {
13
13
  "url": "https://github.com/md-plugins/md-plugins/issues"
14
14
  },
15
+ "license": "MIT",
16
+ "author": "hawkeye64 <galbraith64@gmail.com>",
15
17
  "repository": {
16
18
  "type": "git",
17
19
  "url": "git+https://github.com/md-plugins/md-plugins.git"
18
20
  },
19
- "license": "MIT",
20
- "author": "hawkeye64 <galbraith64@gmail.com>",
21
+ "files": [
22
+ "./dist"
23
+ ],
21
24
  "type": "module",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.ts",
22
27
  "exports": {
23
28
  ".": {
24
29
  "import": {
@@ -27,26 +32,19 @@
27
32
  }
28
33
  }
29
34
  },
30
- "module": "./dist/index.mjs",
31
- "types": "./dist/index.d.ts",
32
- "files": [
33
- "./dist"
34
- ],
35
- "dependencies": {
36
- "gray-matter": "^4.0.3",
37
- "markdown-it": "^14.1.0",
38
- "@md-plugins/shared": "0.1.0-alpha.9"
35
+ "publishConfig": {
36
+ "access": "public"
39
37
  },
40
38
  "devDependencies": {
41
- "@types/markdown-it": "^14.1.2"
39
+ "@types/markdown-it": "^14.1.2",
40
+ "gray-matter": "^4.0.3",
41
+ "markdown-it": "^14.1.1",
42
+ "@md-plugins/shared": "0.1.0-beta.1"
42
43
  },
43
44
  "peerDependencies": {
44
45
  "gray-matter": "^4.0.3",
45
46
  "markdown-it": "^14.1.0"
46
47
  },
47
- "publishConfig": {
48
- "access": "public"
49
- },
50
48
  "scripts": {
51
49
  "build": "unbuild",
52
50
  "clean": "rm -rf dist/ node_modules/",