metalsmith-markdown-partials 2.3.1 → 2.5.0

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
@@ -4,7 +4,9 @@ A Metalsmith plugin that enables the use of Markdown partials.
4
4
 
5
5
  [![metalsmith: plugin][metalsmith-badge]][metalsmith-url]
6
6
  [![npm: version][npm-badge]][npm-url]
7
- [![license: ISC][license-badge]][license-url]
7
+ [![license: MIT][license-badge]][license-url]
8
+ [![coverage][coverage-badge]][coverage-url]
9
+ [![ESM/CommonJS][modules-badge]][npm-url]
8
10
 
9
11
  Markdown fragments are inserted into the contents of a page markdown file by replacing an include marker with markdown partials. This allows for modular markdown and promotes reuse of content.
10
12
 
@@ -58,11 +60,13 @@ const mdPartials = require('metalsmith-markdown-partials').use(
58
60
  ## How it works
59
61
 
60
62
  ### Include marker
63
+
61
64
  ```
62
65
  {#md "<file name>.md" #}
63
66
  ```
64
67
 
65
68
  ### Page Markdown File
69
+
66
70
  A markdown file that will be transformed into an html file via a template
67
71
 
68
72
  ### Markdown Partial
@@ -117,6 +121,7 @@ Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nulla vitae
117
121
  parturient montes, nascetur ridiculus mus.
118
122
  </p>
119
123
  ```
124
+
120
125
  ## Debug
121
126
 
122
127
  To enable debug logs, set the `DEBUG` environment variable to `metalsmith-markdown-partials`:
@@ -132,6 +137,7 @@ Windows:
132
137
  ```
133
138
  set "DEBUG=metalsmith-markdown-partials"
134
139
  ```
140
+
135
141
  ### CLI usage
136
142
 
137
143
  To use this plugin with the Metalsmith CLI, add `metalsmith-markdown-partials` to the `plugins` key in your `metalsmith.json` file:
@@ -149,18 +155,24 @@ To use this plugin with the Metalsmith CLI, add `metalsmith-markdown-partials` t
149
155
  }
150
156
  ```
151
157
 
158
+ ## Test Coverage
159
+
160
+ This project maintains high statement and line coverage for the source code. Coverage is verified during the release process using the c8 coverage tool.
161
+
152
162
  ## Author
153
163
 
154
- - [werner@glinka.co](https://github.com/wernerglinka)
164
+ [werner@glinka.co](https://github.com/wernerglinka)
155
165
 
156
166
  ## License
157
167
 
158
- Code released under [the ISC license](https://github.com/wernerglinka/metalsmith-markdown-partials/blob/main/LICENSE).
159
-
168
+ Code released under [the MIT license](https://github.com/wernerglinka/metalsmith-markdown-partials/blob/main/LICENSE).
160
169
 
161
170
  [npm-badge]: https://img.shields.io/npm/v/metalsmith-markdown-partials.svg
162
171
  [npm-url]: https://www.npmjs.com/package/metalsmith-markdown-partials
163
172
  [metalsmith-badge]: https://img.shields.io/badge/metalsmith-plugin-green.svg?longCache=true
164
173
  [metalsmith-url]: https://metalsmith.io
165
174
  [license-badge]: https://img.shields.io/github/license/wernerglinka/metalsmith-markdown-partials
166
- [license-url]: LICENSE
175
+ [license-url]: LICENSE
176
+ [coverage-badge]: https://img.shields.io/badge/test%20coverage-94%25-brightgreen
177
+ [coverage-url]: #test-coverage
178
+ [modules-badge]: https://img.shields.io/badge/modules-ESM%2FCJS-blue
package/lib/index.cjs ADDED
@@ -0,0 +1,184 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * A Metalsmith plugin to merge markdown partials into main markdown files.
5
+ *
6
+ * @module metalsmith-markdown-partials
7
+ */
8
+
9
+ /**
10
+ * @typedef {Object} Options
11
+ * @property {String} libraryPath - Path to the markdown partials library (defaults to './src/content/md-library/')
12
+ * @property {String} fileSuffix - File suffix for markdown files (defaults to '.md')
13
+ */
14
+
15
+ // Define debug namespace at the top of the file
16
+ const debugNs = 'metalsmith-markdown-partials';
17
+
18
+ /** @type {Options} */
19
+ const defaults = {
20
+ libraryPath: './src/content/md-library/',
21
+ fileSuffix: '.md'
22
+ };
23
+
24
+ /**
25
+ * Normalize plugin options by merging with defaults
26
+ * @param {Options} [options] - User provided options
27
+ * @returns {Options} Normalized options
28
+ */
29
+ function normalizeOptions(options) {
30
+ return Object.assign({}, defaults, options || {});
31
+ }
32
+
33
+ /**
34
+ * Extract markdown partials from files and prepare them for insertion
35
+ *
36
+ * @param {Object} files - The metalsmith file object
37
+ * @param {Options} options - Plugin options
38
+ * @param {Function} debug - Debug function
39
+ * @returns {Array} Array with all markdown include objects
40
+ */
41
+ function getMarkdownIncludes(files, options, debug) {
42
+ const markdownIncludes = [];
43
+
44
+ // Extract the library name from the path
45
+ const libraryPath = options.libraryPath.slice(0, -1).split('/');
46
+ const libraryName = libraryPath[libraryPath.length - 1];
47
+ debug('Processing markdown files with libraryName: %s', libraryName);
48
+
49
+ // Regex for matching include markers
50
+ const markerRegex = /\{#md\s*".+?"\s*#\}/g;
51
+ const markerStart = '{#md';
52
+ const markerEnd = '#}';
53
+
54
+ // Set to track already processed partials to prevent duplicates
55
+ const processedPartials = new Set();
56
+ Object.keys(files).forEach(file => {
57
+ /*
58
+ * checks if string 'file' ends with options.fileSuffix
59
+ * when metalsmith-in-place or metalsmith-layouts are used
60
+ * the suffix depends on what templating language is used
61
+ * for example with Nunjucks it would be .md.njk
62
+ *
63
+ * Also check that file does NOT start with libraryName as
64
+ * the markdown partials library is also located in the content folder
65
+ */
66
+ if (file.endsWith(options.fileSuffix) && !file.startsWith(libraryName)) {
67
+ const str = files[file].contents.toString();
68
+
69
+ // Check if markers are present
70
+ const matches = str.match(markerRegex);
71
+ if (!matches) {
72
+ return;
73
+ }
74
+ debug('Found %d markdown partials in %s', matches.length, file);
75
+
76
+ // Process each marker in the file
77
+ matches.forEach(marker => {
78
+ // Extract the filename from the marker
79
+ const markerFileName = marker.replaceAll(' ', '').replace(`${markerStart}"`, '').replace(`"${markerEnd}`, '');
80
+ const partialKey = `${libraryName}/${markerFileName}`;
81
+
82
+ // Check if partial file exists
83
+ if (!files[partialKey]) {
84
+ debug('Warning: Partial file not found: %s', partialKey);
85
+ return;
86
+ }
87
+
88
+ // Skip if we've already processed this exact marker+file combination
89
+ const combinedKey = `${file}:${marker}`;
90
+ if (processedPartials.has(combinedKey)) {
91
+ return;
92
+ }
93
+ processedPartials.add(combinedKey);
94
+
95
+ // Get the replacement content
96
+ const replacementString = files[partialKey].contents.toString();
97
+ markdownIncludes.push({
98
+ marker,
99
+ markerReplacement: replacementString,
100
+ file
101
+ });
102
+ });
103
+ }
104
+ });
105
+
106
+ // Remove markdown-partials from metalsmith build process
107
+ Object.keys(files).forEach(file => {
108
+ if (file.startsWith(libraryName)) {
109
+ delete files[file];
110
+ }
111
+ });
112
+ debug('Processed %d markdown includes', markdownIncludes.length);
113
+ return markdownIncludes;
114
+ }
115
+
116
+ /**
117
+ * Replace markers with their markdown replacement strings
118
+ *
119
+ * @param {Object} files - The metalsmith file object
120
+ * @param {Array} markdownIncludes - Array with all markdown include objects
121
+ * @param {Function} debug - Debug function
122
+ * @return {void}
123
+ */
124
+ function resolveMarkdownIncludes(files, markdownIncludes, debug) {
125
+ // replace all markers with their markdown replacements
126
+ markdownIncludes.forEach(markdownInclude => {
127
+ const fileData = files[markdownInclude.file];
128
+
129
+ // replace the include marker with the actual include file content
130
+ try {
131
+ const contents = fileData.contents.toString();
132
+ fileData.contents = Buffer.from(contents.replace(markdownInclude.marker, markdownInclude.markerReplacement));
133
+ debug('Replaced marker in %s', markdownInclude.file);
134
+ } catch (e) {
135
+ debug('Error replacing marker in %s: %s', markdownInclude.file, e.message);
136
+ console.error(`Error replacing marker in ${markdownInclude.file}:`, e);
137
+ }
138
+ });
139
+ }
140
+
141
+ /**
142
+ * A Metalsmith plugin to merge markdown partials into main markdown file
143
+ *
144
+ * A marker of the form {#md "<file name>.md" #} indicates where the partial
145
+ * must be inserted and also provides the file name of the replacement markdown.
146
+ *
147
+ * @param {Options} [options] - Plugin options
148
+ * @returns {import('metalsmith').Plugin} Metalsmith plugin function
149
+ * @example
150
+ * // In your metalsmith build:
151
+ * .use(markdownPartials({
152
+ * libraryPath: './src/content/md-partials/',
153
+ * fileSuffix: '.md.njk'
154
+ * }))
155
+ */
156
+ function initMarkdownPartials(options) {
157
+ options = normalizeOptions(options);
158
+ return function markdownPartials(files, metalsmith, done) {
159
+ // Use metalsmith's debug method if available
160
+ const debug = metalsmith.debug ? metalsmith.debug(debugNs) : () => {};
161
+ debug('Running with options: %o', options);
162
+ try {
163
+ // Get all markdown includes
164
+ const markdownIncludes = getMarkdownIncludes(files, options, debug);
165
+
166
+ // Replace include markers with their respective replacement
167
+ if (markdownIncludes.length) {
168
+ resolveMarkdownIncludes(files, markdownIncludes, debug);
169
+ }
170
+ setImmediate(done);
171
+ } catch (err) {
172
+ debug('Error processing markdown partials: %s', err.message);
173
+ setImmediate(() => done(err));
174
+ }
175
+ };
176
+ }
177
+
178
+ // CommonJS export compatibility
179
+ if (typeof module !== 'undefined') {
180
+ module.exports = initMarkdownPartials;
181
+ }
182
+
183
+ module.exports = initMarkdownPartials;
184
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["/**\n * A Metalsmith plugin to merge markdown partials into main markdown files.\n *\n * @module metalsmith-markdown-partials\n */\n\n/**\n * @typedef {Object} Options\n * @property {String} libraryPath - Path to the markdown partials library (defaults to './src/content/md-library/')\n * @property {String} fileSuffix - File suffix for markdown files (defaults to '.md')\n */\n\n// Define debug namespace at the top of the file\nconst debugNs = 'metalsmith-markdown-partials';\n\n/** @type {Options} */\nconst defaults = {\n libraryPath: './src/content/md-library/',\n fileSuffix: '.md'\n};\n\n/**\n * Normalize plugin options by merging with defaults\n * @param {Options} [options] - User provided options\n * @returns {Options} Normalized options\n */\nfunction normalizeOptions(options) {\n return Object.assign({}, defaults, options || {});\n}\n\n/**\n * Extract markdown partials from files and prepare them for insertion\n *\n * @param {Object} files - The metalsmith file object\n * @param {Options} options - Plugin options\n * @param {Function} debug - Debug function\n * @returns {Array} Array with all markdown include objects\n */\nfunction getMarkdownIncludes(files, options, debug) {\n const markdownIncludes = [];\n\n // Extract the library name from the path\n const libraryPath = options.libraryPath.slice(0, -1).split('/');\n const libraryName = libraryPath[libraryPath.length - 1];\n\n debug('Processing markdown files with libraryName: %s', libraryName);\n\n // Regex for matching include markers\n const markerRegex = /\\{#md\\s*\".+?\"\\s*#\\}/g;\n const markerStart = '{#md';\n const markerEnd = '#}';\n\n // Set to track already processed partials to prevent duplicates\n const processedPartials = new Set();\n\n Object.keys(files).forEach((file) => {\n /*\n * checks if string 'file' ends with options.fileSuffix\n * when metalsmith-in-place or metalsmith-layouts are used\n * the suffix depends on what templating language is used\n * for example with Nunjucks it would be .md.njk\n *\n * Also check that file does NOT start with libraryName as\n * the markdown partials library is also located in the content folder\n */\n if (file.endsWith(options.fileSuffix) && !file.startsWith(libraryName)) {\n const str = files[file].contents.toString();\n\n // Check if markers are present\n const matches = str.match(markerRegex);\n if (!matches) {return;}\n\n debug('Found %d markdown partials in %s', matches.length, file);\n\n // Process each marker in the file\n matches.forEach((marker) => {\n // Extract the filename from the marker\n const markerFileName = marker.replaceAll(' ', '').replace(`${markerStart}\"`, '').replace(`\"${markerEnd}`, '');\n const partialKey = `${libraryName}/${markerFileName}`;\n\n // Check if partial file exists\n if (!files[partialKey]) {\n debug('Warning: Partial file not found: %s', partialKey);\n return;\n }\n\n // Skip if we've already processed this exact marker+file combination\n const combinedKey = `${file}:${marker}`;\n if (processedPartials.has(combinedKey)) {return;}\n\n processedPartials.add(combinedKey);\n\n // Get the replacement content\n const replacementString = files[partialKey].contents.toString();\n\n markdownIncludes.push({\n marker,\n markerReplacement: replacementString,\n file\n });\n });\n }\n });\n\n // Remove markdown-partials from metalsmith build process\n Object.keys(files).forEach((file) => {\n if (file.startsWith(libraryName)) {\n delete files[file];\n }\n });\n\n debug('Processed %d markdown includes', markdownIncludes.length);\n return markdownIncludes;\n}\n\n/**\n * Replace markers with their markdown replacement strings\n *\n * @param {Object} files - The metalsmith file object\n * @param {Array} markdownIncludes - Array with all markdown include objects\n * @param {Function} debug - Debug function\n * @return {void}\n */\nfunction resolveMarkdownIncludes(files, markdownIncludes, debug) {\n // replace all markers with their markdown replacements\n markdownIncludes.forEach((markdownInclude) => {\n const fileData = files[markdownInclude.file];\n\n // replace the include marker with the actual include file content\n try {\n const contents = fileData.contents.toString();\n fileData.contents = Buffer.from(contents.replace(markdownInclude.marker, markdownInclude.markerReplacement));\n debug('Replaced marker in %s', markdownInclude.file);\n } catch (e) {\n debug('Error replacing marker in %s: %s', markdownInclude.file, e.message);\n console.error(`Error replacing marker in ${markdownInclude.file}:`, e);\n }\n });\n}\n\n/**\n * A Metalsmith plugin to merge markdown partials into main markdown file\n *\n * A marker of the form {#md \"<file name>.md\" #} indicates where the partial\n * must be inserted and also provides the file name of the replacement markdown.\n *\n * @param {Options} [options] - Plugin options\n * @returns {import('metalsmith').Plugin} Metalsmith plugin function\n * @example\n * // In your metalsmith build:\n * .use(markdownPartials({\n * libraryPath: './src/content/md-partials/',\n * fileSuffix: '.md.njk'\n * }))\n */\nfunction initMarkdownPartials(options) {\n options = normalizeOptions(options);\n\n return function markdownPartials(files, metalsmith, done) {\n // Use metalsmith's debug method if available\n const debug = metalsmith.debug ? metalsmith.debug(debugNs) : () => {};\n debug('Running with options: %o', options);\n\n try {\n // Get all markdown includes\n const markdownIncludes = getMarkdownIncludes(files, options, debug);\n\n // Replace include markers with their respective replacement\n if (markdownIncludes.length) {\n resolveMarkdownIncludes(files, markdownIncludes, debug);\n }\n\n setImmediate(done);\n } catch (err) {\n debug('Error processing markdown partials: %s', err.message);\n setImmediate(() => done(err));\n }\n };\n}\n\n// ESM export\nexport default initMarkdownPartials;\n\n// CommonJS export compatibility\nif (typeof module !== 'undefined') {\n module.exports = initMarkdownPartials;\n}\n"],"names":["debugNs","defaults","libraryPath","fileSuffix","normalizeOptions","options","Object","assign","getMarkdownIncludes","files","debug","markdownIncludes","slice","split","libraryName","length","markerRegex","markerStart","markerEnd","processedPartials","Set","keys","forEach","file","endsWith","startsWith","str","contents","toString","matches","match","marker","markerFileName","replaceAll","replace","partialKey","combinedKey","has","add","replacementString","push","markerReplacement","resolveMarkdownIncludes","markdownInclude","fileData","Buffer","from","e","message","console","error","initMarkdownPartials","markdownPartials","metalsmith","done","setImmediate","err","module","exports"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMA,OAAO,GAAG,8BAA8B,CAAA;;AAE9C;AACA,MAAMC,QAAQ,GAAG;AACfC,EAAAA,WAAW,EAAE,2BAA2B;AACxCC,EAAAA,UAAU,EAAE,KAAA;AACd,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA,SAASC,gBAAgBA,CAACC,OAAO,EAAE;AACjC,EAAA,OAAOC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEN,QAAQ,EAAEI,OAAO,IAAI,EAAE,CAAC,CAAA;AACnD,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,mBAAmBA,CAACC,KAAK,EAAEJ,OAAO,EAAEK,KAAK,EAAE;EAClD,MAAMC,gBAAgB,GAAG,EAAE,CAAA;;AAE3B;AACA,EAAA,MAAMT,WAAW,GAAGG,OAAO,CAACH,WAAW,CAACU,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,KAAK,CAAC,GAAG,CAAC,CAAA;EAC/D,MAAMC,WAAW,GAAGZ,WAAW,CAACA,WAAW,CAACa,MAAM,GAAG,CAAC,CAAC,CAAA;AAEvDL,EAAAA,KAAK,CAAC,gDAAgD,EAAEI,WAAW,CAAC,CAAA;;AAEpE;EACA,MAAME,WAAW,GAAG,sBAAsB,CAAA;EAC1C,MAAMC,WAAW,GAAG,MAAM,CAAA;EAC1B,MAAMC,SAAS,GAAG,IAAI,CAAA;;AAEtB;AACA,EAAA,MAAMC,iBAAiB,GAAG,IAAIC,GAAG,EAAE,CAAA;EAEnCd,MAAM,CAACe,IAAI,CAACZ,KAAK,CAAC,CAACa,OAAO,CAAEC,IAAI,IAAK;AACnC;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACI,IAAA,IAAIA,IAAI,CAACC,QAAQ,CAACnB,OAAO,C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,EAAE;EACjCA,MAAM,CAACC,OAAO,GAAGP,oBAAoB,CAAA;AACvC;;;;"}
package/lib/index.js CHANGED
@@ -1,8 +1,18 @@
1
1
  /**
2
- * @typedef Options
3
- * @property {String} key
2
+ * A Metalsmith plugin to merge markdown partials into main markdown files.
3
+ *
4
+ * @module metalsmith-markdown-partials
5
+ */
6
+
7
+ /**
8
+ * @typedef {Object} Options
9
+ * @property {String} libraryPath - Path to the markdown partials library (defaults to './src/content/md-library/')
10
+ * @property {String} fileSuffix - File suffix for markdown files (defaults to '.md')
4
11
  */
5
12
 
13
+ // Define debug namespace at the top of the file
14
+ const debugNs = 'metalsmith-markdown-partials';
15
+
6
16
  /** @type {Options} */
7
17
  const defaults = {
8
18
  libraryPath: './src/content/md-library/',
@@ -10,104 +20,120 @@ const defaults = {
10
20
  };
11
21
 
12
22
  /**
13
- * Normalize plugin options
14
- * @param {Options} [options]
15
- * @returns {Object}
23
+ * Normalize plugin options by merging with defaults
24
+ * @param {Options} [options] - User provided options
25
+ * @returns {Options} Normalized options
16
26
  */
17
- function normalizeOptions( options ) {
18
- return Object.assign( {}, defaults, options || {} );
27
+ function normalizeOptions(options) {
28
+ return Object.assign({}, defaults, options || {});
19
29
  }
20
30
 
21
31
  /**
22
- * getMarkdownIncludes
23
- * Get include markdown markers and replacements
32
+ * Extract markdown partials from files and prepare them for insertion
24
33
  *
25
- * @param {[Object]} files - the metalsmith file object
26
- * @param {Options} options
27
- *
28
- * @return {[Array]} Array with all markdown include objects
34
+ * @param {Object} files - The metalsmith file object
35
+ * @param {Options} options - Plugin options
36
+ * @param {Function} debug - Debug function
37
+ * @returns {Array} Array with all markdown include objects
29
38
  */
30
- function getMarkdownIncludes( files, options ) {
39
+ function getMarkdownIncludes(files, options, debug) {
31
40
  const markdownIncludes = [];
32
41
 
33
- // get the library name
34
- const libraryPath = options.libraryPath.slice( 0, -1 ).split( "/" );
35
- const libraryName = libraryPath[ libraryPath.length - 1 ];
42
+ // Extract the library name from the path
43
+ const libraryPath = options.libraryPath.slice(0, -1).split('/');
44
+ const libraryName = libraryPath[libraryPath.length - 1];
45
+ debug('Processing markdown files with libraryName: %s', libraryName);
46
+
47
+ // Regex for matching include markers
48
+ const markerRegex = /\{#md\s*".+?"\s*#\}/g;
49
+ const markerStart = '{#md';
50
+ const markerEnd = '#}';
36
51
 
37
- Object.keys( files ).forEach( function ( file ) {
52
+ // Set to track already processed partials to prevent duplicates
53
+ const processedPartials = new Set();
54
+ Object.keys(files).forEach(file => {
38
55
  /*
39
56
  * checks if string 'file' ends with options.fileSuffix
40
57
  * when metalsmith-in-place or metalsmith-layouts are used
41
58
  * the suffix depends on what templating language is used
42
59
  * for example with Nunjucks it would be .md.njk
43
60
  *
44
- * Also check that file does NOT start with libraryName as
45
- * the markdown partials library is also located in the content
46
- * folder
61
+ * Also check that file does NOT start with libraryName as
62
+ * the markdown partials library is also located in the content folder
47
63
  */
48
- if ( file.endsWith( options.fileSuffix ) && !file.startsWith( libraryName ) ) {
49
- const markerStart = "{#md";
50
- const markerEnd = "#}";
51
- const str = files[ file ].contents.toString();
52
-
53
- // check for markers present
54
- const count = str.match( /\{#md\s*".+?"\s*#\}/g ).length;
55
-
56
- // get all markdown includes
57
- if ( count ) {
58
- for ( let i = 0; count > i; i++ ) {
59
- const marker = str.match( /\{#md\s*"(.+?)"\s*#\}/g )[ i ];
60
- const markerFileName = marker.replaceAll( " ", "" ).replace( `${ markerStart }"`, "" ).replace( `"${ markerEnd }`, "" );
61
-
62
- // get the replacement markdown string
63
- // by reconstructing the object key for the replacement markdown file
64
- // `${libraryName}/${markerFileName}`
65
- const replacementString = files[ `${ libraryName }/${ markerFileName }` ].contents.toString();
66
-
67
- markdownIncludes.push( {
68
- marker,
69
- markerReplacement: replacementString,
70
- file
71
- } );
64
+ if (file.endsWith(options.fileSuffix) && !file.startsWith(libraryName)) {
65
+ const str = files[file].contents.toString();
72
66
 
73
- }
67
+ // Check if markers are present
68
+ const matches = str.match(markerRegex);
69
+ if (!matches) {
70
+ return;
74
71
  }
72
+ debug('Found %d markdown partials in %s', matches.length, file);
73
+
74
+ // Process each marker in the file
75
+ matches.forEach(marker => {
76
+ // Extract the filename from the marker
77
+ const markerFileName = marker.replaceAll(' ', '').replace(`${markerStart}"`, '').replace(`"${markerEnd}`, '');
78
+ const partialKey = `${libraryName}/${markerFileName}`;
79
+
80
+ // Check if partial file exists
81
+ if (!files[partialKey]) {
82
+ debug('Warning: Partial file not found: %s', partialKey);
83
+ return;
84
+ }
85
+
86
+ // Skip if we've already processed this exact marker+file combination
87
+ const combinedKey = `${file}:${marker}`;
88
+ if (processedPartials.has(combinedKey)) {
89
+ return;
90
+ }
91
+ processedPartials.add(combinedKey);
92
+
93
+ // Get the replacement content
94
+ const replacementString = files[partialKey].contents.toString();
95
+ markdownIncludes.push({
96
+ marker,
97
+ markerReplacement: replacementString,
98
+ file
99
+ });
100
+ });
75
101
  }
76
- } );
102
+ });
77
103
 
78
104
  // Remove markdown-partials from metalsmith build process
79
- Object.keys( files ).forEach( function ( file ) {
80
- if ( file.startsWith( libraryName ) ) {
81
- delete files[ file ];
105
+ Object.keys(files).forEach(file => {
106
+ if (file.startsWith(libraryName)) {
107
+ delete files[file];
82
108
  }
83
- } );
84
-
109
+ });
110
+ debug('Processed %d markdown includes', markdownIncludes.length);
85
111
  return markdownIncludes;
86
112
  }
87
113
 
88
114
  /**
89
- * resolveMarkdownIncludes
90
115
  * Replace markers with their markdown replacement strings
91
116
  *
92
- * @param {[Object]} files - the metalsmith file object
93
- * @param {[Array]} markdownIncludes with all markdown include objects
94
- * @return {[void]}
117
+ * @param {Object} files - The metalsmith file object
118
+ * @param {Array} markdownIncludes - Array with all markdown include objects
119
+ * @param {Function} debug - Debug function
120
+ * @return {void}
95
121
  */
96
- function resolveMarkdownIncludes( files, markdownIncludes ) {
122
+ function resolveMarkdownIncludes(files, markdownIncludes, debug) {
97
123
  // replace all markers with their markdown replacements
98
- markdownIncludes.forEach( function ( markdownInclude ) {
99
-
100
- const fileData = files[ markdownInclude.file ];
124
+ markdownIncludes.forEach(markdownInclude => {
125
+ const fileData = files[markdownInclude.file];
101
126
 
102
127
  // replace the include marker with the actual include file content
103
128
  try {
104
129
  const contents = fileData.contents.toString();
105
- fileData.contents = Buffer.from( contents.replace( markdownInclude.marker, markdownInclude.markerReplacement ) );
106
- } catch ( e ) {
107
- console.error( e );
130
+ fileData.contents = Buffer.from(contents.replace(markdownInclude.marker, markdownInclude.markerReplacement));
131
+ debug('Replaced marker in %s', markdownInclude.file);
132
+ } catch (e) {
133
+ debug('Error replacing marker in %s: %s', markdownInclude.file, e.message);
134
+ console.error(`Error replacing marker in ${markdownInclude.file}:`, e);
108
135
  }
109
-
110
- } );
136
+ });
111
137
  }
112
138
 
113
139
  /**
@@ -116,25 +142,41 @@ function resolveMarkdownIncludes( files, markdownIncludes ) {
116
142
  * A marker of the form {#md "<file name>.md" #} indicates where the partial
117
143
  * must be inserted and also provides the file name of the replacement markdown.
118
144
  *
119
- * @param {Options} options
120
- * @returns {import('metalsmith').Plugin}
145
+ * @param {Options} [options] - Plugin options
146
+ * @returns {import('metalsmith').Plugin} Metalsmith plugin function
147
+ * @example
148
+ * // In your metalsmith build:
149
+ * .use(markdownPartials({
150
+ * libraryPath: './src/content/md-partials/',
151
+ * fileSuffix: '.md.njk'
152
+ * }))
121
153
  */
154
+ function initMarkdownPartials(options) {
155
+ options = normalizeOptions(options);
156
+ return function markdownPartials(files, metalsmith, done) {
157
+ // Use metalsmith's debug method if available
158
+ const debug = metalsmith.debug ? metalsmith.debug(debugNs) : () => {};
159
+ debug('Running with options: %o', options);
160
+ try {
161
+ // Get all markdown includes
162
+ const markdownIncludes = getMarkdownIncludes(files, options, debug);
122
163
 
123
- function initMarkdownPartials( options ) {
124
- options = normalizeOptions( options );
125
-
126
- return function markdownPartials( files, metalsmith, done ) {
127
- setImmediate( done );
128
-
129
- // get all markdown includes
130
- const markdownIncludes = getMarkdownIncludes( files, options );
131
-
132
- // replace include markers with their respective replacement
133
- if ( markdownIncludes.length ) {
134
- resolveMarkdownIncludes( files, markdownIncludes );
164
+ // Replace include markers with their respective replacement
165
+ if (markdownIncludes.length) {
166
+ resolveMarkdownIncludes(files, markdownIncludes, debug);
167
+ }
168
+ setImmediate(done);
169
+ } catch (err) {
170
+ debug('Error processing markdown partials: %s', err.message);
171
+ setImmediate(() => done(err));
135
172
  }
136
-
137
173
  };
138
174
  }
139
175
 
140
- export default initMarkdownPartials;
176
+ // CommonJS export compatibility
177
+ if (typeof module !== 'undefined') {
178
+ module.exports = initMarkdownPartials;
179
+ }
180
+
181
+ export { initMarkdownPartials as default };
182
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["/**\n * A Metalsmith plugin to merge markdown partials into main markdown files.\n *\n * @module metalsmith-markdown-partials\n */\n\n/**\n * @typedef {Object} Options\n * @property {String} libraryPath - Path to the markdown partials library (defaults to './src/content/md-library/')\n * @property {String} fileSuffix - File suffix for markdown files (defaults to '.md')\n */\n\n// Define debug namespace at the top of the file\nconst debugNs = 'metalsmith-markdown-partials';\n\n/** @type {Options} */\nconst defaults = {\n libraryPath: './src/content/md-library/',\n fileSuffix: '.md'\n};\n\n/**\n * Normalize plugin options by merging with defaults\n * @param {Options} [options] - User provided options\n * @returns {Options} Normalized options\n */\nfunction normalizeOptions(options) {\n return Object.assign({}, defaults, options || {});\n}\n\n/**\n * Extract markdown partials from files and prepare them for insertion\n *\n * @param {Object} files - The metalsmith file object\n * @param {Options} options - Plugin options\n * @param {Function} debug - Debug function\n * @returns {Array} Array with all markdown include objects\n */\nfunction getMarkdownIncludes(files, options, debug) {\n const markdownIncludes = [];\n\n // Extract the library name from the path\n const libraryPath = options.libraryPath.slice(0, -1).split('/');\n const libraryName = libraryPath[libraryPath.length - 1];\n\n debug('Processing markdown files with libraryName: %s', libraryName);\n\n // Regex for matching include markers\n const markerRegex = /\\{#md\\s*\".+?\"\\s*#\\}/g;\n const markerStart = '{#md';\n const markerEnd = '#}';\n\n // Set to track already processed partials to prevent duplicates\n const processedPartials = new Set();\n\n Object.keys(files).forEach((file) => {\n /*\n * checks if string 'file' ends with options.fileSuffix\n * when metalsmith-in-place or metalsmith-layouts are used\n * the suffix depends on what templating language is used\n * for example with Nunjucks it would be .md.njk\n *\n * Also check that file does NOT start with libraryName as\n * the markdown partials library is also located in the content folder\n */\n if (file.endsWith(options.fileSuffix) && !file.startsWith(libraryName)) {\n const str = files[file].contents.toString();\n\n // Check if markers are present\n const matches = str.match(markerRegex);\n if (!matches) {return;}\n\n debug('Found %d markdown partials in %s', matches.length, file);\n\n // Process each marker in the file\n matches.forEach((marker) => {\n // Extract the filename from the marker\n const markerFileName = marker.replaceAll(' ', '').replace(`${markerStart}\"`, '').replace(`\"${markerEnd}`, '');\n const partialKey = `${libraryName}/${markerFileName}`;\n\n // Check if partial file exists\n if (!files[partialKey]) {\n debug('Warning: Partial file not found: %s', partialKey);\n return;\n }\n\n // Skip if we've already processed this exact marker+file combination\n const combinedKey = `${file}:${marker}`;\n if (processedPartials.has(combinedKey)) {return;}\n\n processedPartials.add(combinedKey);\n\n // Get the replacement content\n const replacementString = files[partialKey].contents.toString();\n\n markdownIncludes.push({\n marker,\n markerReplacement: replacementString,\n file\n });\n });\n }\n });\n\n // Remove markdown-partials from metalsmith build process\n Object.keys(files).forEach((file) => {\n if (file.startsWith(libraryName)) {\n delete files[file];\n }\n });\n\n debug('Processed %d markdown includes', markdownIncludes.length);\n return markdownIncludes;\n}\n\n/**\n * Replace markers with their markdown replacement strings\n *\n * @param {Object} files - The metalsmith file object\n * @param {Array} markdownIncludes - Array with all markdown include objects\n * @param {Function} debug - Debug function\n * @return {void}\n */\nfunction resolveMarkdownIncludes(files, markdownIncludes, debug) {\n // replace all markers with their markdown replacements\n markdownIncludes.forEach((markdownInclude) => {\n const fileData = files[markdownInclude.file];\n\n // replace the include marker with the actual include file content\n try {\n const contents = fileData.contents.toString();\n fileData.contents = Buffer.from(contents.replace(markdownInclude.marker, markdownInclude.markerReplacement));\n debug('Replaced marker in %s', markdownInclude.file);\n } catch (e) {\n debug('Error replacing marker in %s: %s', markdownInclude.file, e.message);\n console.error(`Error replacing marker in ${markdownInclude.file}:`, e);\n }\n });\n}\n\n/**\n * A Metalsmith plugin to merge markdown partials into main markdown file\n *\n * A marker of the form {#md \"<file name>.md\" #} indicates where the partial\n * must be inserted and also provides the file name of the replacement markdown.\n *\n * @param {Options} [options] - Plugin options\n * @returns {import('metalsmith').Plugin} Metalsmith plugin function\n * @example\n * // In your metalsmith build:\n * .use(markdownPartials({\n * libraryPath: './src/content/md-partials/',\n * fileSuffix: '.md.njk'\n * }))\n */\nfunction initMarkdownPartials(options) {\n options = normalizeOptions(options);\n\n return function markdownPartials(files, metalsmith, done) {\n // Use metalsmith's debug method if available\n const debug = metalsmith.debug ? metalsmith.debug(debugNs) : () => {};\n debug('Running with options: %o', options);\n\n try {\n // Get all markdown includes\n const markdownIncludes = getMarkdownIncludes(files, options, debug);\n\n // Replace include markers with their respective replacement\n if (markdownIncludes.length) {\n resolveMarkdownIncludes(files, markdownIncludes, debug);\n }\n\n setImmediate(done);\n } catch (err) {\n debug('Error processing markdown partials: %s', err.message);\n setImmediate(() => done(err));\n }\n };\n}\n\n// ESM export\nexport default initMarkdownPartials;\n\n// CommonJS export compatibility\nif (typeof module !== 'undefined') {\n module.exports = initMarkdownPartials;\n}\n"],"names":["debugNs","defaults","libraryPath","fileSuffix","normalizeOptions","options","Object","assign","getMarkdownIncludes","files","debug","markdownIncludes","slice","split","libraryName","length","markerRegex","markerStart","markerEnd","processedPartials","Set","keys","forEach","file","endsWith","startsWith","str","contents","toString","matches","match","marker","markerFileName","replaceAll","replace","partialKey","combinedKey","has","add","replacementString","push","markerReplacement","resolveMarkdownIncludes","markdownInclude","fileData","Buffer","from","e","message","console","error","initMarkdownPartials","markdownPartials","metalsmith","done","setImmediate","err","module","exports"],"mappings":"AAAA;AACA;AACA;AACA;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}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "metalsmith-markdown-partials",
3
- "version": "2.3.1",
4
- "description": "A Metalsmith plugin that allows the use of partial markdowm files",
3
+ "version": "2.5.0",
4
+ "description": "A Metalsmith plugin that allows the use of partial markdown files",
5
5
  "keywords": [
6
6
  "metalsmith-plugin",
7
7
  "metalsmith",
@@ -9,12 +9,23 @@
9
9
  "markdown-partials",
10
10
  "static-site"
11
11
  ],
12
- "main": "lib/index.js",
12
+ "main": "./lib/index.cjs",
13
+ "module": "./lib/index.js",
14
+ "exports": {
15
+ "import": "./lib/index.js",
16
+ "require": "./lib/index.cjs",
17
+ "default": "./lib/index.js"
18
+ },
13
19
  "type": "module",
14
20
  "repository": {
15
21
  "type": "git",
16
22
  "url": "git+https://github.com/wernerglinka/metalsmith-markdown-partials.git"
17
23
  },
24
+ "files": [
25
+ "lib",
26
+ "LICENSE.md",
27
+ "README.md"
28
+ ],
18
29
  "author": {
19
30
  "name": "Werner Glinka",
20
31
  "email": "werner@glinka.co"
@@ -24,35 +35,46 @@
24
35
  "url": "https://github.com/wernerglinka/metalsmith-markdown-partials/issues"
25
36
  },
26
37
  "homepage": "https://github.com/wernerglinka/metalsmith-markdown-partials#readme",
27
- "dependencies": {
28
- "debug": "^4.3.7"
38
+ "scripts": {
39
+ "build": "microbundle --entry src/index.js --output lib/index.js --target node -f esm,cjs --strict --generateTypes=false",
40
+ "changelog": "auto-changelog -u --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release)'",
41
+ "coverage": "npm test && c8 report --reporter=text-lcov > ./coverage.info",
42
+ "format": "prettier --write \"**/*.{yml,md,js,json}\"",
43
+ "format:check": "prettier --list-different \"**/*.{yml,md,js,json}\"",
44
+ "lint": "eslint --fix .",
45
+ "lint:check": "eslint --fix-dry-run .",
46
+ "prepublishOnly": "npm run build",
47
+ "update-coverage": "node scripts/update-coverage-badge.js",
48
+ "prerelease": "npm run update-coverage && git add README.md && git commit -m \"Update coverage badge in README\" || true",
49
+ "release": "npm run build && GITHUB_TOKEN=$(grep GITHUB_TOKEN .env | cut -d '=' -f2) ./node_modules/.bin/release-it . ",
50
+ "release:check": "npm run lint:check && npm run build && GITHUB_TOKEN=$(grep GITHUB_TOKEN .env | cut -d '=' -f2) ./node_modules/.bin/release-it . --dry-run",
51
+ "test": "c8 --include=src/**/*.js mocha 'test/index.js' 'test/cjs.test.cjs' -t 15000",
52
+ "test:esm": "c8 --include=src/**/*.js mocha test/index.js -t 15000",
53
+ "test:cjs": "c8 --include=src/**/*.js mocha test/cjs.test.cjs -t 15000",
54
+ "test:e2e": "serve -l 3000 test/fixtures",
55
+ "depcheck": "depcheck"
29
56
  },
30
57
  "devDependencies": {
31
58
  "auto-changelog": "^2.5.0",
32
- "chai": "^5.1.2",
33
- "coveralls": "^3.1.1",
34
- "eslint": "^9.14.0",
35
- "eslint-config-prettier": "^9.1.0",
59
+ "c8": "^10.1.3",
60
+ "eslint": "^9.26.0",
61
+ "eslint-config-prettier": "^10.1.5",
36
62
  "metalsmith": "^2.6.3",
37
- "mocha": "^10.8.2",
38
- "nyc": "^17.1.0",
39
- "prettier": "^3.3.3",
40
- "release-it": "^17.10.0"
63
+ "microbundle": "^0.15.1",
64
+ "mocha": "^11.2.2",
65
+ "prettier": "^3.5.3",
66
+ "release-it": "19.0.2"
41
67
  },
42
68
  "peerDependencies": {
43
69
  "metalsmith": "^2.5.1"
44
70
  },
45
- "scripts": {
46
- "changelog": "auto-changelog -u date --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release)'",
47
- "format": "prettier --write \"**/*.{yml,md,js,json}\"",
48
- "lint": "eslint --cache --fix-dry-run .",
49
- "release": "release-it .",
50
- "test": "nyc mocha ./tests/index.js"
51
- },
52
71
  "engines": {
53
- "node": ">=8"
72
+ "node": ">=18.0.0"
54
73
  },
55
74
  "publishConfig": {
56
75
  "access": "public"
76
+ },
77
+ "dependencies": {
78
+ "depcheck": "^1.4.7"
57
79
  }
58
80
  }
package/.eslintcache DELETED
@@ -1 +0,0 @@
1
- [{"/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/lib/index.js":"1","/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/tests/index.js":"2"},{"size":4171,"mtime":1644358226139,"results":"3","hashOfConfig":"4"},{"size":862,"mtime":1643928622922,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","suppressedMessages":"8","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"uajcbk",{"filePath":"9","messages":"10","suppressedMessages":"11","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/lib/index.js",[],[],"/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/tests/index.js",[],[]]
package/.eslintrc.yml DELETED
@@ -1,8 +0,0 @@
1
- env:
2
- node: true
3
- es6: true
4
- extends:
5
- - 'eslint:recommended'
6
- - 'prettier'
7
- parserOptions:
8
- ecmaVersion: 2017
package/.gitattributes DELETED
@@ -1,7 +0,0 @@
1
- # Automatically normalize line endings for all text-based files
2
- # http://git-scm.com/docs/gitattributes#_end_of_line_conversion
3
- * text=auto eol=lf
4
-
5
- # For binary file types, prevent converting CRLF chars
6
- *.jpg -text
7
- *.png -text
@@ -1 +0,0 @@
1
- {"parent":null,"pid":96565,"argv":["/Users/wernerglinka/.nvm/versions/node/v18.16.0/bin/node","/Users/wernerglinka/Documents/Projects/Metalsmith/>>>plugins/ms-markdown-partials/node_modules/.bin/mocha","./tests/index.js"],"execArgv":[],"cwd":"/Users/wernerglinka/Documents/Projects/Metalsmith/>>>plugins/ms-markdown-partials","time":1731375730889,"ppid":96562,"coverageFilename":"/Users/wernerglinka/Documents/Projects/Metalsmith/>>>plugins/ms-markdown-partials/.nyc_output/181518ec-15ce-4116-8650-58fc4a5be71d.json","externalId":"","uuid":"181518ec-15ce-4116-8650-58fc4a5be71d","files":[]}
@@ -1 +0,0 @@
1
- {"processes":{"181518ec-15ce-4116-8650-58fc4a5be71d":{"parent":null,"children":[]}},"files":{},"externalIds":{}}
package/.prettierignore DELETED
@@ -1,3 +0,0 @@
1
- test/fixtures/**
2
- .nyc_output/**
3
- package-lock.json
package/.prettierrc.yml DELETED
@@ -1,7 +0,0 @@
1
- trailingComma: none
2
- tabWidth: 2
3
- semi: true
4
- singleQuote: true
5
- bracketSpacing: true
6
- arrowParens: always
7
- printWidth: 120
package/.release-it.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "hooks": {
3
- "before:init": ["npm run lint", "npm test"],
4
- "after:bump": "auto-changelog -p --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release)'",
5
- "after:npm:bump": "npm pack",
6
- "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
7
- },
8
- "git": {
9
- "commitMessage": "Release ${version}",
10
- "commitArgs": ["-S"],
11
- "tagAnnotation": "Release ${version}",
12
- "tagArgs": ["-s"],
13
- "changelog": "auto-changelog -u --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release)' --stdout"
14
- },
15
- "npm": {
16
- "publish": false
17
- },
18
- "github": {
19
- "release": true,
20
- "releaseName": "@metalsmith/~core-plugin~ ${version}",
21
- "tokenRef": "GITHUB_TOKEN",
22
- "assets": ["metalsmith-~core-plugin~-${version}.tgz"]
23
- }
24
- }
package/CHANGELOG.md DELETED
@@ -1,16 +0,0 @@
1
- ### Changelog
2
-
3
- All notable changes to this project will be documented in this file. Dates are displayed in UTC.
4
-
5
- Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
-
7
- #### Unreleased
8
-
9
- - added various config files [`1be389c`](https://github.com/wernerglinka/metalsmith-markdown-partials/commit/1be389cb9aedf82405c08c79cdfa866e7d3560d9)
10
- - updated to ES6 style JS, added license [`37b000f`](https://github.com/wernerglinka/metalsmith-markdown-partials/commit/37b000fa3669d928f693ec23a7ccfa629c0e7163)
11
- - added test [`d998103`](https://github.com/wernerglinka/metalsmith-markdown-partials/commit/d998103cb57b4a35ac9224afb11f4264b56f4abe)
12
- - initial commit [`9a91277`](https://github.com/wernerglinka/metalsmith-markdown-partials/commit/9a91277da228d9a718b2c86b012901559c95470d)
13
- - streamlined code and added to readme.md [`67c32be`](https://github.com/wernerglinka/metalsmith-markdown-partials/commit/67c32be34771325f407b9652dc3e7760971e3574)
14
- - added package.json [`86bfc7d`](https://github.com/wernerglinka/metalsmith-markdown-partials/commit/86bfc7d8de66be9127d612c5c5a9a79258a413f8)
15
- - removed initial debug directory [`46643bd`](https://github.com/wernerglinka/metalsmith-markdown-partials/commit/46643bd1aa19f45a9bf1b2513b6c7683da3eff78)
16
- - added install snippet [`321fb60`](https://github.com/wernerglinka/metalsmith-markdown-partials/commit/321fb6042240e1147b90468938911f6d8ed88f28)
package/coverage.info DELETED
File without changes
@@ -1,11 +0,0 @@
1
- # Markdown page... testing markdown partials plugin
2
-
3
- Nullam quis risus eget urna mollis ornare vel eu leo. Curabitur blandit tempus porttitor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec sed odio dui.
4
-
5
- ## Test partial title
6
-
7
- Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Sed posuere consectetur est at lobortis. Maecenas faucibus mollis interdum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
8
-
9
- Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Maecenas faucibus mollis interdum. Sed posuere consectetur est at lobortis.
10
-
11
- Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Aenean lacinia bibendum nulla sed consectetur.
@@ -1,11 +0,0 @@
1
- # Markdown page... testing markdown partials plugin
2
-
3
- Nullam quis risus eget urna mollis ornare vel eu leo. Curabitur blandit tempus porttitor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec sed odio dui.
4
-
5
- ## Test partial title
6
-
7
- Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Sed posuere consectetur est at lobortis. Maecenas faucibus mollis interdum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
8
-
9
- Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Maecenas faucibus mollis interdum. Sed posuere consectetur est at lobortis.
10
-
11
- Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Aenean lacinia bibendum nulla sed consectetur.
@@ -1,9 +0,0 @@
1
- # Markdown page... testing markdown partials plugin
2
-
3
- Nullam quis risus eget urna mollis ornare vel eu leo. Curabitur blandit tempus porttitor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec sed odio dui.
4
-
5
- {#md "test-partial.md" #}
6
-
7
- Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Maecenas faucibus mollis interdum. Sed posuere consectetur est at lobortis.
8
-
9
- Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Aenean lacinia bibendum nulla sed consectetur.
@@ -1,3 +0,0 @@
1
- ## Test partial title
2
-
3
- Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Sed posuere consectetur est at lobortis. Maecenas faucibus mollis interdum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
package/tests/index.js DELETED
@@ -1,42 +0,0 @@
1
- /* global describe, it */
2
-
3
- 'use strict';
4
-
5
- import * as chai from 'chai';
6
- import metalsmith from 'metalsmith';
7
- import mdPartials from '../lib/index.js';
8
- import fs from 'fs';
9
- import path from 'path';
10
- import { fileURLToPath } from 'node:url';
11
- import { dirname } from 'node:path';
12
-
13
- /* eslint-disable no-underscore-dangle */
14
- const __dirname = dirname( fileURLToPath( import.meta.url ) );
15
-
16
- const { expect } = chai;
17
-
18
- const fixture = path.resolve.bind( path, __dirname, 'fixtures' );
19
-
20
- function file( _path ) {
21
- return fs.readFileSync( fixture( _path ), 'utf8' );
22
- }
23
-
24
- describe( 'metalsmith-markdown-partials', () => {
25
-
26
- it( 'should replace marker with markdown partial', done => {
27
-
28
- metalsmith( fixture() )
29
- .use( mdPartials( {
30
- libraryPath: path.join( fixture(), `/src/md-partials/` ),
31
- fileSuffix: '.md',
32
- } ) )
33
- .build( err => {
34
- if ( err ) {
35
- return done( err );
36
- }
37
- expect( file( 'build/markdown.md' ) ).to.be.eql( file( 'expected/final-markdown.md' ) );
38
-
39
- done();
40
- } );
41
- } );
42
- } );