hdoc-tools 0.12.0 → 0.13.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,7 +12,8 @@
12
12
 
13
13
  let port = 3000;
14
14
  let docId;
15
- let hdocbook_config;
15
+ let hdocbook_config,
16
+ hdocbook_project;
16
17
 
17
18
  exports.run = async function (ui_path, source_path, md) {
18
19
 
@@ -47,7 +48,7 @@
47
48
  const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
48
49
 
49
50
  // Load the hdocbook config file
50
- var hdocbook_project = require(hdocbook_project_config_path);
51
+ hdocbook_project = require(hdocbook_project_config_path);
51
52
 
52
53
  // Get the ID of the hdocbook we are serving
53
54
  docId = hdocbook_project.docId;
@@ -134,8 +135,10 @@
134
135
  return false;
135
136
  }
136
137
 
137
- function send_content_file(req, res, file_path) {
138
+ function send_content_file(req, res, file_path, redirected = false) {
138
139
  let content_txt = hdoc.expand_variables(fs.readFileSync(file_path).toString(), docId);
140
+ if (redirected)
141
+ content_txt = `Redirected from ${redirected}\n\n${content_txt}`;
139
142
 
140
143
  let contentType = hdoc.content_type_for_ext(path.extname(file_path));
141
144
 
@@ -198,6 +201,17 @@
198
201
 
199
202
  console.log('URL Requested:', url);
200
203
 
204
+ // Process redirect
205
+ if (hdocbook_project.redirects && hdocbook_project.redirects instanceof Array && hdocbook_project.redirects.length > 0) {
206
+ const source_url = url.indexOf('/') === 0 ? url.replace('/', '') : url;
207
+ hdocbook_project.redirects.forEach(function (redir) {
208
+ if (redir.url === source_url && redir.location && redir.location !== '') {
209
+ url = `/${redir.location}`;
210
+ console.log(`Redirecting to ${url}`);
211
+ }
212
+ });
213
+ }
214
+
201
215
  let file_path = path.join(source_path, url);
202
216
 
203
217
  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.13.0",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {