hdoc-tools 0.47.4 → 0.48.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.
@@ -0,0 +1,134 @@
1
+ (() => {
2
+ const fs = require("node:fs");
3
+ const path = require("node:path");
4
+
5
+ // Replicates the URL normalisation logic from populate_index so page keys match.
6
+ function to_page_path(file) {
7
+ let p = file.relative_path.replaceAll("\\", "/");
8
+ if (
9
+ p.endsWith("/index.md") ||
10
+ p.endsWith("/index.html") ||
11
+ p.endsWith("/index.htm")
12
+ ) {
13
+ p = p.substring(0, p.lastIndexOf("/"));
14
+ }
15
+ return `/${p.replace(path.extname(file.relative_path), "")}`;
16
+ }
17
+
18
+ // Groups index_records into one entry per page, preserving section order.
19
+ function build_pages(index_records) {
20
+ const pages = new Map();
21
+ for (const file of index_records) {
22
+ if (file.inline) continue;
23
+ const page_path = to_page_path(file);
24
+ if (!pages.has(page_path)) {
25
+ pages.set(page_path, {
26
+ page_path,
27
+ title: file.index_html.fm_props.title || "",
28
+ keywords: file.keywords || "",
29
+ status: file.status || "release",
30
+ lastmod: file.lastmod || null,
31
+ sections: [],
32
+ });
33
+ }
34
+ const text = (file.index_html.text || "").trim();
35
+ if (text) pages.get(page_path).sections.push(text);
36
+ }
37
+ return Array.from(pages.values());
38
+ }
39
+
40
+ // Returns an ISO 8601 string, or null if the value is absent or unparseable.
41
+ function safe_iso(value) {
42
+ if (!value) return null;
43
+ const d = new Date(value);
44
+ return Number.isNaN(d.getTime()) ? null : d.toISOString();
45
+ }
46
+
47
+ exports.populate_onyx_index = (
48
+ work_path_content,
49
+ doc_id,
50
+ book_config,
51
+ index_records,
52
+ base_url = "",
53
+ verbose = false,
54
+ ) => {
55
+ const response = {
56
+ success: false,
57
+ document_count: 0,
58
+ error: "",
59
+ };
60
+
61
+ const pages = build_pages(index_records);
62
+ const canonical_base = base_url.replace(/\/$/, "");
63
+ const metadata_entries = [];
64
+
65
+ for (const page of pages) {
66
+ // e.g. onyx/getting-started/index.txt or onyx/reference/api.txt
67
+ const txt_rel = `_onyx${page.page_path}.txt`;
68
+ const txt_abs = path.join(work_path_content, txt_rel);
69
+
70
+ fs.mkdirSync(path.dirname(txt_abs), { recursive: true });
71
+
72
+ // Plain-text body: title, keywords hint, then each section separated by
73
+ // a blank line so Onyx's chunker sees natural paragraph boundaries.
74
+ const lines = [];
75
+ if (page.title) lines.push(page.title, "");
76
+ if (page.keywords) lines.push(`Keywords: ${page.keywords}`, "");
77
+ for (const section of page.sections) {
78
+ lines.push(section, "");
79
+ }
80
+
81
+ try {
82
+ fs.writeFileSync(txt_abs, lines.join("\n").trimEnd(), "utf8");
83
+ } catch (e) {
84
+ response.error = `Failed to write ${txt_rel}: ${e.message}`;
85
+ return response;
86
+ }
87
+
88
+ if (verbose) console.log(`Onyx: wrote ${txt_rel}`);
89
+
90
+ const entry = {
91
+ filename: txt_rel.replaceAll("\\", "/"),
92
+ link: canonical_base
93
+ ? `${canonical_base}${page.page_path}`
94
+ : page.page_path,
95
+ primary_owners: [],
96
+ secondary_owners: [],
97
+ metadata: {
98
+ book_id: doc_id,
99
+ product_family: book_config.productFamily || "",
100
+ audience: Array.isArray(book_config.audience)
101
+ ? book_config.audience.join(",")
102
+ : "",
103
+ tags: Array.isArray(book_config.tags)
104
+ ? book_config.tags.join(",")
105
+ : "",
106
+ status: page.status,
107
+ },
108
+ };
109
+ const updated_at = safe_iso(page.lastmod);
110
+ if (updated_at) entry.doc_updated_at = updated_at;
111
+ metadata_entries.push(entry);
112
+
113
+ response.document_count++;
114
+ }
115
+
116
+ const meta_path = path.join(work_path_content, ".onyx_metadata.json");
117
+ try {
118
+ fs.writeFileSync(
119
+ meta_path,
120
+ JSON.stringify(metadata_entries, null, 2),
121
+ "utf8",
122
+ );
123
+ } catch (e) {
124
+ response.error = `Failed to write .onyx_metadata.json: ${e.message}`;
125
+ return response;
126
+ }
127
+
128
+ response.success = true;
129
+ console.log(
130
+ `\nOnyx Index Build Complete: ${response.document_count} document records created.`,
131
+ );
132
+ return response;
133
+ };
134
+ })();
package/hdoc-build.js CHANGED
@@ -7,6 +7,7 @@
7
7
  const hdoc_validate = require(path.join(__dirname, "hdoc-validate.js"));
8
8
  const hdoc = require(path.join(__dirname, "hdoc-module.js"));
9
9
  const hdoc_build_db = require(path.join(__dirname, "hdoc-build-db.js"));
10
+ const hdoc_build_onyx = require(path.join(__dirname, "hdoc-build-onyx.js"));
10
11
  const hdoc_build_pdf = require(path.join(__dirname, "hdoc-build-pdf.js"));
11
12
  const hdoc_index = require(path.join(__dirname, "hdoc-db.js"));
12
13
  const archiver = require("archiver");
package/hdoc-validate.js CHANGED
@@ -529,7 +529,10 @@ const { error } = require("node:console");
529
529
  const valid_url = hdoc.valid_url(links[i]);
530
530
  if (!valid_url) {
531
531
  // Could be a relative path, check
532
- if (links[i].startsWith("/") && !links[i].startsWith("/#")) {
532
+ if (links[i].startsWith("#") || links[i].startsWith("/#")) {
533
+ //Flat Anchor - validate we have a same-file hit
534
+ isHashAnchor(htmlFile, links[i]);
535
+ } else if (links[i].startsWith("/") && !links[i].startsWith("/#")) {
533
536
  let link_segments = links[i].split("/");
534
537
  if (link_segments[0] === "") link_segments.shift();
535
538
  const link_root = link_segments[0] === "_books" ? link_segments[1] : link_segments[0];
@@ -542,14 +545,11 @@ const { error } = require("node:console");
542
545
  }
543
546
 
544
547
  // Checking for internal links in other books - can't easily validate those here, returning
545
- if (link_segments.length > 1 && link_root !== hdocbook_config.docId) {
548
+ if ((link_segments.length > 1 && link_root !== hdocbook_config.docId) || (link_segments.length === 1 && link_root !== hdocbook_config.docId && link_root !== "index")) {
546
549
  fs.appendFileSync(skip_link_file, `${links[i]}\n`);
547
550
  continue;
548
551
  }
549
552
  isRelativePath(source_path, htmlFile, links[i]);
550
- } else if (links[i].startsWith("#") || links[i].startsWith("/#")) {
551
- //Flat Anchor - validate we have a same-file hit
552
- isHashAnchor(htmlFile, links[i]);
553
553
  } else {
554
554
  const error_message = processErrorMessage(`Root relative links should start with a forward-slash: ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
555
555
  errors[htmlFile.relativePath].push(error_message);
package/hdoc.js CHANGED
@@ -105,6 +105,7 @@
105
105
  let gen_exclude = false;
106
106
  let bump_type = "patch"; // To generate spellcheck exclusions for all files
107
107
  let output_links = true;
108
+ let onyx_index = false;
108
109
 
109
110
  // Get options from command args
110
111
  for (let x = 0; x < process.argv.length; x++) {
@@ -151,6 +152,8 @@
151
152
  console_color = false;
152
153
  } else if (process.argv[x].toLowerCase() === "--no-links") {
153
154
  output_links = false;
155
+ } else if (process.argv[x].toLowerCase() === "--onyx") {
156
+ onyx_index = true;
154
157
  }
155
158
  }
156
159
  source_path = hdoc.true_case_path_sync(source_path);
@@ -186,6 +189,7 @@
186
189
  gen_exclude,
187
190
  build_version,
188
191
  output_links,
192
+ onyx_index,
189
193
  );
190
194
  } else if (command.toLowerCase() === "createdocs") {
191
195
  const creator = require(path.join(__dirname, "hdoc-create.js"));
@@ -200,6 +204,7 @@
200
204
  gen_exclude,
201
205
  build_version,
202
206
  output_links,
207
+ onyx_index,
203
208
  );
204
209
  } else if (command.toLowerCase() === "stats") {
205
210
  const stats = require(path.join(__dirname, "hdoc-stats.js"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.47.4",
3
+ "version": "0.48.0",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -11,6 +11,7 @@
11
11
  "hdoc-db.js",
12
12
  "hdoc-build.js",
13
13
  "hdoc-build-db.js",
14
+ "hdoc-build-onyx.js",
14
15
  "hdoc-build-pdf.js",
15
16
  "hdoc-bump.js",
16
17
  "hdoc-create.js",