hdoc-tools 0.17.28 → 0.17.30
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 +9 -3
- package/hdoc-serve.js +12 -2
- package/package.json +1 -1
- package/ui/content/invalid-hdocbook-json.html +6 -0
- package/ui/content/invalid-hdocbook-json.md +7 -0
- package/ui/index.html +57 -46
- package/ui/js/doc.hornbill.js +16 -41
package/hdoc-build.js
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
const { extension } = require("mime-types");
|
2
|
-
|
3
1
|
(function () {
|
4
2
|
"use strict";
|
5
3
|
|
@@ -19,6 +17,7 @@ const { extension } = require("mime-types");
|
|
19
17
|
xmlFormat = require("xml-formatter");
|
20
18
|
|
21
19
|
const h_tags_to_search = ["h1", "h2", "h3"],
|
20
|
+
image_extensions = [ 'png', 'svg', 'jpg' ],
|
22
21
|
doc_header_template_path = path.join(
|
23
22
|
__dirname,
|
24
23
|
"templates",
|
@@ -1030,11 +1029,14 @@ const { extension } = require("mime-types");
|
|
1030
1029
|
// File scan callback for filename validation
|
1031
1030
|
const filename_validation_callback = function (element) {
|
1032
1031
|
if (element.relativePath.startsWith('_inline/')) return;
|
1032
|
+
if (element.name.toLowerCase() === '.ds_store') return;
|
1033
1033
|
if (element.name === 'article_ext.md' || element.name === 'description_ext.md') return;
|
1034
|
+
if (image_extensions.includes(element.extension)) return;
|
1034
1035
|
const file_no_ext = element.name.replace(`.${element.extension}`, '');
|
1035
1036
|
if (!file_no_ext.match(regex_filename)) errors_filename.push(element.relativePath);
|
1036
1037
|
};
|
1037
1038
|
|
1039
|
+
|
1038
1040
|
const dreeOptions = {
|
1039
1041
|
hash: true,
|
1040
1042
|
extensions: ["md", "html", "htm"],
|
@@ -1210,10 +1212,14 @@ const { extension } = require("mime-types");
|
|
1210
1212
|
}
|
1211
1213
|
fs.mkdirSync(work_path);
|
1212
1214
|
|
1215
|
+
const file_filter = (src) => {
|
1216
|
+
return !src.toLowerCase().endsWith('.ds_store');
|
1217
|
+
};
|
1218
|
+
|
1213
1219
|
// Copy files from book into _work-doc_id folder
|
1214
1220
|
console.log(`Copying content into work folder...`);
|
1215
1221
|
try {
|
1216
|
-
fs.copySync(path.join(source_path, doc_id), work_path_content);
|
1222
|
+
fs.copySync(path.join(source_path, doc_id), work_path_content, { filter: file_filter });
|
1217
1223
|
} catch (e) {
|
1218
1224
|
console.error("Error copying from source_path:\n", e);
|
1219
1225
|
process.exit(1);
|
package/hdoc-serve.js
CHANGED
@@ -48,7 +48,12 @@
|
|
48
48
|
const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
|
49
49
|
|
50
50
|
// Load the hdocbook config file
|
51
|
-
|
51
|
+
try {
|
52
|
+
hdocbook_project = require(hdocbook_project_config_path);
|
53
|
+
} catch (e) {
|
54
|
+
console.log(`\nFailed to load hdocbook-project.json:\n${e}\n`);
|
55
|
+
process.exit(1);
|
56
|
+
}
|
52
57
|
|
53
58
|
// Get the ID of the hdocbook we are serving
|
54
59
|
docId = hdocbook_project.docId;
|
@@ -78,7 +83,12 @@
|
|
78
83
|
const hdocbook_path = path.join(source_path, docId, 'hdocbook.json');
|
79
84
|
|
80
85
|
// Pull in the book config file
|
81
|
-
|
86
|
+
try {
|
87
|
+
hdocbook_config = require(hdocbook_path);
|
88
|
+
} catch (e) {
|
89
|
+
console.log(`\nFailed to load hdocbook.json:\n${e}\n`);
|
90
|
+
process.exit(1);
|
91
|
+
}
|
82
92
|
|
83
93
|
app.get('/_books/library.json', function (req, res) {
|
84
94
|
let library = {
|
package/package.json
CHANGED
@@ -0,0 +1,6 @@
|
|
1
|
+
<h1>FAILED TO LOAD HDOC MENU</h1>
|
2
|
+
<div class="alert alert-danger" role="alert">
|
3
|
+
<strong>Warning!</strong>
|
4
|
+
<p><strong>hdoc serve</strong> has failed to load the book navigation. This is due to invalid JSON in the <code>hdocbook.json</code> file in your book.</p>
|
5
|
+
<p>Please fix the broken JSON, then refresh your browser to reload the book.</p>
|
6
|
+
</div>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<h1>FAILED TO LOAD HDOC MENU</h1>
|
2
|
+
<div class="alert alert-danger" role="alert">
|
3
|
+
<p><code>hdoc serve</code> has failed to load the book navigation. This is due to invalid JSON in the <code>hdocbook.json</code> file in your book.</p>
|
4
|
+
<p>Please fix the broken JSON, then refresh your browser to reload the book.</p>
|
5
|
+
<p>{{docApp.error}}</p>
|
6
|
+
</div>
|
7
|
+
</div>
|
package/ui/index.html
CHANGED
@@ -138,6 +138,7 @@
|
|
138
138
|
|
139
139
|
<h2 class="title">{{docApp.title}}</h2>
|
140
140
|
<h6 class="description">{{docApp.description}}</h6>
|
141
|
+
|
141
142
|
<!-- could generate nav bar based on library settings -->
|
142
143
|
<!--
|
143
144
|
<ul class="nav-bar-nav-list">
|
@@ -240,59 +241,69 @@
|
|
240
241
|
<div v-show="!docApp.showInlineDocumentsMarkup" class="injected-document-container hb-container-horizontal">
|
241
242
|
|
242
243
|
<div class="injected-document-content">
|
243
|
-
<div
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
<div class="hb-
|
248
|
-
<
|
249
|
-
<
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
244
|
+
<div v-if="docApp.error === ''">
|
245
|
+
<div class="document-header">
|
246
|
+
|
247
|
+
<!-- breadcrumb-->
|
248
|
+
<div class="hb-container-horizontal">
|
249
|
+
<div class="hb-center-v hb-container-expand">
|
250
|
+
<ul class="ps-0 nav-bar-nav-list noeffects after-fslash overflow-ellipsis">
|
251
|
+
<li class="mt-0 nav-bar-item"
|
252
|
+
v-for="(crumb,$index) in docApp.bookBreadCrumb">
|
253
|
+
<a class="ps-0 pe-0 text-decoration-none"
|
254
|
+
v-bind:href="crumb.link">{{crumb.title}}</a>
|
255
|
+
</li>
|
256
|
+
</ul>
|
257
|
+
</div>
|
258
|
+
<div class="toolbar-right hb-center-v">
|
259
|
+
|
260
|
+
<a class="toolbar-action" v-bind:href="docApp.documentGithubUrl"
|
261
|
+
target="_blank">
|
262
|
+
<i class="bi bi-pencil"></i>
|
263
|
+
</a>
|
264
|
+
|
265
|
+
<a class="toolbar-action">
|
266
|
+
<i class="bi bi-three-dots-vertical"></i>
|
267
|
+
</a>
|
268
|
+
</div>
|
255
269
|
</div>
|
256
|
-
<div class="toolbar-right hb-center-v">
|
257
270
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
271
|
+
<div class="document-title"></div>
|
272
|
+
|
273
|
+
<!-- doc frontmatter info -->
|
274
|
+
<div class="hb-container-horizontal">
|
275
|
+
<div class="hb-center-v hb-container-expand">
|
276
|
+
<ul
|
277
|
+
class="ps-0 nav-bar-nav-list noeffects after-bullets overflow-ellipsis text-light-2">
|
278
|
+
<li class="ps-0 mt-0 nav-bar-item">
|
279
|
+
Article
|
280
|
+
</li>
|
281
|
+
<li class="ps-0 mt-0 nav-bar-item">
|
282
|
+
YYYY-MM-DD
|
283
|
+
</li>
|
284
|
+
<li class="ps-0 mt-0 nav-bar-item">
|
285
|
+
(n) minutes to read
|
286
|
+
</li>
|
287
|
+
<li class="ps-0 mt-0 nav-bar-item">
|
288
|
+
<a class="link c-pointer">(n) contributors</a>
|
289
|
+
</li>
|
290
|
+
</ul>
|
291
|
+
</div>
|
292
|
+
<div class="toolbar-right hb-center-v">
|
293
|
+
</div>
|
266
294
|
</div>
|
267
|
-
</div>
|
268
295
|
|
269
|
-
<div class="document-title"></div>
|
270
|
-
|
271
|
-
<!-- doc frontmatter info -->
|
272
|
-
<div class="hb-container-horizontal">
|
273
|
-
<div class="hb-center-v hb-container-expand">
|
274
|
-
<ul
|
275
|
-
class="ps-0 nav-bar-nav-list noeffects after-bullets overflow-ellipsis text-light-2">
|
276
|
-
<li class="ps-0 mt-0 nav-bar-item">
|
277
|
-
Article
|
278
|
-
</li>
|
279
|
-
<li class="ps-0 mt-0 nav-bar-item">
|
280
|
-
YYYY-MM-DD
|
281
|
-
</li>
|
282
|
-
<li class="ps-0 mt-0 nav-bar-item">
|
283
|
-
(n) minutes to read
|
284
|
-
</li>
|
285
|
-
<li class="ps-0 mt-0 nav-bar-item">
|
286
|
-
<a class="link c-pointer">(n) contributors</a>
|
287
|
-
</li>
|
288
|
-
</ul>
|
289
|
-
</div>
|
290
|
-
<div class="toolbar-right hb-center-v">
|
291
|
-
</div>
|
292
296
|
</div>
|
297
|
+
<div class="document-body"></div>
|
298
|
+
</div>
|
293
299
|
|
300
|
+
<div v-if="docApp.error !== ''">
|
301
|
+
<div class="alert alert-danger" role="alert">
|
302
|
+
<h1>Book Navigation Render Failed!</h1>
|
303
|
+
<p>This is likely due to invalid JSON in the <strong>hdocbook.json</strong> file in your book. Please fix the error below, then refresh your browser to reload the book.</p>
|
304
|
+
<p><code>{{docApp.error}}</code></p>
|
305
|
+
</div>
|
294
306
|
</div>
|
295
|
-
<div class="document-body"></div>
|
296
307
|
|
297
308
|
</div>
|
298
309
|
|
package/ui/js/doc.hornbill.js
CHANGED
@@ -246,10 +246,9 @@ function generateTableOfContentsFromDoc() {
|
|
246
246
|
}
|
247
247
|
|
248
248
|
|
249
|
-
function loadContentUrl(linkRef, fromPageRefresh, fromPopState) {
|
249
|
+
function loadContentUrl(linkRef, fromPageRefresh, fromPopState, fromBook = true) {
|
250
250
|
//-- clear table of contents
|
251
251
|
view.docApp.tableOfContents = [];
|
252
|
-
|
253
252
|
if (linkRef.indexOf(window.location.origin + "/") === 0) {
|
254
253
|
linkRef = linkRef.replace(window.location.origin + "/", "");
|
255
254
|
}
|
@@ -260,15 +259,17 @@ function loadContentUrl(linkRef, fromPageRefresh, fromPopState) {
|
|
260
259
|
linkRef = removeStartingSlash(linkRef);
|
261
260
|
|
262
261
|
//-- update url in browser
|
263
|
-
setBrowserViewUrl(linkRef, {}, fromPageRefresh, fromPopState);
|
264
|
-
|
262
|
+
if (fromBook) setBrowserViewUrl(linkRef, {}, fromPageRefresh, fromPopState);
|
265
263
|
//-- destroy any existing content children and events properly
|
266
264
|
jqContentContainer.empty();
|
267
265
|
jqDocumentHeader.find(".document-title").empty();
|
268
|
-
|
266
|
+
|
269
267
|
//-- for now just load whatever the href prop is (we can add actions to perform specific processing and then load content based on element atts etc)
|
270
268
|
let frontmatterData = {};
|
271
|
-
let booksLinkRef = linkRef
|
269
|
+
let booksLinkRef = linkRef;
|
270
|
+
if (fromBook) {
|
271
|
+
booksLinkRef = linkRef.includes('_books/') ? linkRef : "_books/" + linkRef;
|
272
|
+
}
|
272
273
|
fetch(booksLinkRef).then(response => {
|
273
274
|
if (response.headers.has("X-frontmatter")) {
|
274
275
|
frontmatterData = response.headers.get("X-frontmatter");
|
@@ -333,7 +334,6 @@ function loadContentUrl(linkRef, fromPageRefresh, fromPopState) {
|
|
333
334
|
});
|
334
335
|
});
|
335
336
|
|
336
|
-
|
337
337
|
//-- do any code highlighting
|
338
338
|
if (hljs) {
|
339
339
|
document.querySelectorAll('pre code').forEach((el) => {
|
@@ -372,8 +372,7 @@ function loadContentUrl(linkRef, fromPageRefresh, fromPopState) {
|
|
372
372
|
|
373
373
|
|
374
374
|
setGitHubBookUrl(linkRef);
|
375
|
-
|
376
|
-
|
375
|
+
|
377
376
|
//-- make sure selected link parents are set to .expand=true
|
378
377
|
if (expandNavParentSectionBySelectedLinkHref(linkRef)) {
|
379
378
|
view.updateCounter++;
|
@@ -381,7 +380,7 @@ function loadContentUrl(linkRef, fromPageRefresh, fromPopState) {
|
|
381
380
|
//-- find any navigation links that match url and highlight
|
382
381
|
// listenForHrefClicks();
|
383
382
|
highlightNavigationLinkFromUrl(linkRef);
|
384
|
-
|
383
|
+
|
385
384
|
//-- scroll to element that match hash (if have one)
|
386
385
|
if (document.location.hash) {
|
387
386
|
let gotoEle = getAnchorFromHash(document.location.hash);
|
@@ -390,7 +389,7 @@ function loadContentUrl(linkRef, fromPageRefresh, fromPopState) {
|
|
390
389
|
});
|
391
390
|
view.$forceUpdate();
|
392
391
|
}
|
393
|
-
|
392
|
+
|
394
393
|
listenForHrefClicks();
|
395
394
|
});
|
396
395
|
}
|
@@ -547,11 +546,11 @@ async function fetchJsonFile(strFilePath) {
|
|
547
546
|
|
548
547
|
|
549
548
|
//-- THE INIT APP CALLED FROM index.html
|
550
|
-
|
549
|
+
//$(".document-body").attr("v-pre", "");
|
551
550
|
|
552
551
|
var view = new Vue({
|
553
552
|
el: '#vDocDevApp',
|
554
|
-
data: { userSession: {}, updateCounter: 0, bookId: "", docApp: {inlinePopupDocumentHref:"",showInlineDocumentsMarkup:false, keepTocLayout: false, book: {}, navSections: [], inlineDocumentItems:[], tableOfContents: [], bookBreadCrumb: [] } },
|
553
|
+
data: { userSession: {}, updateCounter: 0, bookId: "", docApp: {error: "", inlinePopupDocumentHref:"",showInlineDocumentsMarkup:false, keepTocLayout: false, book: {}, navSections: [], inlineDocumentItems:[], tableOfContents: [], bookBreadCrumb: [] } },
|
555
554
|
methods: docAppMethods,
|
556
555
|
directives: {
|
557
556
|
somedirectivename: {
|
@@ -603,33 +602,6 @@ async function intialiseApp() {
|
|
603
602
|
//jqContentContainer = $(".injected-document-content");
|
604
603
|
jqLeftNav = $("#DocSidebarNav");
|
605
604
|
|
606
|
-
|
607
|
-
//-- get session info
|
608
|
-
/*
|
609
|
-
let dummyResponse = {
|
610
|
-
"type": "user",
|
611
|
-
"userId": "doom-guy",
|
612
|
-
"userName": "Doom Guy",
|
613
|
-
"email": "doomguy@hornbill.com",
|
614
|
-
"profileImage": "https://www.writeups.org/wp-content/uploads/Doomguy-doom-portrait-featured-sprite.jpg",
|
615
|
-
"issuerDomain": ".hornbill.com",
|
616
|
-
"issuerInstance": "hornbill",
|
617
|
-
"validUntil": "2023-07-30 06:33:49Z"
|
618
|
-
}
|
619
|
-
dummyResponse.expiresDateTime = new Date(dummyResponse.validUntil).toLocaleDateString() + ' ' + new Date(dummyResponse.validUntil).toLocaleTimeString();
|
620
|
-
*/
|
621
|
-
|
622
|
-
fetchJsonFile("_api/session/").then(function (sessionData) {
|
623
|
-
hslDocLog.log("Hornbill docs get session data response", sessionData)
|
624
|
-
if (sessionData && sessionData.type === "user") {
|
625
|
-
hslDocLog.log("Hornbill docs set session set expires date time to browser locale")
|
626
|
-
sessionData.expiresDateTime = new Date(sessionData.validUntil).toLocaleDateString() + ' ' + new Date(sessionData.validUntil).toLocaleTimeString();
|
627
|
-
hslDocLog.log("Hornbill docs update vue session object model", sessionData);
|
628
|
-
view.setSessionInfo(sessionData);
|
629
|
-
}
|
630
|
-
});
|
631
|
-
|
632
|
-
//-- eof session stuff
|
633
605
|
await fetchJsonFile("_books/library.json").then(function (data) {
|
634
606
|
|
635
607
|
// Get docbook library list
|
@@ -674,12 +646,15 @@ async function intialiseApp() {
|
|
674
646
|
|
675
647
|
}
|
676
648
|
else {
|
677
|
-
hslDocLog.log("initial first view link to
|
649
|
+
hslDocLog.log("initial first view link to load is not present");
|
678
650
|
}
|
679
651
|
|
680
652
|
$(".hb-hidden").removeClass("hb-hidden");
|
681
653
|
|
682
654
|
}, 200);
|
655
|
+
}).catch(function (data) {
|
656
|
+
view.docApp.error = data;
|
657
|
+
$(".hb-hidden").removeClass("hb-hidden");
|
683
658
|
});
|
684
659
|
});
|
685
660
|
}
|