hdoc-tools 0.54.0 → 0.55.0

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.
@@ -33,6 +33,47 @@ function escape_html(str) {
33
33
  .replace(/>/g, ">");
34
34
  }
35
35
 
36
+ // Recursively walk <source_path>/<docId>/_inline building the nav fragment
37
+ // consumed by the viewer's nav-section-component. Subfolders become
38
+ // expandable container nodes (items, no link); files become leaf links.
39
+ function build_inline_nav_items(dir, docId, rel_prefix) {
40
+ const items = [];
41
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
42
+ if (entry.isDirectory()) {
43
+ items.push({
44
+ text: entry.name,
45
+ expand: false,
46
+ items: build_inline_nav_items(
47
+ path.join(dir, entry.name),
48
+ docId,
49
+ `${rel_prefix}${entry.name}/`,
50
+ ),
51
+ });
52
+ } else {
53
+ const name = entry.name.replace(path.extname(entry.name), "");
54
+ items.push({
55
+ text: name,
56
+ link: `${docId}/_inline/${rel_prefix}${name}`,
57
+ });
58
+ }
59
+ }
60
+ return items;
61
+ }
62
+
63
+ // Build the top-level "Inline Help Items" nav fragment for a book, or {}
64
+ // if the book has no _inline folder.
65
+ function build_nav_inline(source_path, docId) {
66
+ const inline_path = path.join(source_path, docId, "_inline");
67
+ if (!fs.existsSync(inline_path)) return {};
68
+ return {
69
+ text: "Inline Help Items",
70
+ expand: true,
71
+ inline: true,
72
+ items: build_inline_nav_items(inline_path, docId, ""),
73
+ };
74
+ }
75
+ exports.build_nav_inline = build_nav_inline;
76
+
36
77
  // Build a content handler bound to a single book's context.
37
78
  //
38
79
  // ctx:
package/hdoc-edit.js CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  const sha1 = (data) =>
27
27
  crypto.createHash("sha1").update(Buffer.from(data)).digest("hex");
28
- const { create_content_handler } = require(
28
+ const { create_content_handler, build_nav_inline } = require(
29
29
  path.join(__dirname, "hdoc-content-routes.js"),
30
30
  );
31
31
  const { TocModel } = require(path.join(__dirname, "hdoc-toc.js"));
@@ -184,17 +184,7 @@
184
184
  );
185
185
 
186
186
  // Inline-help nav fragment, surfaced via /_books/library.json.
187
- let inline = {};
188
- const inline_path = path.join(sp, id, "_inline");
189
- if (fs.existsSync(inline_path)) {
190
- inline = { text: "Inline Help Items", expand: true, inline: true, items: [] };
191
- for (const file of fs.readdirSync(inline_path)) {
192
- inline.items.push({
193
- text: file.replace(path.extname(file), ""),
194
- link: `${id}/_inline/${file.replace(path.extname(file), "")}`,
195
- });
196
- }
197
- }
187
+ const inline = build_nav_inline(sp, id);
198
188
 
199
189
  source_path = sp;
200
190
  hdocbook_project = proj;
package/hdoc-serve.js CHANGED
@@ -4,7 +4,7 @@
4
4
  const fs = require("node:fs");
5
5
  const path = require("node:path");
6
6
  const hdoc = require(path.join(__dirname, "hdoc-module.js"));
7
- const { create_content_handler } = require(
7
+ const { create_content_handler, build_nav_inline } = require(
8
8
  path.join(__dirname, "hdoc-content-routes.js"),
9
9
  );
10
10
 
@@ -59,23 +59,7 @@
59
59
  docId = hdocbook_project.docId;
60
60
 
61
61
  // Get inline content for nav
62
- const inline_path = path.join(source_path, docId, "_inline");
63
- let nav_inline = {};
64
- if (fs.existsSync(inline_path)) {
65
- const inline_files = fs.readdirSync(inline_path);
66
- nav_inline = {
67
- text: "Inline Help Items",
68
- expand: true,
69
- inline: true,
70
- items: [],
71
- };
72
- for (const file of inline_files) {
73
- nav_inline.items.push({
74
- text: file.replace(path.extname(file), ""),
75
- link: `${docId}/_inline/${file.replace(path.extname(file), "")}`,
76
- });
77
- }
78
- }
62
+ const nav_inline = build_nav_inline(source_path, docId);
79
63
  // Get an express server instance
80
64
  const app = express();
81
65
 
@@ -135,10 +119,10 @@
135
119
  });
136
120
 
137
121
  const server = app.listen(port, "0.0.0.0", () => {
138
- const host = server.address().address;
139
- const port = server.address().port;
122
+ const addr = server.address();
123
+ if (!addr) return;
140
124
 
141
- console.log("Server listening at http://127.0.0.1:%s", port);
125
+ console.log("Server listening at http://127.0.0.1:%s", addr.port);
142
126
  console.log(`Document source path is: ${source_path}`);
143
127
 
144
128
  const _vars = ["{{DOC_ID}}", "{{BUILD_NUMBER}}", "{{BUILD_DATE}}"];
@@ -148,6 +132,15 @@
148
132
  console.log(" ", name, " = ", hdoc.expand_variables(name, docId));
149
133
  }
150
134
  });
135
+
136
+ server.on("error", (err) => {
137
+ if (err.code === "EADDRINUSE") {
138
+ console.error(`\nPort ${port} is already in use. Pick a different port with -port.\n`);
139
+ } else {
140
+ console.error(`\nServer error: ${err}\n`);
141
+ }
142
+ process.exit(1);
143
+ });
151
144
  };
152
145
 
153
146
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.54.0",
3
+ "version": "0.55.0",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {