markdown_link_checker_sc 0.0.120 → 0.0.121

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.
Files changed (3) hide show
  1. package/index.js +4 -80
  2. package/package.json +1 -1
  3. package/src/filters.js +83 -0
package/index.js CHANGED
@@ -6,7 +6,8 @@ import { sharedData } from "./src/shared_data.js";
6
6
  //const path = require("path");
7
7
  import { program } from "commander";
8
8
  //const { program } = require("commander");
9
- import { logToFile, isMarkdown, isHTML, isImage } from "./src/helpers.js";
9
+ import { logFunction, logToFile, isMarkdown, isHTML, isImage } from "./src/helpers.js";
10
+
10
11
  import { outputErrors } from "./src/output_errors.js";
11
12
 
12
13
  import { slugifyVuepress } from "./src/slugify.js";
@@ -19,6 +20,8 @@ import {
19
20
  getPageWithMostLinks,
20
21
  } from "./src/process_orphans.js";
21
22
  import { checkImageOrphansGlobal } from "./src/process_image_orphans.js";
23
+ import { filterErrors, filterIgnoreErrors } from "./src/filters.js";
24
+
22
25
 
23
26
  program
24
27
  .option(
@@ -182,85 +185,6 @@ const processDirectory = async (dir) => {
182
185
  return results;
183
186
  };
184
187
 
185
- function filterIgnoreErrors(errors) {
186
- // This method removes any errors that are in the ignore errors list
187
- // This list is imported from the file _link_checker_sc/ignore_errors.json
188
-
189
- // Currently it is the pages to output, as listed in the options.files to output.
190
- sharedData.options.log.includes("functions")
191
- ? console.log(`Function: filterIgnoreErrors()`)
192
- : null;
193
-
194
- try {
195
- //sharedData.IgnoreErrors = require('./_link_checker_sc/ignore_errors.json');
196
- const ignoreFromFile = fs.readFileSync(
197
- "./_link_checker_sc/ignore_errors.json"
198
- );
199
- sharedData.IgnoreErrors = JSON.parse(ignoreFromFile);
200
- //console.log(sharedData.IgnoreErrors);
201
- } catch (error) {
202
- //console.log("probs loading");
203
- //console.log(error);
204
- sharedData.IgnoreErrors = [];
205
- }
206
-
207
- const filteredErrors = errors.filter((error) => {
208
-
209
- let returnValue = true; //All items are not filtered, by default.
210
- sharedData.IgnoreErrors.forEach((ignorableError) => {
211
- if (
212
- error.type === ignorableError.type &&
213
- error.fileRelativeToRoot === ignorableError.fileRelativeToRoot
214
- ) {
215
- // Same file and type, so probably filter out.
216
- if (!(error.link && ignorableError.link)) {
217
- returnValue = false; // Neither have a link, so we match on same type
218
- }
219
-
220
- if (
221
- error.link &&
222
- ignorableError.link &&
223
- error.link.url === ignorableError.link.url
224
- ) {
225
- returnValue = false; // They both have a link and it is the same link
226
- }
227
- }
228
-
229
-
230
- });
231
- //if (returnValue ==false) console.log(error);
232
- return returnValue;
233
- });
234
-
235
-
236
- return filteredErrors;
237
- }
238
-
239
- function filterErrors(errors) {
240
- // This method filters all errors against settings in the command line
241
- // Currently it is the pages to output, as listed in the options.files to output.
242
- sharedData.options.log.includes("functions")
243
- ? console.log(`Function: filterErrors()`)
244
- : null;
245
-
246
- let filteredErrors = errors;
247
- // Filter results on specified file names (if any specified)
248
- //console.log(`Number pages to filter: ${sharedData.options.files.length}`);
249
- if (sharedData.options.files.length > 0) {
250
- //console.log(`USharedFileslength: ${sharedData.options.files.length}`);
251
- filteredErrors = errors.filter((error) => {
252
- //console.log(`UError: ${error}`);
253
- //console.log(JSON.stringify(error, null, 2));
254
- //console.log(`UError file: ${error.file}`);
255
- const filterResult = sharedData.options.files.includes(error.file);
256
- return filterResult;
257
- });
258
- }
259
- // Filter on other things - such as errors.
260
-
261
- //console.log(filteredErrors);
262
- return filteredErrors;
263
- }
264
188
 
265
189
  //main function, after options et have been set up.
266
190
  (async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown_link_checker_sc",
3
- "version": "0.0.120",
3
+ "version": "0.0.121",
4
4
  "description": "Markdown Link Checker",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/filters.js ADDED
@@ -0,0 +1,83 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { sharedData } from "./shared_data.js";
4
+ import { logFunction } from "./helpers.js";
5
+
6
+ function filterIgnoreErrors(errors) {
7
+ // This method removes any errors that are in the ignore errors list
8
+ // This list is imported from the file _link_checker_sc/ignore_errors.json
9
+
10
+ // Currently it is the pages to output, as listed in the options.files to output.
11
+ logFunction(`Function: filterIgnoreErrors(${errors})`);
12
+ const errorFile = path.join(
13
+ sharedData.options.root,
14
+ "./_link_checker_sc/ignore_errors.json"
15
+ );
16
+ //console.log(errorFile);
17
+
18
+ try {
19
+ //sharedData.IgnoreErrors = require('./_link_checker_sc/ignore_errors.json');
20
+ const ignoreFromFile = fs.readFileSync(errorFile);
21
+ sharedData.IgnoreErrors = JSON.parse(ignoreFromFile);
22
+ //sharedData.options.log.includes("quick") ? console.log(sharedData.IgnoreErrors) : null;
23
+ } catch (error) {
24
+ sharedData.IgnoreErrors = [];
25
+ sharedData.options.log.includes("quick")
26
+ ? console.log("Error loading IgnoreErrors")
27
+ : null;
28
+ sharedData.options.log.includes("quick") ? console.log(error) : null;
29
+ }
30
+
31
+ const filteredErrors = errors.filter((error) => {
32
+ let returnValue = true; //All items are not filtered, by default.
33
+ sharedData.IgnoreErrors.forEach((ignorableError) => {
34
+ if (
35
+ error.type === ignorableError.type &&
36
+ error.fileRelativeToRoot === ignorableError.fileRelativeToRoot
37
+ ) {
38
+ // Same file and type, so probably filter out.
39
+ if (!(error.link && ignorableError.link)) {
40
+ returnValue = false; // Neither have a link, so we match on same type
41
+ }
42
+
43
+ if (
44
+ error.link &&
45
+ ignorableError.link &&
46
+ error.link.url === ignorableError.link.url
47
+ ) {
48
+ returnValue = false; // They both have a link and it is the same link
49
+ }
50
+ }
51
+ });
52
+ //if (returnValue ==false) console.log(error);
53
+ return returnValue;
54
+ });
55
+
56
+ return filteredErrors;
57
+ }
58
+
59
+ function filterErrors(errors) {
60
+ // This method filters all errors against settings in the command line
61
+ // Currently it is the pages to output, as listed in the options.files to output.
62
+ logFunction(`Function: filterErrors(${errors})`);
63
+
64
+ let filteredErrors = errors;
65
+ // Filter results on specified file names (if any specified)
66
+ //console.log(`Number pages to filter: ${sharedData.options.files.length}`);
67
+ if (sharedData.options.files.length > 0) {
68
+ //console.log(`USharedFileslength: ${sharedData.options.files.length}`);
69
+ filteredErrors = errors.filter((error) => {
70
+ //console.log(`UError: ${error}`);
71
+ //console.log(JSON.stringify(error, null, 2));
72
+ //console.log(`UError file: ${error.file}`);
73
+ const filterResult = sharedData.options.files.includes(error.file);
74
+ return filterResult;
75
+ });
76
+ }
77
+ // Filter on other things - such as errors.
78
+
79
+ //console.log(filteredErrors);
80
+ return filteredErrors;
81
+ }
82
+
83
+ export { filterErrors, filterIgnoreErrors };