From a47f6cda34ee5a59be88d30e21838037b10012d4 Mon Sep 17 00:00:00 2001 From: Tom Collins Date: Fri, 3 Feb 2023 08:52:13 +0000 Subject: [PATCH] Improve path handling when creating docs index. --- gh-pages/examples/examples-index.md | 6 +++--- lib/json-schema-static-docs.js | 3 +++ lib/renderer/index.js | 14 ++++---------- package.json | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/gh-pages/examples/examples-index.md b/gh-pages/examples/examples-index.md index 03123d6..8c7bf87 100644 --- a/gh-pages/examples/examples-index.md +++ b/gh-pages/examples/examples-index.md @@ -5,11 +5,11 @@ - [oneof.html](oneof.html) - [person.html](person.html) -## Draft-06 -- [draft-06/animal.html](draft-06/animal.html) - ## Draft-07 - [draft-07/user.html](draft-07/user.html) +## Draft-06 +- [draft-06/animal.html](draft-06/animal.html) + ## Draft-2019-09 - [draft-2019-09/array.html](draft-2019-09/array.html) diff --git a/lib/json-schema-static-docs.js b/lib/json-schema-static-docs.js index 36fc6b6..2d56dc5 100644 --- a/lib/json-schema-static-docs.js +++ b/lib/json-schema-static-docs.js @@ -28,6 +28,9 @@ const defaultOptions = { var JsonSchemaStaticDocs = function (options) { this._options = extend(true, defaultOptions, options); + + this._options.inputPath = this._options.inputPath.replace(/\/$/, ""); + this._options.outputPath = this._options.outputPath.replace(/\/$/, ""); }; JsonSchemaStaticDocs.prototype.generate = async function () { diff --git a/lib/renderer/index.js b/lib/renderer/index.js index 23440ea..b825122 100644 --- a/lib/renderer/index.js +++ b/lib/renderer/index.js @@ -3,15 +3,7 @@ const path = require("path"); const fg = require("fast-glob"); const removeSourcePathPrefix = (filename, sourcePath) => { - let result = filename - .replace( - new RegExp( - `/Users/collinst/Workspace/json-schema-static-docs/gh-pages/examples` - ), - "" - ) - .replace(/^\//, ""); - + let result = filename.replace(new RegExp(sourcePath), "").replace(/^\//, ""); return result; }; @@ -99,7 +91,9 @@ const sortFilenames = (filenames) => { const createIndex = async (indexPath, sourcePath, options) => { options = options || {}; - let files = await fg([sourcePath + "/**"]); + const globPattern = path.join(sourcePath, "/**"); + + let files = await fg([globPattern]); files = sortFilenames(files); let title = options.title || "Index of Schema"; diff --git a/package.json b/package.json index 19c1c68..bba1de6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "json-schema-static-docs", - "version": "0.22.0", + "version": "0.22.1", "description": "Generates static documentation for humans based on the contents of JSON schema files (yml or json).", "main": "lib/json-schema-static-docs.js", "bin": {