hdoc-tools 0.17.12 → 0.17.14
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 +2 -2
- package/hdoc-module.js +40 -22
- package/hdoc-serve.js +1 -1
- package/package.json +1 -1
package/hdoc-build.js
CHANGED
@@ -533,7 +533,7 @@
|
|
533
533
|
if (!bc[relative_path.replace('.html', '')] && bc[relative_path.replace('/index.html', '')]) {
|
534
534
|
relative_path = relative_path.replace('/index.html', '');
|
535
535
|
}
|
536
|
-
|
536
|
+
|
537
537
|
index_records.push({
|
538
538
|
relative_path: relative_path,
|
539
539
|
index_html: hdoc_index.transform_html_for_index(html_txt),
|
@@ -624,7 +624,7 @@
|
|
624
624
|
let last_commit_date = fm_headers[i].value;
|
625
625
|
if (last_commit_date !== 'No Commit Date Available') {
|
626
626
|
last_commit_date = new Date(fm_headers[i].value).toDateString();
|
627
|
-
}
|
627
|
+
}
|
628
628
|
wip_doc_header = wip_doc_header.replaceAll('{{last-update}}', last_commit_date);
|
629
629
|
break;
|
630
630
|
}
|
package/hdoc-module.js
CHANGED
@@ -4,9 +4,11 @@
|
|
4
4
|
const axios = require('axios'),
|
5
5
|
axiosRetry = require('axios-retry'),
|
6
6
|
cheerio = require('cheerio'),
|
7
|
+
fs = require('fs'),
|
7
8
|
html2text = require('html-to-text'),
|
8
9
|
https = require('https'),
|
9
10
|
htmlentities = require('html-entities'),
|
11
|
+
path = require('path'),
|
10
12
|
wordsCount = require('words-count').default;
|
11
13
|
|
12
14
|
let includesCache = {},
|
@@ -106,6 +108,7 @@
|
|
106
108
|
found: 0,
|
107
109
|
success: 0,
|
108
110
|
failed: 0,
|
111
|
+
included: [],
|
109
112
|
errors: []
|
110
113
|
};
|
111
114
|
|
@@ -129,37 +132,52 @@
|
|
129
132
|
continue;
|
130
133
|
}
|
131
134
|
|
132
|
-
if (includesCache[link] !== undefined) {
|
135
|
+
if ((link.startsWith('http://') || link.startsWith('https://')) && includesCache[link] !== undefined) {
|
133
136
|
console.log(`Serving From Cache: ${link}`);
|
134
137
|
body = body.replace(include_value, includesCache[link]);
|
138
|
+
response.success++;
|
135
139
|
continue;
|
136
140
|
}
|
137
141
|
|
138
142
|
// Validate link in INCLUDE
|
139
|
-
try {
|
140
|
-
new URL(link);
|
141
|
-
} catch (err) {
|
142
|
-
response.failed++;
|
143
|
-
response.errors.push(`Error validating INCLUDE link [${link}] from [${file_path}]: ${e}`);
|
144
|
-
continue;
|
145
|
-
}
|
146
|
-
|
147
143
|
let file_content;
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
144
|
+
if (link.startsWith('http://') || link.startsWith('https://')) {
|
145
|
+
// Remote content to include
|
146
|
+
try {
|
147
|
+
new URL(link);
|
148
|
+
} catch (e) {
|
149
|
+
response.failed++;
|
150
|
+
response.errors.push(`Error validating INCLUDE link [${link}] from [${file_path}]: ${e}`);
|
151
|
+
continue;
|
153
152
|
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
153
|
+
|
154
|
+
try {
|
155
|
+
const file_response = await axios.get(link);
|
156
|
+
if (retried) {
|
157
|
+
retried = false;
|
158
|
+
console.log(`API call retry success!`);
|
159
|
+
}
|
160
|
+
if (file_response.status === 200) {
|
161
|
+
file_content = file_response.data;
|
162
|
+
} else {
|
163
|
+
throw `Unexpected Status ${file_response.status}`;
|
164
|
+
}
|
165
|
+
} catch (e) {
|
166
|
+
response.failed++;
|
167
|
+
response.errors.push(`Error getting INCLUDE link content [${link}] from [${file_path}]: ${e}`);
|
168
|
+
continue;
|
158
169
|
}
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
170
|
+
console.log(`Included From Remote Source: ${link}`);
|
171
|
+
} else {
|
172
|
+
// Local content to include
|
173
|
+
try {
|
174
|
+
file_content = fs.readFileSync(path.join(process.cwd(), link), 'utf8');
|
175
|
+
} catch (e) {
|
176
|
+
response.failed++;
|
177
|
+
response.errors.push(`Error getting INCLUDE file [${link}] from [${file_path}]: ${e}`);
|
178
|
+
continue;
|
179
|
+
}
|
180
|
+
console.log(`Included From Local Source: ${link}`);
|
163
181
|
}
|
164
182
|
response.success++;
|
165
183
|
includesCache[link] = file_content;
|
package/hdoc-serve.js
CHANGED