Skip to content

Commit 43c3e1c

Browse files
committed
fix: replacing optional graph arr with graph file path
1 parent 8eab577 commit 43c3e1c

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

Diff for: readme.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,19 @@ customElements.define('eve-app', AppComponent);
117117

118118
## Advanced Options
119119

120-
If you want to pre-scaffold an application with a graph of all md files paths and add your own generated labels(removing the need to cite label in each of the file's front-matter), you can create a graph object then add it to to the options of the loader e.g.
120+
If you want to pre-scaffold an application with a graph of all md files paths and add your own generated labels(removing the need to cite label in each of the file's front-matter), you can create a graph array, write the serialized json to a cache file, then add the path of that .json file to the options of the loader e.g.
121121

122-
graph object:
122+
graph.json file:
123123

124124
```js
125-
const graph = [
125+
[
126126
{
127-
filePath: '/home/user/workspace/app/src/pages/mypage.md'
128-
label: 'some-generated-label-asjhfkawa'
127+
"filePath": "/home/user/workspace/app/src/pages/mypage.md"
128+
"label": "some-generated-label-asjhfkawa"
129129
},
130130
{
131-
filePath: '/home/user/workspace/app/src/pages/myotherpage.md'
132-
label: 'some-generated-label-jkhkdsfskwad'
131+
"filePath": "/home/user/workspace/app/src/pages/myotherpage.md"
132+
"label": "some-generated-label-jkhkdsfskwad"
133133
}
134134
]
135135
```
@@ -143,7 +143,7 @@ module: {
143143
test: /\.md$/,
144144
loader: 'wc-markdown-loader',
145145
options: {
146-
graph
146+
graph: path.join(__dirname, 'graph.json')
147147
}
148148
}
149149
]

Diff for: src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const fs = require('fs');
34
const { getOptions } = require('loader-utils');
45
const validateOptions = require('schema-utils');
56
const build = require('./build.js');
@@ -18,7 +19,8 @@ module.exports = async function loader(content) {
1819
validateOptions(schema, options, 'wc-markdown-loader');
1920

2021
if (Object.keys(options).length > 0 && options.graph.length > 0) {
21-
elementLabel = options.graph.filter(page => page.filePath === this.resourcePath)[0].label;
22+
const graph = JSON.parse(fs.readFileSync(options.graph, 'utf8'));
23+
elementLabel = graph.filter(page => page.filePath === this.resourcePath)[0].label;
2224
}
2325
parser.parse(content)
2426
.then(markdown => build(markdown, elementLabel))

Diff for: src/options.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"type": "object",
33
"properties": {
44
"graph": {
5-
"type": [ "array" ]
5+
"type": [ "string" ]
66
}
77
},
88
"errorMessage": {
9-
"test": "should be {array})"
9+
"test": "should be {string})"
1010
},
1111
"additionalProperties": false
1212
}

0 commit comments

Comments
 (0)