hdoc-tools 0.12.0 → 0.14.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.
package/hdoc-build.js CHANGED
@@ -215,6 +215,13 @@
215
215
  });
216
216
  }
217
217
 
218
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) {
219
+ fm_headers.push({
220
+ id: 'pdf-path',
221
+ value: file_path.relativePath.replace(path.extname(file_path.relativePath), '.pdf')
222
+ })
223
+ }
224
+
218
225
  let fm_header_content = '<!--[[FRONTMATTER\n';
219
226
  if (fm_headers.length > 0) {
220
227
  for (let i = 0; i < fm_headers.length; i++) {
@@ -229,13 +236,20 @@
229
236
 
230
237
  let doc_header = '';
231
238
  let pdf_header = '';
239
+ const inline_content = file_path.relativePath.startsWith(`${hdocbook_config.docId}/_inline/`);
232
240
  if (hdocbook_config.publicSource && hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
233
241
  // Build doc header from template and frontmatter tags
234
- doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
235
- if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
242
+ if (!inline_content)
243
+ doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
244
+
245
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath))
246
+ pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
236
247
  } else {
237
- doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
238
- if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
248
+ if (!inline_content)
249
+ doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
250
+
251
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath))
252
+ pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
239
253
  }
240
254
 
241
255
  let pdf_size = 0;
@@ -249,7 +263,10 @@
249
263
  }
250
264
  if (pdf_size > 0) pdf_created++;
251
265
 
252
- html_txt = `${fm_header_content}\n${doc_header}\n${html_txt}`;
266
+ if (inline_content)
267
+ html_txt = `${fm_header_content}\n${html_txt}`;
268
+ else
269
+ html_txt = `${fm_header_content}\n${doc_header}\n${html_txt}`;
253
270
 
254
271
  index_records.push({
255
272
  relative_path: file_path.relativePath,
@@ -431,6 +448,13 @@
431
448
  });
432
449
  }
433
450
 
451
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) {
452
+ fm_headers.push({
453
+ id: 'pdf-path',
454
+ value: file_path.relativePath.replace(path.extname(file_path.relativePath), '.pdf')
455
+ })
456
+ }
457
+
434
458
  // Add frontmatter tags as comment
435
459
  let fm_header = '<!--[[FRONTMATTER\n';
436
460
  if (fm_headers.length > 0) {
@@ -442,14 +466,21 @@
442
466
 
443
467
  let doc_header = '';
444
468
  let pdf_header = '';
469
+ const inline_content = file_path.relativePath.startsWith(`${hdocbook_config.docId}/_inline/`);
445
470
  if (hdocbook_config.publicSource && hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
446
471
  // Build doc header from template and frontmatter tags
447
- doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
448
- if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
472
+ if (!inline_content)
473
+ doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
474
+
475
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath))
476
+ pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
449
477
  } else {
450
478
  // Build doc header from template and frontmatter tags
451
- doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
452
- if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
479
+ if (!inline_content)
480
+ doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
481
+
482
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath))
483
+ pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
453
484
  }
454
485
 
455
486
  let pdf_size = 0;
@@ -462,7 +493,11 @@
462
493
  pdf_size = await hdoc_build_pdf.generate_pdf(browser, pdf_template_path, pdf_template, hdocbook_config, pdf_txt, pdf_file_path, css_templates, verbose);
463
494
  }
464
495
  if (pdf_size > 0) pdf_created++;
465
- html_txt = `${fm_header}\n${doc_header}\n${html_txt}`;
496
+
497
+ if (inline_content)
498
+ html_txt = `${fm_header}\n${html_txt}`;
499
+ else
500
+ html_txt = `${fm_header}\n${doc_header}\n${html_txt}`;
466
501
 
467
502
  // Save HTML into HTML file
468
503
  const target_file = file_path.path.replace(path.extname(file_path.path), '.html');
package/hdoc-serve.js CHANGED
@@ -12,9 +12,11 @@
12
12
 
13
13
  let port = 3000;
14
14
  let docId;
15
- let hdocbook_config;
15
+ let hdocbook_config,
16
+ hdocbook_project,
17
+ inline_content = {};
16
18
 
17
- exports.run = async function (ui_path, source_path, md) {
19
+ exports.run = async function (ui_path, source_path) {
18
20
 
19
21
  for (let x = 0; x < process.argv.length; x++) {
20
22
  // First two arguments are command, and script
@@ -39,19 +41,37 @@
39
41
  return -1;
40
42
  }
41
43
 
42
- // Get an express server instance
43
- var app = express();
44
-
45
44
  // In the root of the project there is a hdocbook.json file which includes
46
45
  // the id of the hdocbook we are working with
47
46
  const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
48
47
 
49
48
  // Load the hdocbook config file
50
- var hdocbook_project = require(hdocbook_project_config_path);
49
+ hdocbook_project = require(hdocbook_project_config_path);
51
50
 
52
51
  // Get the ID of the hdocbook we are serving
53
52
  docId = hdocbook_project.docId;
54
53
 
54
+ // Get inline content for nav
55
+ const inline_path = path.join(source_path, docId, '_inline');
56
+ let nav_inline = {};
57
+ if (fs.existsSync(inline_path)) {
58
+ const inline_files = fs.readdirSync(inline_path);
59
+ nav_inline = {
60
+ text: 'Inline Help Items',
61
+ expand: true,
62
+ inline: true,
63
+ items: []
64
+ };
65
+ inline_files.forEach(file => {
66
+ nav_inline.items.push({
67
+ text: file.replace(path.extname(file), ''),
68
+ link: `${docId}/_inline/${file.replace(path.extname(file), '')}`
69
+ });
70
+ });
71
+ }
72
+ // Get an express server instance
73
+ var app = express();
74
+
55
75
  // Get the path of the book.json file
56
76
  const hdocbook_path = path.join(source_path, docId, 'hdocbook.json');
57
77
 
@@ -62,7 +82,8 @@
62
82
  let library = {
63
83
  books: [{
64
84
  docId: hdocbook_config.docId,
65
- title: hdocbook_config.title
85
+ title: hdocbook_config.title,
86
+ nav_inline: nav_inline
66
87
  }]
67
88
  };
68
89
  res.setHeader('Content-Type', 'application/json');
@@ -134,8 +155,10 @@
134
155
  return false;
135
156
  }
136
157
 
137
- function send_content_file(req, res, file_path) {
158
+ function send_content_file(req, res, file_path, redirected = false) {
138
159
  let content_txt = hdoc.expand_variables(fs.readFileSync(file_path).toString(), docId);
160
+ if (redirected)
161
+ content_txt = `Redirected from ${redirected}\n\n${content_txt}`;
139
162
 
140
163
  let contentType = hdoc.content_type_for_ext(path.extname(file_path));
141
164
 
@@ -198,6 +221,17 @@
198
221
 
199
222
  console.log('URL Requested:', url);
200
223
 
224
+ // Process redirect
225
+ if (hdocbook_project.redirects && hdocbook_project.redirects instanceof Array && hdocbook_project.redirects.length > 0) {
226
+ const source_url = url.indexOf('/') === 0 ? url.replace('/', '') : url;
227
+ hdocbook_project.redirects.forEach(function (redir) {
228
+ if (redir.url === source_url && redir.location && redir.location !== '') {
229
+ url = `/${redir.location}`;
230
+ console.log(`Redirecting to ${url}`);
231
+ }
232
+ });
233
+ }
234
+
201
235
  let file_path = path.join(source_path, url);
202
236
 
203
237
  if (path.extname(file_path) == '.html') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {