metalsmith-markdown-partials 1.0.0 → 2.0.3
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/.eslintcache +1 -0
- package/.eslintrc.yml +8 -0
- package/.gitattributes +7 -0
- package/.nyc_output/9d928c88-3cb5-4d77-8d43-36a76d50ab03.json +1 -0
- package/.nyc_output/processinfo/9d928c88-3cb5-4d77-8d43-36a76d50ab03.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/.prettierignore +3 -0
- package/.prettierrc.yml +7 -0
- package/.release-it.json +24 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE +7 -0
- package/README.md +83 -31
- package/coverage.info +0 -0
- package/lib/index.js +140 -0
- package/metalsmith-markdown-partials-2.0.3.tgz +0 -0
- package/package.json +45 -16
- package/tests/fixtures/build/markdown.md +11 -0
- package/tests/fixtures/expected/final-markdown.md +11 -0
- package/tests/fixtures/src/markdown.md +9 -0
- package/tests/fixtures/src/md-partials/test-partial.md +3 -0
- package/tests/index.js +36 -0
- package/.npmignore +0 -2
- package/index.js +0 -112
package/.eslintcache
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/lib/index.js":{"path":"/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/lib/index.js","statementMap":{"0":{"start":{"line":7,"column":17},"end":{"line":10,"column":1}},"1":{"start":{"line":18,"column":2},"end":{"line":18,"column":52}},"2":{"start":{"line":31,"column":29},"end":{"line":31,"column":31}},"3":{"start":{"line":34,"column":24},"end":{"line":34,"column":67}},"4":{"start":{"line":35,"column":24},"end":{"line":35,"column":59}},"5":{"start":{"line":37,"column":4},"end":{"line":76,"column":7}},"6":{"start":{"line":48,"column":6},"end":{"line":75,"column":7}},"7":{"start":{"line":49,"column":28},"end":{"line":49,"column":34}},"8":{"start":{"line":50,"column":26},"end":{"line":50,"column":30}},"9":{"start":{"line":51,"column":20},"end":{"line":51,"column":51}},"10":{"start":{"line":54,"column":22},"end":{"line":54,"column":62}},"11":{"start":{"line":57,"column":8},"end":{"line":74,"column":9}},"12":{"start":{"line":58,"column":10},"end":{"line":73,"column":11}},"13":{"start":{"line":58,"column":23},"end":{"line":58,"column":24}},"14":{"start":{"line":59,"column":27},"end":{"line":59,"column":65}},"15":{"start":{"line":60,"column":35},"end":{"line":60,"column":121}},"16":{"start":{"line":65,"column":38},"end":{"line":65,"column":99}},"17":{"start":{"line":67,"column":12},"end":{"line":71,"column":15}},"18":{"start":{"line":79,"column":4},"end":{"line":83,"column":7}},"19":{"start":{"line":80,"column":6},"end":{"line":82,"column":7}},"20":{"start":{"line":81,"column":8},"end":{"line":81,"column":27}},"21":{"start":{"line":85,"column":4},"end":{"line":85,"column":27}},"22":{"start":{"line":98,"column":2},"end":{"line":110,"column":5}},"23":{"start":{"line":100,"column":21},"end":{"line":100,"column":48}},"24":{"start":{"line":103,"column":4},"end":{"line":108,"column":5}},"25":{"start":{"line":104,"column":23},"end":{"line":104,"column":51}},"26":{"start":{"line":105,"column":6},"end":{"line":105,"column":115}},"27":{"start":{"line":107,"column":6},"end":{"line":107,"column":23}},"28":{"start":{"line":124,"column":2},"end":{"line":124,"column":38}},"29":{"start":{"line":126,"column":2},"end":{"line":137,"column":4}},"30":{"start":{"line":127,"column":4},"end":{"line":127,"column":23}},"31":{"start":{"line":130,"column":29},"end":{"line":130,"column":64}},"32":{"start":{"line":133,"column":4},"end":{"line":135,"column":5}},"33":{"start":{"line":134,"column":6},"end":{"line":134,"column":55}},"34":{"start":{"line":140,"column":0},"end":{"line":140,"column":38}}},"fnMap":{"0":{"name":"normalizeOptions","decl":{"start":{"line":17,"column":10},"end":{"line":17,"column":26}},"loc":{"start":{"line":17,"column":36},"end":{"line":19,"column":1}},"line":17},"1":{"name":"getMarkdownIncludes","decl":{"start":{"line":30,"column":9},"end":{"line":30,"column":28}},"loc":{"start":{"line":30,"column":45},"end":{"line":86,"column":1}},"line":30},"2":{"name":"(anonymous_2)","decl":{"start":{"line":37,"column":31},"end":{"line":37,"column":32}},"loc":{"start":{"line":37,"column":47},"end":{"line":76,"column":5}},"line":37},"3":{"name":"(anonymous_3)","decl":{"start":{"line":79,"column":31},"end":{"line":79,"column":32}},"loc":{"start":{"line":79,"column":47},"end":{"line":83,"column":5}},"line":79},"4":{"name":"resolveMarkdownIncludes","decl":{"start":{"line":96,"column":9},"end":{"line":96,"column":32}},"loc":{"start":{"line":96,"column":58},"end":{"line":111,"column":1}},"line":96},"5":{"name":"(anonymous_5)","decl":{"start":{"line":98,"column":27},"end":{"line":98,"column":28}},"loc":{"start":{"line":98,"column":53},"end":{"line":110,"column":3}},"line":98},"6":{"name":"initMarkdownPartials","decl":{"start":{"line":123,"column":9},"end":{"line":123,"column":29}},"loc":{"start":{"line":123,"column":39},"end":{"line":138,"column":1}},"line":123},"7":{"name":"markdownPartials","decl":{"start":{"line":126,"column":18},"end":{"line":126,"column":34}},"loc":{"start":{"line":126,"column":60},"end":{"line":137,"column":3}},"line":126}},"branchMap":{"0":{"loc":{"start":{"line":18,"column":37},"end":{"line":18,"column":50}},"type":"binary-expr","locations":[{"start":{"line":18,"column":37},"end":{"line":18,"column":44}},{"start":{"line":18,"column":48},"end":{"line":18,"column":50}}],"line":18},"1":{"loc":{"start":{"line":48,"column":6},"end":{"line":75,"column":7}},"type":"if","locations":[{"start":{"line":48,"column":6},"end":{"line":75,"column":7}},{"start":{"line":48,"column":6},"end":{"line":75,"column":7}}],"line":48},"2":{"loc":{"start":{"line":48,"column":10},"end":{"line":48,"column":76}},"type":"binary-expr","locations":[{"start":{"line":48,"column":10},"end":{"line":48,"column":43}},{"start":{"line":48,"column":47},"end":{"line":48,"column":76}}],"line":48},"3":{"loc":{"start":{"line":57,"column":8},"end":{"line":74,"column":9}},"type":"if","locations":[{"start":{"line":57,"column":8},"end":{"line":74,"column":9}},{"start":{"line":57,"column":8},"end":{"line":74,"column":9}}],"line":57},"4":{"loc":{"start":{"line":80,"column":6},"end":{"line":82,"column":7}},"type":"if","locations":[{"start":{"line":80,"column":6},"end":{"line":82,"column":7}},{"start":{"line":80,"column":6},"end":{"line":82,"column":7}}],"line":80},"5":{"loc":{"start":{"line":133,"column":4},"end":{"line":135,"column":5}},"type":"if","locations":[{"start":{"line":133,"column":4},"end":{"line":135,"column":5}},{"start":{"line":133,"column":4},"end":{"line":135,"column":5}}],"line":133}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":2,"7":1,"8":1,"9":1,"10":1,"11":1,"12":1,"13":1,"14":1,"15":1,"16":1,"17":1,"18":1,"19":2,"20":1,"21":1,"22":1,"23":1,"24":1,"25":1,"26":1,"27":0,"28":1,"29":1,"30":1,"31":1,"32":1,"33":1,"34":1},"f":{"0":1,"1":1,"2":2,"3":2,"4":1,"5":1,"6":1,"7":1},"b":{"0":[1,0],"1":[1,1],"2":[2,2],"3":[1,0],"4":[1,1],"5":[1,0]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"5a1610d35933a6d0de98c2efdfcab0bbaafbd6bd","contentHash":"0267ccac04a4935df40548e98e2dbbb2d1c5b36280a2a47d872df36ae3e24b14"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":46842,"argv":["/Users/wernerglinka/.nvm/versions/node/v16.13.0/bin/node","/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/node_modules/.bin/mocha","./tests/index.js"],"execArgv":[],"cwd":"/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials","time":1644364249222,"ppid":46841,"coverageFilename":"/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/.nyc_output/9d928c88-3cb5-4d77-8d43-36a76d50ab03.json","externalId":"","uuid":"9d928c88-3cb5-4d77-8d43-36a76d50ab03","files":["/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/lib/index.js"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"processes":{"9d928c88-3cb5-4d77-8d43-36a76d50ab03":{"parent":null,"children":[]}},"files":{"/Users/wernerglinka/Documents/Projects/1-SANDBOXES/metalsmith-sandbox/>>>plugins/ms-markdown-partials/lib/index.js":["9d928c88-3cb5-4d77-8d43-36a76d50ab03"]},"externalIds":{}}
|
package/.prettierignore
ADDED
package/.prettierrc.yml
ADDED
package/.release-it.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ISC License (ISC)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Werner Glinka
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,80 +2,132 @@
|
|
|
2
2
|
|
|
3
3
|
This Metalsmith plugin enables the use of Markdown partials, e.g. Markdown fragments can be inserted into the contents section of a page markdown file via an include marker.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
[![metalsmith: plugin][metalsmith-badge]][metalsmith-url]
|
|
6
|
+
[![npm: version][npm-badge]][npm-url]
|
|
7
|
+
[![license: MIT][license-badge]][license-url]
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
{#md "<file name>.md" #}
|
|
11
|
+
```
|
|
8
12
|
|
|
9
13
|
This allows for modular markdown and promotes reuse of markdown partials.
|
|
10
14
|
|
|
11
15
|
## Page Markdown File
|
|
16
|
+
|
|
12
17
|
A markdown file that will be transformed into an html file via a template
|
|
13
18
|
|
|
14
|
-
## Markdown
|
|
19
|
+
## Markdown Partial
|
|
20
|
+
|
|
15
21
|
A markdown file to be inserted into a Page Markdown file
|
|
16
22
|
|
|
17
|
-
Markdown partials are located in a separate directory, for example
|
|
23
|
+
Markdown partials are located in a separate directory, for example `/markdown-library/`. This directory should be located inside `/src/` .
|
|
18
24
|
|
|
19
|
-
Partial markdown files have the extention
|
|
25
|
+
Partial markdown files have the extention `.md`. A markdown partial file does NOT have frontmatter metadata, only the markdown to be inserted into a page markdown file.
|
|
20
26
|
|
|
21
|
-
The markdown partials directory's default location is
|
|
27
|
+
The markdown partials directory's default location is `./src/markdown-library/`. The partials directory can be set via the libraryPath option.
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.use(ignore([
|
|
29
|
-
'library/*'
|
|
30
|
-
]))
|
|
31
|
-
...
|
|
32
|
-
````
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
$ npm install --save metalsmith-markdown-partials
|
|
33
|
+
```
|
|
33
34
|
|
|
34
35
|
## Usage
|
|
35
|
-
|
|
36
|
+
|
|
37
|
+
```js
|
|
36
38
|
var mdPartials = require('metalsmith-markdown-partials');
|
|
37
39
|
|
|
38
40
|
...
|
|
39
|
-
.use(mdPartials({
|
|
41
|
+
.use(mdPartials({
|
|
42
|
+
libraryPath: './markdown-partials/',
|
|
43
|
+
fileSuffix: '.md.njk',
|
|
44
|
+
}))
|
|
40
45
|
...
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Options
|
|
50
|
+
|
|
51
|
+
**libraryPath**
|
|
52
|
+
|
|
53
|
+
The default libraryPath is `./markdown-partials/`. This default assumes that all pages are located in `./src/` so the markdown partials are located inside the metalsmith source directory.
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
const mdPartials = require('metalsmith-markdown-partials');
|
|
57
|
+
|
|
58
|
+
metalsmith(__dirname)
|
|
59
|
+
.use(mdPartials({
|
|
60
|
+
libraryPath: './markdown-partials/'
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**fileSuffix**
|
|
65
|
+
|
|
66
|
+
The default fileSuffix is `.md`, but depending on which templating language is used, the suffix will have two parts. For example for Nunjucks it will be `md.njk`.
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
const mdPartials = require('metalsmith-markdown-partials').use(
|
|
70
|
+
mdPartials({
|
|
71
|
+
fileSuffix: '.md.njk'
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## How it works
|
|
43
77
|
|
|
44
78
|
### index.md
|
|
45
79
|
|
|
46
|
-
|
|
80
|
+
```markdown
|
|
47
81
|
# This is an Example Page
|
|
48
82
|
|
|
49
83
|
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec id elit non mi porta gravida at eget metus. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.
|
|
50
84
|
|
|
51
|
-
{
|
|
85
|
+
{#md "example_partial.md" #}
|
|
52
86
|
|
|
53
87
|
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
|
|
54
|
-
|
|
88
|
+
```
|
|
55
89
|
|
|
56
90
|
### example_partial.md
|
|
57
91
|
|
|
58
|
-
|
|
92
|
+
```markdown
|
|
59
93
|
## Inserted Content
|
|
94
|
+
|
|
60
95
|
Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nulla vitae elit libero, a pharetra augue.
|
|
61
|
-
|
|
96
|
+
```
|
|
62
97
|
|
|
63
98
|
### index.html
|
|
64
|
-
|
|
99
|
+
|
|
100
|
+
```html
|
|
65
101
|
<h1>This is an Example Page</h1>
|
|
66
102
|
|
|
67
|
-
<p>
|
|
103
|
+
<p>
|
|
104
|
+
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec id elit non mi porta
|
|
105
|
+
gravida at eget metus. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec
|
|
106
|
+
elit.
|
|
107
|
+
</p>
|
|
68
108
|
|
|
69
109
|
<h2>Inserted Content</h2>
|
|
70
110
|
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nulla vitae elit libero, a pharetra augue.</p>
|
|
71
111
|
|
|
72
|
-
<p>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
112
|
+
<p>
|
|
113
|
+
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
|
|
114
|
+
Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Cum sociis natoque penatibus et magnis dis
|
|
115
|
+
parturient montes, nascetur ridiculus mus.
|
|
116
|
+
</p>
|
|
117
|
+
```
|
|
76
118
|
|
|
119
|
+
## Credits
|
|
77
120
|
|
|
121
|
+
- [werner@glinka.co](https://github.com/wernerglinka)
|
|
78
122
|
|
|
123
|
+
## License
|
|
79
124
|
|
|
125
|
+
Code released under [the ISC license](https://github.com/wernerglinka/metalsmith-markdown-partials/blob/main/LICENSE).
|
|
80
126
|
|
|
81
127
|
|
|
128
|
+
[npm-badge]: https://img.shields.io/npm/v/metalsmith-markdown-partials.svg
|
|
129
|
+
[npm-url]: https://www.npmjs.com/package/metalsmith-markdown-partials
|
|
130
|
+
[metalsmith-badge]: https://img.shields.io/badge/metalsmith-plugin-green.svg?longCache=true
|
|
131
|
+
[metalsmith-url]: https://metalsmith.io
|
|
132
|
+
[license-badge]: https://img.shields.io/github/license/wernerglinka/metalsmith-markdown-partials
|
|
133
|
+
[license-url]: LICENSE
|
package/coverage.info
ADDED
|
File without changes
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef Options
|
|
3
|
+
* @property {String} key
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** @type {Options} */
|
|
7
|
+
const defaults = {
|
|
8
|
+
libraryPath: './src/content/md-library/',
|
|
9
|
+
fileSuffix: '.md'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Normalize plugin options
|
|
14
|
+
* @param {Options} [options]
|
|
15
|
+
* @returns {Object}
|
|
16
|
+
*/
|
|
17
|
+
function normalizeOptions(options) {
|
|
18
|
+
return Object.assign({}, defaults, options || {});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* getMarkdownIncludes
|
|
23
|
+
* Get include markdown markers and replacements
|
|
24
|
+
*
|
|
25
|
+
* @param {[Object]} files - the metalsmith file object
|
|
26
|
+
* @param {Options} options
|
|
27
|
+
*
|
|
28
|
+
* @return {[Array]} Array with all markdown include objects
|
|
29
|
+
*/
|
|
30
|
+
function getMarkdownIncludes(files, options) {
|
|
31
|
+
const markdownIncludes = [];
|
|
32
|
+
|
|
33
|
+
// get the library name
|
|
34
|
+
const libraryPath = options.libraryPath.slice(0, -1).split("/");
|
|
35
|
+
const libraryName = libraryPath[libraryPath.length - 1];
|
|
36
|
+
|
|
37
|
+
Object.keys(files).forEach(function (file) {
|
|
38
|
+
/*
|
|
39
|
+
* checks if string 'file' ends with options.fileSuffix
|
|
40
|
+
* when metalsmith-in-place or metalsmith-layouts are used
|
|
41
|
+
* the suffix depends on what templating language is used
|
|
42
|
+
* for example with Nunjucks it would be .md.njk
|
|
43
|
+
*
|
|
44
|
+
* Also check that file does NOT start with libraryName as
|
|
45
|
+
* the markdown partials library is also located in the content
|
|
46
|
+
* folder
|
|
47
|
+
*/
|
|
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
|
+
});
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Remove markdown-partials from metalsmith build process
|
|
79
|
+
Object.keys(files).forEach(function (file) {
|
|
80
|
+
if (file.startsWith(libraryName)) {
|
|
81
|
+
delete files[file];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return markdownIncludes
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* resolveMarkdownIncludes
|
|
90
|
+
* Replace markers with their markdown replacement strings
|
|
91
|
+
*
|
|
92
|
+
* @param {[Object]} files - the metalsmith file object
|
|
93
|
+
* @param {[Array]} markdownIncludes with all markdown include objects
|
|
94
|
+
* @return {[void]}
|
|
95
|
+
*/
|
|
96
|
+
function resolveMarkdownIncludes(files, markdownIncludes) {
|
|
97
|
+
// replace all markers with their markdown replacements
|
|
98
|
+
markdownIncludes.forEach(function(markdownInclude) {
|
|
99
|
+
|
|
100
|
+
const fileData = files[markdownInclude.file];
|
|
101
|
+
|
|
102
|
+
// replace the include marker with the actual include file content
|
|
103
|
+
try {
|
|
104
|
+
const contents = fileData.contents.toString();
|
|
105
|
+
fileData.contents = Buffer.from(contents.replace(markdownInclude.marker, markdownInclude.markerReplacement));
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.error(e);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A Metalsmith plugin to merge markdown partials into main markdown file
|
|
115
|
+
*
|
|
116
|
+
* A marker of the form {#md "<file name>.md" #} indicates where the partial
|
|
117
|
+
* must be inserted and also provides the file name of the replacement markdown.
|
|
118
|
+
*
|
|
119
|
+
* @param {Options} options
|
|
120
|
+
* @returns {import('metalsmith').Plugin}
|
|
121
|
+
*/
|
|
122
|
+
|
|
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);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = initMarkdownPartials;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,28 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metalsmith-markdown-partials",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "A Metalsmith plugin that allows the use of partial markdowm files",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
5
|
+
"keywords": [
|
|
6
|
+
"metalsmith-plugin",
|
|
7
|
+
"metalsmith",
|
|
8
|
+
"markdown",
|
|
9
|
+
"markdown-partials",
|
|
10
|
+
"static-site"
|
|
11
|
+
],
|
|
12
|
+
"main": "lib/index.js",
|
|
9
13
|
"repository": {
|
|
10
14
|
"type": "git",
|
|
11
15
|
"url": "git+https://github.com/wernerglinka/metalsmith-markdown-partials.git"
|
|
12
16
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
],
|
|
18
|
-
"author": [
|
|
19
|
-
{ "name": "Werner Glinka",
|
|
20
|
-
"email": "werner@glinka.co"
|
|
21
|
-
}
|
|
22
|
-
],
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Werner Glinka",
|
|
19
|
+
"email": "werner@glinka.co"
|
|
20
|
+
},
|
|
23
21
|
"license": "MIT",
|
|
24
22
|
"bugs": {
|
|
25
23
|
"url": "https://github.com/wernerglinka/metalsmith-markdown-partials/issues"
|
|
26
24
|
},
|
|
27
|
-
"homepage": "https://github.com/wernerglinka/metalsmith-markdown-partials#readme"
|
|
25
|
+
"homepage": "https://github.com/wernerglinka/metalsmith-markdown-partials#readme",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"debug": "^4.3.3"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"auto-changelog": "^2.4.0",
|
|
31
|
+
"chai": "^4.3.6",
|
|
32
|
+
"coveralls": "^3.1.1",
|
|
33
|
+
"eslint": "^8.4.1",
|
|
34
|
+
"eslint-config-prettier": "^8.3.0",
|
|
35
|
+
"metalsmith": "^2.4.1",
|
|
36
|
+
"mocha": "^9.2.0",
|
|
37
|
+
"nyc": "^15.1.0",
|
|
38
|
+
"prettier": "^2.5.1",
|
|
39
|
+
"release-it": "^14.12.4"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"metalsmith": "^2.4.1"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"changelog": "auto-changelog -u date --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release)'",
|
|
46
|
+
"format": "prettier --write \"**/*.{yml,md,js,json}\"",
|
|
47
|
+
"lint": "eslint --cache --fix-dry-run .",
|
|
48
|
+
"release": "release-it .",
|
|
49
|
+
"test": "nyc mocha ./tests/index.js"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=8"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
}
|
|
28
57
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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.
|
|
@@ -0,0 +1,11 @@
|
|
|
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.
|
|
@@ -0,0 +1,9 @@
|
|
|
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.
|
|
@@ -0,0 +1,3 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* global describe, it */
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const chai = require('chai');
|
|
6
|
+
const metalsmith = require('metalsmith');
|
|
7
|
+
const mdPartials = require('../lib');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const expect = chai.expect;
|
|
11
|
+
|
|
12
|
+
const fixture = path.resolve.bind(path, __dirname, 'fixtures');
|
|
13
|
+
|
|
14
|
+
function file(_path) {
|
|
15
|
+
return fs.readFileSync(fixture(_path), 'utf8');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('metalsmith-markdown-partials', () => {
|
|
19
|
+
|
|
20
|
+
it('should replace marker with markdown partial', done => {
|
|
21
|
+
|
|
22
|
+
metalsmith(fixture())
|
|
23
|
+
.use(mdPartials({
|
|
24
|
+
libraryPath: path.join(fixture(), `/src/md-partials/`),
|
|
25
|
+
fileSuffix: '.md',
|
|
26
|
+
}))
|
|
27
|
+
.build( err => {
|
|
28
|
+
if (err) {
|
|
29
|
+
return done(err);
|
|
30
|
+
}
|
|
31
|
+
expect(file('build/markdown.md')).to.be.eql(file('expected/final-markdown.md'));
|
|
32
|
+
|
|
33
|
+
done();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
package/.npmignore
DELETED
package/index.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
var fs = require('fs');
|
|
3
|
-
|
|
4
|
-
module.exports = plugin;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Metalsmith plugin to merge markdown partials into main markdown file
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
function plugin(options){
|
|
11
|
-
options = options || {};
|
|
12
|
-
|
|
13
|
-
return function(files, metalsmith, done){
|
|
14
|
-
setImmediate(done);
|
|
15
|
-
|
|
16
|
-
Object.keys(files).forEach(function(file){
|
|
17
|
-
|
|
18
|
-
// exit if this file is not a markdown file
|
|
19
|
-
var fileExtension = file.split('.').pop();
|
|
20
|
-
if ( fileExtension !== 'md') return;
|
|
21
|
-
|
|
22
|
-
// get the file data and convert to string
|
|
23
|
-
var fileData = files[file];
|
|
24
|
-
|
|
25
|
-
// get all include markers for this file
|
|
26
|
-
var markers = getIncludes(fileData);
|
|
27
|
-
|
|
28
|
-
// replace all include markers with their respective file content
|
|
29
|
-
if (markers.length) {
|
|
30
|
-
resolveIncludes(fileData, markers, options);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* getIncludes
|
|
38
|
-
* function to extract all include markers from the file contents
|
|
39
|
-
* @param {[string]} str - the file contents in string form
|
|
40
|
-
* @return {[array]} markers - the start and end indexes for all include markers
|
|
41
|
-
*/
|
|
42
|
-
function getIncludes(fileData) {
|
|
43
|
-
var str = fileData.contents.toString();
|
|
44
|
-
var markers = [];
|
|
45
|
-
var previousMarker, i;
|
|
46
|
-
var temp = [];
|
|
47
|
-
// get any include marker
|
|
48
|
-
var newMarker = str.indexOf('{{md');
|
|
49
|
-
|
|
50
|
-
if ( newMarker > -1 ) {
|
|
51
|
-
// get the number of partials in this file
|
|
52
|
-
var count = (str.match(/{{md/g) || []).length;
|
|
53
|
-
|
|
54
|
-
// get the marker boundaries for this file
|
|
55
|
-
// a marker looks like this: {{md "<partial name>.md"}}
|
|
56
|
-
for(i = 0; count > i; i++) {
|
|
57
|
-
// get the marker pair
|
|
58
|
-
temp.push(newMarker);
|
|
59
|
-
previousMarker = newMarker;
|
|
60
|
-
// find the closing brackets '}}'
|
|
61
|
-
newMarker = str.indexOf('}}', previousMarker) + 2;
|
|
62
|
-
temp.push(newMarker);
|
|
63
|
-
// push marker pair into markers array
|
|
64
|
-
markers.push(temp);
|
|
65
|
-
temp = [];
|
|
66
|
-
previousMarker = newMarker;
|
|
67
|
-
newMarker = str.indexOf('{{md', previousMarker);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return markers;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* resolveIncludes
|
|
76
|
-
* function to replace all include markers with their respective files content
|
|
77
|
-
* @param {[object]} fileData - the file being processed as an object
|
|
78
|
-
* @param {[array]} markers - the start and end indexes for all include markers
|
|
79
|
-
* @param {[object]} options - plugin options. in this case the path to the directory that holds all the markdown includes
|
|
80
|
-
* @return {[void]}
|
|
81
|
-
*/
|
|
82
|
-
function resolveIncludes(fileData, markers, options) {
|
|
83
|
-
var filePath, replaceThis;
|
|
84
|
-
var str = fileData.contents.toString();
|
|
85
|
-
|
|
86
|
-
for (i = 0; markers.length > i; i++) {
|
|
87
|
-
// get the whole marker string
|
|
88
|
-
filePath = str.substring(markers[i][0], markers[i][1]);
|
|
89
|
-
// keep the include market string for later replace
|
|
90
|
-
replaceThis = filePath;
|
|
91
|
-
// replace single quotes with double quotes... just in case
|
|
92
|
-
filePath = filePath.replace(/'/g, '"');
|
|
93
|
-
// get the path inside the marker between the quotes
|
|
94
|
-
filePath = filePath.match(/"([^"]+)"/)[1];
|
|
95
|
-
|
|
96
|
-
// get the file content synchronously
|
|
97
|
-
var libPath = options.libraryPath || './dev/content/library/'
|
|
98
|
-
try {
|
|
99
|
-
var data = fs.readFileSync(libPath + filePath, 'utf8');
|
|
100
|
-
} catch(e) {
|
|
101
|
-
console.log('Error:', e.stack);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// replace the include marker with the actual include file content
|
|
105
|
-
try {
|
|
106
|
-
var contents = fileData.contents.toString();
|
|
107
|
-
fileData.contents = new Buffer(contents.replace(replaceThis, data));
|
|
108
|
-
} catch (e) {
|
|
109
|
-
console.error(e);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|