markdown_link_checker_sc 0.0.132 → 0.0.134
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/index.js +40 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -130,6 +130,39 @@ async function loadJSONFileToReportOn(filePath) {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
// Function for loading JSON file that contains files to ignore (such as _summary.md)
|
|
134
|
+
// This will be in _link_checker_sc/ignorelist.json relative to root.
|
|
135
|
+
async function loadJSONFileToIgnore(filePath) {
|
|
136
|
+
sharedData.options.log.includes("functions")
|
|
137
|
+
? console.log(`Function: loadJSONFileToIgnore(): filePath: ${filePath}`)
|
|
138
|
+
: null;
|
|
139
|
+
sharedData.options.log.includes("quick")
|
|
140
|
+
? console.log(`Function: loadJSONFileToIgnore(): filePath: ${filePath}`)
|
|
141
|
+
: null;
|
|
142
|
+
try {
|
|
143
|
+
const fileContent = await fs.promises.readFile(filePath, "utf8");
|
|
144
|
+
let filesArray = JSON.parse(fileContent);
|
|
145
|
+
if (filesArray.length == 0) {
|
|
146
|
+
return [];
|
|
147
|
+
} else {
|
|
148
|
+
// Array relative to root, so update to have full path
|
|
149
|
+
filesArray = filesArray.map((str) =>
|
|
150
|
+
path.join(sharedData.options.root, str)
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
sharedData.options.log.includes("quick")
|
|
155
|
+
? console.log(`quick:filesArray: ${filesArray}`)
|
|
156
|
+
: null;
|
|
157
|
+
|
|
158
|
+
return filesArray;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error(`Error reading file: ${error.message}`);
|
|
161
|
+
console.log(`Error reading file: ${error.message}`);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
133
166
|
const replaceDelimiter = (str, underscore) =>
|
|
134
167
|
underscore ? str.replace(/\s+/g, "_") : str.replace(/\s+/g, "-");
|
|
135
168
|
|
|
@@ -174,6 +207,9 @@ const processDirectory = async (dir) => {
|
|
|
174
207
|
if (files[i].isDirectory()) {
|
|
175
208
|
const subResults = await processDirectory(file);
|
|
176
209
|
results.push(...subResults);
|
|
210
|
+
} else if (sharedData.options.ignoreFiles.includes(file)) {
|
|
211
|
+
// do nothing
|
|
212
|
+
// console.log(`XxxxXignorelist: file: ${file}`);
|
|
177
213
|
} else if (isMarkdown(file)) {
|
|
178
214
|
sharedData.allMarkdownFiles.add(file);
|
|
179
215
|
const result = await processFile(file);
|
|
@@ -203,6 +239,10 @@ const processDirectory = async (dir) => {
|
|
|
203
239
|
))
|
|
204
240
|
: (sharedData.options.files = []);
|
|
205
241
|
|
|
242
|
+
sharedData.options.ignoreFiles = await loadJSONFileToIgnore(
|
|
243
|
+
"_link_checker_sc/ignorefile.json"
|
|
244
|
+
);
|
|
245
|
+
|
|
206
246
|
// process containing markdown, return results which includes links, headings, id anchors
|
|
207
247
|
const results = await processDirectory(markdownDirectory);
|
|
208
248
|
|