hdoc-tools 0.9.33 → 0.9.35
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-pdf.js +0 -3
- package/hdoc-build.js +14 -2
- package/hdoc-module.js +33 -1
- package/hdoc-validate.js +3 -33
- package/package.json +1 -1
package/hdoc-build-pdf.js
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
const axios = require('axios'),
|
5
5
|
cheerio = require('cheerio'),
|
6
|
-
dree = require('dree'),
|
7
6
|
fs = require('fs-extra'),
|
8
7
|
mime = require('mime-types'),
|
9
8
|
path = require('path'),
|
@@ -102,8 +101,6 @@
|
|
102
101
|
exports.generate_pdf = async function (browser, pdf_template_path, pdf_template_content, book_config, html_source, target_file, css_templates, verbose = false) {
|
103
102
|
let pdf_size = 0;
|
104
103
|
|
105
|
-
//dree.scan(pdf_template_path, dree_options_css, file_callback_css);
|
106
|
-
|
107
104
|
// Cache footer
|
108
105
|
if (footer === '') footer = get_footer(pdf_template_path);
|
109
106
|
|
package/hdoc-build.js
CHANGED
@@ -41,6 +41,8 @@
|
|
41
41
|
pdf_header_template = '',
|
42
42
|
pdf_header_template_non_git = '',
|
43
43
|
pdf_template = '',
|
44
|
+
prod_families = {},
|
45
|
+
prods_supported = [],
|
44
46
|
doc_id = '',
|
45
47
|
git_token = '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', // Github fine-grained personal access token that has minimum read-only access to Hornbill Docs org repo content
|
46
48
|
hdocbook_config = {},
|
@@ -628,6 +630,16 @@
|
|
628
630
|
|
629
631
|
if (hdocbook_config.publicSource.endsWith('.git')) hdocbook_config.publicSource = hdocbook_config.publicSource.substring(0, hdocbook_config.publicSource.length - 4);
|
630
632
|
|
633
|
+
console.log(`Loading product families...`);
|
634
|
+
const prods = await hdoc.load_product_families();
|
635
|
+
if (!prods.success) {
|
636
|
+
console.log(`ERROR: Failed to load product families: ${prods.errors}\n`);
|
637
|
+
process.exit(1);
|
638
|
+
} else {
|
639
|
+
prod_families = prods.prod_families;
|
640
|
+
prods_supported = prods.prods_supported;
|
641
|
+
}
|
642
|
+
|
631
643
|
console.log('Caching CSS for PDF generation...');
|
632
644
|
const css_files = [
|
633
645
|
path.join(pdf_template_path, 'css', 'custom-block.css'),
|
@@ -725,7 +737,7 @@
|
|
725
737
|
for (let i = 0; i < md_files.length; i++) {
|
726
738
|
mdPromiseArray.push(md_files[i]);
|
727
739
|
}
|
728
|
-
const chunkSize =
|
740
|
+
const chunkSize = 4;
|
729
741
|
for (let i = 0; i < mdPromiseArray.length; i += chunkSize) {
|
730
742
|
const chunk = mdPromiseArray.slice(i, i + chunkSize);
|
731
743
|
// do whatever
|
@@ -767,7 +779,7 @@
|
|
767
779
|
}
|
768
780
|
|
769
781
|
// Validate content
|
770
|
-
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc);
|
782
|
+
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc, prod_families, prods_supported);
|
771
783
|
if (!validation_success) {
|
772
784
|
const end_time = Date.now();
|
773
785
|
console.log(`\nTime Taken: ${get_duration(start_time, end_time)}\n`);
|
package/hdoc-module.js
CHANGED
@@ -4,9 +4,13 @@
|
|
4
4
|
const axios = require('axios'),
|
5
5
|
cheerio = require('cheerio'),
|
6
6
|
html2text = require('html-to-text'),
|
7
|
+
https = require('https'),
|
7
8
|
wordsCount = require('words-count').default;
|
8
9
|
|
9
|
-
let includesCache = {}
|
10
|
+
let includesCache = {},
|
11
|
+
agent = new https.Agent({
|
12
|
+
rejectUnauthorized: false
|
13
|
+
});
|
10
14
|
|
11
15
|
exports.content_type_for_ext = function (ext) {
|
12
16
|
switch (ext) {
|
@@ -394,4 +398,32 @@
|
|
394
398
|
}
|
395
399
|
return bc;
|
396
400
|
};
|
401
|
+
|
402
|
+
exports.load_product_families = async function () {
|
403
|
+
let response = {
|
404
|
+
success: false,
|
405
|
+
prod_families: {},
|
406
|
+
prods_supported: [],
|
407
|
+
errors: ''
|
408
|
+
};
|
409
|
+
|
410
|
+
try {
|
411
|
+
const prods = await axios.get('https://docs.hornbill.com/_books/products.json', {
|
412
|
+
httpsAgent: agent
|
413
|
+
});
|
414
|
+
if (prods.status === 200) {
|
415
|
+
response.prod_families = prods.data;
|
416
|
+
response.prods_supported = [];
|
417
|
+
for (let i = 0; i < response.prod_families.products.length; i++) {
|
418
|
+
response.prods_supported.push(response.prod_families.products[i].id);
|
419
|
+
}
|
420
|
+
response.success = true;
|
421
|
+
} else {
|
422
|
+
throw `Unexpected Status ${prods.status}`;
|
423
|
+
}
|
424
|
+
} catch (e) {
|
425
|
+
response.errors = (`Error returning product families: ${e}`);
|
426
|
+
}
|
427
|
+
return response;
|
428
|
+
};
|
397
429
|
})();
|
package/hdoc-validate.js
CHANGED
@@ -5,24 +5,17 @@
|
|
5
5
|
cheerio = require('cheerio'),
|
6
6
|
dree = require('dree'),
|
7
7
|
fs = require('fs'),
|
8
|
-
https = require('https'),
|
9
8
|
path = require('path'),
|
10
9
|
hdoc = require(path.join(__dirname, 'hdoc-module.js')),
|
11
10
|
translator = require('american-british-english-translator'),
|
12
11
|
{ trueCasePathSync } = require('true-case-path');
|
13
12
|
|
14
|
-
const
|
15
|
-
rejectUnauthorized: false
|
16
|
-
}),
|
17
|
-
spellcheck_options = {
|
13
|
+
const spellcheck_options = {
|
18
14
|
british: true,
|
19
15
|
spelling: true
|
20
16
|
},
|
21
17
|
regex_nav_paths = /[a-z0-9-\/]+/g;
|
22
18
|
|
23
|
-
let prod_families = {},
|
24
|
-
prods_supported = [];
|
25
|
-
|
26
19
|
let errors = {},
|
27
20
|
messages = {},
|
28
21
|
warnings = {},
|
@@ -32,26 +25,6 @@
|
|
32
25
|
exclude_spellcheck = {},
|
33
26
|
exclude_h1_count = {};
|
34
27
|
|
35
|
-
const load_product_families = async function () {
|
36
|
-
try {
|
37
|
-
const prods = await axios.get('https://docs.hornbill.com/_books/products.json', {
|
38
|
-
httpsAgent: agent
|
39
|
-
});
|
40
|
-
if (prods.status === 200) {
|
41
|
-
prod_families = prods.data;
|
42
|
-
for (let i = 0; i < prod_families.products.length; i++) {
|
43
|
-
prods_supported.push(prod_families.products[i].id);
|
44
|
-
}
|
45
|
-
} else {
|
46
|
-
throw `Unexpected Status ${prods.status}`;
|
47
|
-
}
|
48
|
-
} catch (e) {
|
49
|
-
console.log(`Error returning product families: ${e}`);
|
50
|
-
return false;
|
51
|
-
}
|
52
|
-
return true;
|
53
|
-
};
|
54
|
-
|
55
28
|
const spellcheckContent = async function (sourceFile, excludes) {
|
56
29
|
const text = fs.readFileSync(sourceFile.path, 'utf8');
|
57
30
|
const source_path = sourceFile.relativePath.replace('.' + sourceFile.extension, '');
|
@@ -344,12 +317,9 @@
|
|
344
317
|
return links;
|
345
318
|
};
|
346
319
|
|
347
|
-
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items) {
|
320
|
+
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items, prod_families, prods_supported) {
|
348
321
|
console.log(`Performing Validation and Building SEO Link List...`);
|
349
|
-
|
350
|
-
// Load product families
|
351
|
-
await load_product_families();
|
352
|
-
|
322
|
+
|
353
323
|
// Get a list of HTML files in source_path
|
354
324
|
dree.scan(source_path, dreeOptions, fileCallback);
|
355
325
|
|