markdown_link_checker_sc 0.0.137 → 0.0.139

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
@@ -30,6 +30,18 @@ Options:
30
30
  -h, --help display help for command
31
31
  ```
32
32
 
33
+ ## Ignore file
34
+
35
+ You can create a `_link_checker_sc\ignorefile.json` in the docs (path specified by `-d`) that lists any files you want to avoid parsing.
36
+ This is a JSON array of file paths relative the the docsroot.
37
+
38
+ For example, to not parse `en/_sidebar.md` your ignore file would have this pattern:
39
+
40
+ ```
41
+ ["en/_sidebar.md"]
42
+ ```
43
+
44
+ Note that a missing ignorefile is not an error.
33
45
 
34
46
  ## What link formats can it match
35
47
 
package/index.js CHANGED
@@ -3,9 +3,7 @@
3
3
  import fs from "fs";
4
4
  import path from "path";
5
5
  import { sharedData } from "./src/shared_data.js";
6
- //const path = require("path");
7
6
  import { program } from "commander";
8
- //const { program } = require("commander");
9
7
  import {
10
8
  logFunction,
11
9
  logToFile,
@@ -21,6 +19,7 @@ import { processMarkdown } from "./src/process_markdown.js";
21
19
  import { processRelativeLinks } from "./src/process_relative_links.js";
22
20
  import { checkLocalImageLinks } from "./src/process_local_image_links.js";
23
21
  import { processUrlsToLocalSource } from "./src/process_internal_url_links.js";
22
+ import { processExternalUrlLinks } from "./src/process_external_url_links.js";
24
23
  import {
25
24
  checkPageOrphans,
26
25
  getPageWithMostLinks,
@@ -36,7 +35,7 @@ program
36
35
  )
37
36
  .option(
38
37
  "-d, --doc [directory]",
39
- "Docs root directory, relative to -g (such as `docs`). Defaults to '' (all docs in root of repo). Use -d as well to restrict search to a particular subfolder. Defaults to current directory.",
38
+ "Docs root directory, relative to -r (such as `docs`). Defaults to '' (all docs in root of repo). Use -d as well to restrict search to a particular subfolder. Defaults to current directory.",
40
39
  process.cwd()
41
40
  )
42
41
  .option(
@@ -88,6 +87,7 @@ program
88
87
  "Detect anchors in heading such as: # Heading {#anchor}",
89
88
  true
90
89
  )
90
+ .option("-x, --externallink [value]", "Output logs to file", false)
91
91
  .parse(process.argv);
92
92
 
93
93
  // TODO PX4 special parsing - errors or pages we exclude by default.
@@ -101,9 +101,20 @@ sharedData.allHTMLFiles = new Set([]);
101
101
  sharedData.allImageFiles = new Set([]);
102
102
  sharedData.allOtherFiles = new Set([]);
103
103
 
104
- //console.log(`debug: sharedData.options.repo: ${sharedData.options.repo}`);
105
- //console.log(`debug: sharedData.options.doc: ${sharedData.options.doc}`);
106
- //console.log(`debug: sharedData.options.subdir: ${sharedData.options.subdir}`);
104
+ function resolveRepoPath(repoOption) {
105
+ // This gets the path from CWD by default, or resolves path up.
106
+ if (!repoOption || repoOption === ".") {
107
+ return process.cwd(); // Current working directory (Node.js)
108
+ }
109
+
110
+ if (repoOption === "..") {
111
+ return path.resolve(process.cwd(), ".."); // One directory up
112
+ }
113
+
114
+ return path.resolve(repoOption); // Resolve to absolute path
115
+ }
116
+
117
+ sharedData.options.repo = resolveRepoPath(sharedData.options.repo);
107
118
 
108
119
  sharedData.options.docsroot = path.join(
109
120
  sharedData.options.repo,
@@ -179,8 +190,8 @@ async function loadJSONFileToIgnore(filePath) {
179
190
 
180
191
  return filesArray;
181
192
  } catch (error) {
182
- //console.error(`Error reading file: ${error.message}`);
183
- console.log(`Error reading ignore file: ${error.message}`);
193
+ //console.log(`Error reading ignore file: ${error.message}`);
194
+ //Note, ignore file is private really.
184
195
  return [];
185
196
  //process.exit(1);
186
197
  }
@@ -272,7 +283,7 @@ const processDirectory = async (dir) => {
272
283
  pathToJsonIgnoreFile
273
284
  );
274
285
 
275
- // process containing markdown, return results which includes links, headings, id anchors
286
+ // process containing markdown, return results which includes links, headings, id anchors
276
287
  const results = await processDirectory(sharedData.options.markdownroot);
277
288
 
278
289
  if (!results.allErrors) {
@@ -316,6 +327,13 @@ const processDirectory = async (dir) => {
316
327
  const errorsGlobalImageOrphanCheck = await checkImageOrphansGlobal(results);
317
328
  results["allErrors"].push(...errorsGlobalImageOrphanCheck);
318
329
 
330
+ // Process links to externalURLs.
331
+ if (sharedData.options.externallink) {
332
+ const errorsFromExternalUrlLinks = await processExternalUrlLinks(results);
333
+ //console.log( `debug: errorsFromExternalUrlLinks: ${errorsFromExternalUrlLinks}` );
334
+ results["allErrors"].push(...errorsFromExternalUrlLinks);
335
+ }
336
+
319
337
  // Filter the errors based on the settings in options.
320
338
  // At time of writing just filters on specific set of pages.
321
339
  let filteredResults = filterErrors(results.allErrors);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown_link_checker_sc",
3
- "version": "0.0.137",
3
+ "version": "0.0.139",
4
4
  "description": "Markdown Link Checker",
5
5
  "main": "index.js",
6
6
  "scripts": {