hdoc-tools 0.61.0 → 0.62.1

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.
Files changed (45) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +89 -75
  3. package/editor/dist/assets/index-Blewr90z.css +1 -1
  4. package/editor/dist/assets/index-BtxvGZHW.js +111 -111
  5. package/editor/dist/assets/spell.worker-sryEKmOj.js +13 -13
  6. package/editor/dist/index.html +14 -14
  7. package/hdoc-build-db.js +275 -275
  8. package/hdoc-build-embeddings.js +202 -202
  9. package/hdoc-build-pdf.js +232 -232
  10. package/hdoc-bump.js +125 -125
  11. package/hdoc-create.js +110 -110
  12. package/hdoc-db.js +114 -114
  13. package/hdoc-help.js +60 -60
  14. package/hdoc-install-browser.js +145 -145
  15. package/hdoc-mermaid.js +204 -204
  16. package/hdoc-module.js +1102 -1102
  17. package/hdoc-validate-config.js +355 -355
  18. package/hdoc-validate-interbook.js +321 -321
  19. package/hdoc-validate.js +1231 -1231
  20. package/hdoc-ver.js +45 -45
  21. package/package.json +12 -1
  22. package/templates/doc-header-non-git.html +19 -19
  23. package/templates/doc-header.html +26 -26
  24. package/templates/init/.github/workflows/hdocbuild_onpull.yml +16 -16
  25. package/templates/init/.github/workflows/hdocbuild_onpush.yml +15 -15
  26. package/templates/init/LICENSE +21 -21
  27. package/templates/init/README.md +9 -9
  28. package/templates/init/_hdocbook/index.md +4 -4
  29. package/templates/init/gitignore +8 -8
  30. package/templates/init/resources/README.md +2 -2
  31. package/templates/pdf/css/custom-block.css +90 -90
  32. package/templates/pdf/css/fonts.css +221 -221
  33. package/templates/pdf/css/hdocs-pdf.css +495 -495
  34. package/templates/pdf/css/vars.css +404 -404
  35. package/templates/pdf/template-footer.html +19 -19
  36. package/templates/pdf/template-header.html +37 -37
  37. package/templates/pdf/template.html +20 -20
  38. package/templates/pdf-header-non-git.html +12 -12
  39. package/templates/pdf-header.html +16 -16
  40. package/ui/content/invalid-hdocbook-json.html +6 -6
  41. package/ui/content/invalid-hdocbook-json.md +7 -7
  42. package/ui/css/theme-default/styles/components/content.css +124 -124
  43. package/ui/css/theme-default/styles/components/sidebar.css +182 -182
  44. package/ui/css/theme-default/styles/htldoc.layouts.css +310 -310
  45. package/ui/index.html +419 -419
@@ -1,14 +1,14 @@
1
- (function(){var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),l=o(((e,t)=>{
2
- /*!
3
- * Determine if an object is a Buffer
4
- *
5
- * @author Feross Aboukhadijeh <https://feross.org>
6
- * @license MIT
7
- */
8
- t.exports=function(e){return e!=null&&e.constructor!=null&&typeof e.constructor.isBuffer==`function`&&e.constructor.isBuffer(e)}})),u=o(((e,t)=>{t.exports=r;var n=[];function r(e,t){var r=0,i;if(!t)return n;if(e.FLAG===`long`){for(i=Array(Math.ceil(t.length/2));r<t.length;)i[r/2]=t.slice(r,r+2),r+=2;return i}return t.split(e.FLAG===`num`?`,`:``)}})),d=o(((e,t)=>{var n=u();t.exports=s;var r=[].push,i=`etaoinshrdlcumwfgypbvkjxqz`.split(``),a=/\s+/,o=[`qwertzuop`,`yxcvbnm`,`qaw`,`say`,`wse`,`dsx`,`sy`,`edr`,`fdc`,`dx`,`rft`,`gfv`,`fc`,`tgz`,`hgb`,`gv`,`zhu`,`jhn`,`hb`,`uji`,`kjm`,`jn`,`iko`,`lkm`];function s(e){var t=Object.create(null),s=Object.create(null),u=Object.create(null),d=[],f={in:[],out:[]},p=[],m=e.toString(`utf8`),h=[],g=0,_=m.indexOf(`
9
- `),v,y,b,x,S,C,w,T,E,D,O,k,A;for(u.KEY=[];_>-1;)j(m.slice(g,_)),g=_+1,_=m.indexOf(`
10
- `,g);for(j(m.slice(g)),_=-1;++_<h.length;)if(y=h[_],v=y.split(a),b=v[0],b===`REP`){for(x=_+parseInt(v[1],10);++_<=x;)v=h[_].split(a),d.push([v[1],v[2]]);_--}else if(b===`ICONV`||b===`OCONV`){for(x=_+parseInt(v[1],10),T=f[b===`ICONV`?`in`:`out`];++_<=x;)v=h[_].split(a),T.push([new RegExp(v[1],`g`),v[2]]);_--}else if(b===`COMPOUNDRULE`){for(x=_+parseInt(v[1],10);++_<=x;)for(D=h[_].split(a)[1],E=-1,p.push(D);++E<D.length;)s[D.charAt(E)]=[];_--}else if(b===`PFX`||b===`SFX`){for(x=_+parseInt(v[3],10),D={type:b,combineable:v[2]===`Y`,entries:[]},t[v[1]]=D;++_<=x;){v=h[_].split(a),S=v[2],C=v[3].split(`/`),w=v[4],T={add:``,remove:``,match:``,continuation:n(u,C[1])},C&&C[0]!==`0`&&(T.add=C[0]);try{S!==`0`&&(T.remove=b===`SFX`?c(S):S),w&&w!==`.`&&(T.match=b===`SFX`?c(w):l(w))}catch{T=null}T&&D.entries.push(T)}_--}else if(b===`TRY`){for(w=v[1],k=-1,O=[];++k<w.length;)A=w.charAt(k),A.toLowerCase()===A&&O.push(A);for(k=-1;++k<i.length;)w.indexOf(i[k])<0&&O.push(i[k]);u[b]=O}else b===`KEY`?r.apply(u[b],v[1].split(`|`)):b===`COMPOUNDMIN`?u[b]=Number(v[1]):b===`ONLYINCOMPOUND`?(u[b]=v[1],s[v[1]]=[]):u[b]=v[1];return isNaN(u.COMPOUNDMIN)&&(u.COMPOUNDMIN=3),u.KEY.length||(u.KEY=o),u.TRY||=i.concat(),u.KEEPCASE||=!1,{compoundRuleCodes:s,replacementTable:d,conversion:f,compoundRules:p,rules:t,flags:u};function j(e){e=e.trim(),e&&e.charCodeAt(0)!==35&&h.push(e)}}function c(e){return RegExp(e+`$`)}function l(e){return RegExp(`^`+e)}})),f=o(((e,t)=>{t.exports=n;function n(e,t){for(var n=-1;++n<t.length;)e=e.replace(t[n][0],t[n][1]);return e}})),p=o(((e,t)=>{t.exports=n;function n(e,t,n){return n&&t in e&&n.indexOf(e[t])>-1}})),m=o(((e,t)=>{var n=p();t.exports=r;function r(e,t){var r=-1;if(e.data[t])return!n(e.flags,`ONLYINCOMPOUND`,e.data[t]);if(t.length>=e.flags.COMPOUNDMIN){for(;++r<e.compoundRules.length;)if(e.compoundRules[r].test(t))return!0}return!1}})),h=o(((e,t)=>{var n=f(),r=m(),i=p();t.exports=a;function a(e,t,a){var s=t.trim(),c;if(!s)return null;if(s=n(s,e.conversion.in),r(e,s))return!a&&i(e.flags,`FORBIDDENWORD`,e.data[s])?null:s;if(s.toUpperCase()===s){if(c=s.charAt(0)+s.slice(1).toLowerCase(),o(e.flags,e.data[c],a))return null;if(r(e,c))return c}if(c=s.toLowerCase(),c!==s){if(o(e.flags,e.data[c],a))return null;if(r(e,c))return c}return null}function o(e,t,n){return i(e,`KEEPCASE`,t)||n||i(e,`FORBIDDENWORD`,t)}})),g=o(((e,t)=>{var n=h();t.exports=r;function r(e){return!!n(this,e)}})),_=o(((e,t)=>{t.exports=n;function n(e){var t=r(e.charAt(0)),n=e.slice(1);return!n||(n=r(n),t===n)?t:t===`u`&&n===`l`?`s`:null}function r(e){return e===e.toLowerCase()?`l`:e===e.toUpperCase()?`u`:null}})),v=o(((e,t)=>{var n=_(),r=f(),i=p(),a=h();t.exports=s;var o=[].push;function s(e){var t=this,i={},a=[],s={},l,u,d=[],f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,N,P;if(e=r(e.trim(),t.conversion.in),!e||t.correct(e))return[];for(P=n(e),p=-1;++p<t.replacementTable.length;)for(u=t.replacementTable[p],m=e.indexOf(u[0]);m>-1;)d.push(e.replace(u[0],u[1])),m=e.indexOf(u[0],m+1);for(p=-1;++p<e.length;)for(y=e.charAt(p),x=e.slice(0,p),S=e.slice(p+1),w=y.toLowerCase(),C=w!==y,i={},m=-1;++m<t.flags.KEY.length;)if(b=t.flags.KEY[m],h=b.indexOf(w),!(h<0)){for(_=-1;++_<b.length;)if(_!==h){if(v=b.charAt(_),i[v])continue;i[v]=!0,C&&(v=v.toUpperCase()),d.push(x+v+S)}}for(p=-1,O=e.charAt(0),f=[``],k=1,A=0;++p<e.length;){for(y=O,O=e.charAt(p+1),x=e.slice(0,p),u=y===O?``:y+y,m=-1,g=f.length;++m<g;)m<=k&&f.push(f[m]+u),f[m]+=y;++A<3&&(k=f.length)}for(o.apply(d,f),f=[e],u=e.toLowerCase(),(e===u||P===null)&&f.push(e.charAt(0).toUpperCase()+u.slice(1)),u=e.toUpperCase(),e!==u&&f.push(u),l={state:{},weighted:s,suggestions:a},T=c(t,l,f,d),E=0,k=Math.min(T.length,Math.max(15-e.length,3)**3),j=Math.max((10-e.length)**3,1);!a.length&&E<k;)D=E+j,c(t,l,T.slice(E,D)),E=D;for(a.sort(F),f=[],M=[],p=-1;++p<a.length;)N=r(a[p],t.conversion.out),u=N.toLowerCase(),M.indexOf(u)<0&&(f.push(N),M.push(u));return f;function F(e,t){return I(e,t)||L(e,t)||R(e,t)}function I(e,t){return s[e]===s[t]?0:s[e]>s[t]?-1:1}function L(e,t){var r=n(e),i=n(t);return r===i?0:r===P?-1:i===P?1:void 0}function R(e,t){return e.localeCompare(t)}}function c(e,t,r,o){var s=e.flags.TRY,c=e.data,l=e.flags,u=[],d=-1,f,p,m,h,g,_,v,y,b,x,S,C,w;if(o)for(;++d<o.length;)T(o[d],!0);for(d=-1;++d<r.length;)for(f=r[d],p=``,m=``,h=f.charAt(0),g=f,_=f.slice(1),v=h.toLowerCase()!==h,y=n(f),b=-1;++b<=f.length;)for(p+=m,x=g,g=_,_=g.slice(1),m=h,h=f.charAt(b+1),S=v,h&&(v=h.toLowerCase()!==h),g&&S!==v&&(T(p+E(g)),T(p+E(h)+E(m)+_)),T(p+g),g&&T(p+h+m+_),w=-1;++w<s.length;)C=s[w],S&&C!==C.toUpperCase()?(y!==`s`&&(T(p+C+x),T(p+C+g)),C=C.toUpperCase(),T(p+C+x),T(p+C+g)):(T(p+C+x),T(p+C+g));return u;function T(n,r){var o=t.state[n],s;o!==!!o&&(u.push(n),s=a(e,n),o=s&&!i(l,`NOSUGGEST`,c[s]),t.state[n]=o,o&&(t.weighted[n]=r?10:0,t.suggestions.push(n))),o&&t.weighted[n]++}function E(e){var t=e.charAt(0);return(t.toLowerCase()===t?t.toUpperCase():t.toLowerCase())+e.slice(1)}}})),y=o(((e,t)=>{var n=h(),r=p();t.exports=i;function i(e){var t=this,i=n(t,e,!0);return{correct:t.correct(e),forbidden:!!(i&&r(t.flags,`FORBIDDENWORD`,t.data[i])),warn:!!(i&&r(t.flags,`WARN`,t.data[i]))}}})),b=o(((e,t)=>{t.exports=n;function n(e,t,r,i){for(var a=-1,o,s,c,l,u;++a<t.entries.length;)if(o=t.entries[a],l=o.continuation,u=-1,(!o.match||o.match.test(e))&&(s=o.remove?e.replace(o.remove,``):e,s=t.type===`SFX`?s+o.add:o.add+s,i.push(s),l&&l.length))for(;++u<l.length;)c=r[l[u]],c&&n(s,c,r,i);return i}})),x=o(((e,t)=>{var n=b();t.exports=o;var r=[].push,i=[];function a(e,t,n){var a=e[t];t in e?a===i?e[t]=n.concat():r.apply(a,n):e[t]=n.concat()}function o(e,t,r,o){var s=-1,c,l,u,d,f,p,m;for((!(`NEEDAFFIX`in o.flags)||r.indexOf(o.flags.NEEDAFFIX)<0)&&a(e,t,r);++s<r.length;)if(c=o.rules[r[s]],r[s]in o.compoundRuleCodes&&o.compoundRuleCodes[r[s]].push(t),c){for(p=n(t,c,o.rules,[]),l=-1;++l<p.length;)if(p[l]in e||(e[p[l]]=i),c.combineable){for(u=s;++u<r.length;)if(f=o.rules[r[u]],f&&f.combineable&&c.type!==f.type)for(m=n(p[l],f,o.rules,[]),d=-1;++d<m.length;)m[d]in e||(e[m[d]]=i)}}}})),S=o(((e,t)=>{var n=x();t.exports=i;var r=[];function i(e,t){var i=this;return n(i.data,e,i.data[t]||r,i),i}})),C=o(((e,t)=>{t.exports=n;function n(e){var t=this;return delete t.data[e],t}})),w=o(((e,t)=>{t.exports=n;function n(){return this.flags.WORDCHARS||null}})),T=o(((e,t)=>{var n=u(),r=x();t.exports=a;var i=/\s/g;function a(e,t,n){for(var r=e.toString(`utf8`),i=r.indexOf(`
11
- `)+1,a=r.indexOf(`
12
- `,i);a>-1;)r.charCodeAt(i)!==9&&o(r.slice(i,a),t,n),i=a+1,a=r.indexOf(`
13
- `,i);o(r.slice(i),t,n)}function o(e,t,a){for(var o=e.indexOf(`/`),s=e.indexOf(`#`),c=``,l,u;o>-1&&e.charCodeAt(o-1)===92;)e=e.slice(0,o-1)+e.slice(o),o=e.indexOf(`/`,o);s>-1?o>-1&&o<s?(l=e.slice(0,o),i.lastIndex=o+1,u=i.exec(e),c=e.slice(o+1,u?u.index:void 0)):l=e.slice(0,s):o>-1?(l=e.slice(0,o),c=e.slice(o+1)):l=e,l=l.trim(),l&&r(a,l,n(t.flags,c.trim()),t)}})),E=o(((e,t)=>{var n=T();t.exports=r;function r(e){var t=this,r=-1,i,a,o,s;for(n(e,t,t.data);++r<t.compoundRules.length;){for(i=t.compoundRules[r],a=``,s=-1;++s<i.length;)o=i.charAt(s),a+=t.compoundRuleCodes[o].length?`(?:`+t.compoundRuleCodes[o].join(`|`)+`)`:o;t.compoundRules[r]=new RegExp(a,`i`)}return t}})),D=o(((e,t)=>{t.exports=n;function n(e){var t=this,n=e.toString(`utf8`).split(`
1
+ (function(){var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),l=o(((e,t)=>{
2
+ /*!
3
+ * Determine if an object is a Buffer
4
+ *
5
+ * @author Feross Aboukhadijeh <https://feross.org>
6
+ * @license MIT
7
+ */
8
+ t.exports=function(e){return e!=null&&e.constructor!=null&&typeof e.constructor.isBuffer==`function`&&e.constructor.isBuffer(e)}})),u=o(((e,t)=>{t.exports=r;var n=[];function r(e,t){var r=0,i;if(!t)return n;if(e.FLAG===`long`){for(i=Array(Math.ceil(t.length/2));r<t.length;)i[r/2]=t.slice(r,r+2),r+=2;return i}return t.split(e.FLAG===`num`?`,`:``)}})),d=o(((e,t)=>{var n=u();t.exports=s;var r=[].push,i=`etaoinshrdlcumwfgypbvkjxqz`.split(``),a=/\s+/,o=[`qwertzuop`,`yxcvbnm`,`qaw`,`say`,`wse`,`dsx`,`sy`,`edr`,`fdc`,`dx`,`rft`,`gfv`,`fc`,`tgz`,`hgb`,`gv`,`zhu`,`jhn`,`hb`,`uji`,`kjm`,`jn`,`iko`,`lkm`];function s(e){var t=Object.create(null),s=Object.create(null),u=Object.create(null),d=[],f={in:[],out:[]},p=[],m=e.toString(`utf8`),h=[],g=0,_=m.indexOf(`
9
+ `),v,y,b,x,S,C,w,T,E,D,O,k,A;for(u.KEY=[];_>-1;)j(m.slice(g,_)),g=_+1,_=m.indexOf(`
10
+ `,g);for(j(m.slice(g)),_=-1;++_<h.length;)if(y=h[_],v=y.split(a),b=v[0],b===`REP`){for(x=_+parseInt(v[1],10);++_<=x;)v=h[_].split(a),d.push([v[1],v[2]]);_--}else if(b===`ICONV`||b===`OCONV`){for(x=_+parseInt(v[1],10),T=f[b===`ICONV`?`in`:`out`];++_<=x;)v=h[_].split(a),T.push([new RegExp(v[1],`g`),v[2]]);_--}else if(b===`COMPOUNDRULE`){for(x=_+parseInt(v[1],10);++_<=x;)for(D=h[_].split(a)[1],E=-1,p.push(D);++E<D.length;)s[D.charAt(E)]=[];_--}else if(b===`PFX`||b===`SFX`){for(x=_+parseInt(v[3],10),D={type:b,combineable:v[2]===`Y`,entries:[]},t[v[1]]=D;++_<=x;){v=h[_].split(a),S=v[2],C=v[3].split(`/`),w=v[4],T={add:``,remove:``,match:``,continuation:n(u,C[1])},C&&C[0]!==`0`&&(T.add=C[0]);try{S!==`0`&&(T.remove=b===`SFX`?c(S):S),w&&w!==`.`&&(T.match=b===`SFX`?c(w):l(w))}catch{T=null}T&&D.entries.push(T)}_--}else if(b===`TRY`){for(w=v[1],k=-1,O=[];++k<w.length;)A=w.charAt(k),A.toLowerCase()===A&&O.push(A);for(k=-1;++k<i.length;)w.indexOf(i[k])<0&&O.push(i[k]);u[b]=O}else b===`KEY`?r.apply(u[b],v[1].split(`|`)):b===`COMPOUNDMIN`?u[b]=Number(v[1]):b===`ONLYINCOMPOUND`?(u[b]=v[1],s[v[1]]=[]):u[b]=v[1];return isNaN(u.COMPOUNDMIN)&&(u.COMPOUNDMIN=3),u.KEY.length||(u.KEY=o),u.TRY||=i.concat(),u.KEEPCASE||=!1,{compoundRuleCodes:s,replacementTable:d,conversion:f,compoundRules:p,rules:t,flags:u};function j(e){e=e.trim(),e&&e.charCodeAt(0)!==35&&h.push(e)}}function c(e){return RegExp(e+`$`)}function l(e){return RegExp(`^`+e)}})),f=o(((e,t)=>{t.exports=n;function n(e,t){for(var n=-1;++n<t.length;)e=e.replace(t[n][0],t[n][1]);return e}})),p=o(((e,t)=>{t.exports=n;function n(e,t,n){return n&&t in e&&n.indexOf(e[t])>-1}})),m=o(((e,t)=>{var n=p();t.exports=r;function r(e,t){var r=-1;if(e.data[t])return!n(e.flags,`ONLYINCOMPOUND`,e.data[t]);if(t.length>=e.flags.COMPOUNDMIN){for(;++r<e.compoundRules.length;)if(e.compoundRules[r].test(t))return!0}return!1}})),h=o(((e,t)=>{var n=f(),r=m(),i=p();t.exports=a;function a(e,t,a){var s=t.trim(),c;if(!s)return null;if(s=n(s,e.conversion.in),r(e,s))return!a&&i(e.flags,`FORBIDDENWORD`,e.data[s])?null:s;if(s.toUpperCase()===s){if(c=s.charAt(0)+s.slice(1).toLowerCase(),o(e.flags,e.data[c],a))return null;if(r(e,c))return c}if(c=s.toLowerCase(),c!==s){if(o(e.flags,e.data[c],a))return null;if(r(e,c))return c}return null}function o(e,t,n){return i(e,`KEEPCASE`,t)||n||i(e,`FORBIDDENWORD`,t)}})),g=o(((e,t)=>{var n=h();t.exports=r;function r(e){return!!n(this,e)}})),_=o(((e,t)=>{t.exports=n;function n(e){var t=r(e.charAt(0)),n=e.slice(1);return!n||(n=r(n),t===n)?t:t===`u`&&n===`l`?`s`:null}function r(e){return e===e.toLowerCase()?`l`:e===e.toUpperCase()?`u`:null}})),v=o(((e,t)=>{var n=_(),r=f(),i=p(),a=h();t.exports=s;var o=[].push;function s(e){var t=this,i={},a=[],s={},l,u,d=[],f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,N,P;if(e=r(e.trim(),t.conversion.in),!e||t.correct(e))return[];for(P=n(e),p=-1;++p<t.replacementTable.length;)for(u=t.replacementTable[p],m=e.indexOf(u[0]);m>-1;)d.push(e.replace(u[0],u[1])),m=e.indexOf(u[0],m+1);for(p=-1;++p<e.length;)for(y=e.charAt(p),x=e.slice(0,p),S=e.slice(p+1),w=y.toLowerCase(),C=w!==y,i={},m=-1;++m<t.flags.KEY.length;)if(b=t.flags.KEY[m],h=b.indexOf(w),!(h<0)){for(_=-1;++_<b.length;)if(_!==h){if(v=b.charAt(_),i[v])continue;i[v]=!0,C&&(v=v.toUpperCase()),d.push(x+v+S)}}for(p=-1,O=e.charAt(0),f=[``],k=1,A=0;++p<e.length;){for(y=O,O=e.charAt(p+1),x=e.slice(0,p),u=y===O?``:y+y,m=-1,g=f.length;++m<g;)m<=k&&f.push(f[m]+u),f[m]+=y;++A<3&&(k=f.length)}for(o.apply(d,f),f=[e],u=e.toLowerCase(),(e===u||P===null)&&f.push(e.charAt(0).toUpperCase()+u.slice(1)),u=e.toUpperCase(),e!==u&&f.push(u),l={state:{},weighted:s,suggestions:a},T=c(t,l,f,d),E=0,k=Math.min(T.length,Math.max(15-e.length,3)**3),j=Math.max((10-e.length)**3,1);!a.length&&E<k;)D=E+j,c(t,l,T.slice(E,D)),E=D;for(a.sort(F),f=[],M=[],p=-1;++p<a.length;)N=r(a[p],t.conversion.out),u=N.toLowerCase(),M.indexOf(u)<0&&(f.push(N),M.push(u));return f;function F(e,t){return I(e,t)||L(e,t)||R(e,t)}function I(e,t){return s[e]===s[t]?0:s[e]>s[t]?-1:1}function L(e,t){var r=n(e),i=n(t);return r===i?0:r===P?-1:i===P?1:void 0}function R(e,t){return e.localeCompare(t)}}function c(e,t,r,o){var s=e.flags.TRY,c=e.data,l=e.flags,u=[],d=-1,f,p,m,h,g,_,v,y,b,x,S,C,w;if(o)for(;++d<o.length;)T(o[d],!0);for(d=-1;++d<r.length;)for(f=r[d],p=``,m=``,h=f.charAt(0),g=f,_=f.slice(1),v=h.toLowerCase()!==h,y=n(f),b=-1;++b<=f.length;)for(p+=m,x=g,g=_,_=g.slice(1),m=h,h=f.charAt(b+1),S=v,h&&(v=h.toLowerCase()!==h),g&&S!==v&&(T(p+E(g)),T(p+E(h)+E(m)+_)),T(p+g),g&&T(p+h+m+_),w=-1;++w<s.length;)C=s[w],S&&C!==C.toUpperCase()?(y!==`s`&&(T(p+C+x),T(p+C+g)),C=C.toUpperCase(),T(p+C+x),T(p+C+g)):(T(p+C+x),T(p+C+g));return u;function T(n,r){var o=t.state[n],s;o!==!!o&&(u.push(n),s=a(e,n),o=s&&!i(l,`NOSUGGEST`,c[s]),t.state[n]=o,o&&(t.weighted[n]=r?10:0,t.suggestions.push(n))),o&&t.weighted[n]++}function E(e){var t=e.charAt(0);return(t.toLowerCase()===t?t.toUpperCase():t.toLowerCase())+e.slice(1)}}})),y=o(((e,t)=>{var n=h(),r=p();t.exports=i;function i(e){var t=this,i=n(t,e,!0);return{correct:t.correct(e),forbidden:!!(i&&r(t.flags,`FORBIDDENWORD`,t.data[i])),warn:!!(i&&r(t.flags,`WARN`,t.data[i]))}}})),b=o(((e,t)=>{t.exports=n;function n(e,t,r,i){for(var a=-1,o,s,c,l,u;++a<t.entries.length;)if(o=t.entries[a],l=o.continuation,u=-1,(!o.match||o.match.test(e))&&(s=o.remove?e.replace(o.remove,``):e,s=t.type===`SFX`?s+o.add:o.add+s,i.push(s),l&&l.length))for(;++u<l.length;)c=r[l[u]],c&&n(s,c,r,i);return i}})),x=o(((e,t)=>{var n=b();t.exports=o;var r=[].push,i=[];function a(e,t,n){var a=e[t];t in e?a===i?e[t]=n.concat():r.apply(a,n):e[t]=n.concat()}function o(e,t,r,o){var s=-1,c,l,u,d,f,p,m;for((!(`NEEDAFFIX`in o.flags)||r.indexOf(o.flags.NEEDAFFIX)<0)&&a(e,t,r);++s<r.length;)if(c=o.rules[r[s]],r[s]in o.compoundRuleCodes&&o.compoundRuleCodes[r[s]].push(t),c){for(p=n(t,c,o.rules,[]),l=-1;++l<p.length;)if(p[l]in e||(e[p[l]]=i),c.combineable){for(u=s;++u<r.length;)if(f=o.rules[r[u]],f&&f.combineable&&c.type!==f.type)for(m=n(p[l],f,o.rules,[]),d=-1;++d<m.length;)m[d]in e||(e[m[d]]=i)}}}})),S=o(((e,t)=>{var n=x();t.exports=i;var r=[];function i(e,t){var i=this;return n(i.data,e,i.data[t]||r,i),i}})),C=o(((e,t)=>{t.exports=n;function n(e){var t=this;return delete t.data[e],t}})),w=o(((e,t)=>{t.exports=n;function n(){return this.flags.WORDCHARS||null}})),T=o(((e,t)=>{var n=u(),r=x();t.exports=a;var i=/\s/g;function a(e,t,n){for(var r=e.toString(`utf8`),i=r.indexOf(`
11
+ `)+1,a=r.indexOf(`
12
+ `,i);a>-1;)r.charCodeAt(i)!==9&&o(r.slice(i,a),t,n),i=a+1,a=r.indexOf(`
13
+ `,i);o(r.slice(i),t,n)}function o(e,t,a){for(var o=e.indexOf(`/`),s=e.indexOf(`#`),c=``,l,u;o>-1&&e.charCodeAt(o-1)===92;)e=e.slice(0,o-1)+e.slice(o),o=e.indexOf(`/`,o);s>-1?o>-1&&o<s?(l=e.slice(0,o),i.lastIndex=o+1,u=i.exec(e),c=e.slice(o+1,u?u.index:void 0)):l=e.slice(0,s):o>-1?(l=e.slice(0,o),c=e.slice(o+1)):l=e,l=l.trim(),l&&r(a,l,n(t.flags,c.trim()),t)}})),E=o(((e,t)=>{var n=T();t.exports=r;function r(e){var t=this,r=-1,i,a,o,s;for(n(e,t,t.data);++r<t.compoundRules.length;){for(i=t.compoundRules[r],a=``,s=-1;++s<i.length;)o=i.charAt(s),a+=t.compoundRuleCodes[o].length?`(?:`+t.compoundRuleCodes[o].join(`|`)+`)`:o;t.compoundRules[r]=new RegExp(a,`i`)}return t}})),D=o(((e,t)=>{t.exports=n;function n(e){var t=this,n=e.toString(`utf8`).split(`
14
14
  `),r=-1,i,a,o,s;for(t.flags.FORBIDDENWORD===void 0&&(t.flags.FORBIDDENWORD=!1),s=t.flags.FORBIDDENWORD;++r<n.length;)i=n[r].trim(),i&&(i=i.split(`/`),o=i[0],a=o.charAt(0)===`*`,a&&(o=o.slice(1)),t.add(o,i[1]),a&&t.data[o].push(s));return t}})),O=c(o(((e,t)=>{var n=l(),r=d();t.exports=a;var i=a.prototype;i.correct=g(),i.suggest=v(),i.spell=y(),i.add=S(),i.remove=C(),i.wordCharacters=w(),i.dictionary=E(),i.personal=D();function a(e,t){var i=-1,o;if(!(this instanceof a))return new a(e,t);if(typeof e==`string`||n(e)?(typeof t==`string`||n(t))&&(o=[{dic:t}]):e&&(`length`in e?(o=e,e=e[0]&&e[0].aff):(e.dic&&(o=[e]),e=e.aff)),!e)throw Error("Missing `aff` in dictionary");if(e=r(e),this.data=Object.create(null),this.compoundRuleCodes=e.compoundRuleCodes,this.replacementTable=e.replacementTable,this.conversion=e.conversion,this.compoundRules=e.compoundRules,this.rules=e.rules,this.flags=e.flags,o)for(;++i<o.length;)o[i].dic&&this.dictionary(o[i].dic)}}))(),1);let k=null,A=null,j=new Map,M=new Map;function N(e){return A||=(async()=>{let[t,n]=await Promise.all([fetch(`/dict/en.aff`).then(e=>e.text()),fetch(`/dict/en.dic`).then(e=>e.text())]);k=(0,O.default)(t,n);for(let t of e)k.add(t)})(),A}function P(e){let t=[],n=n=>{let r;for(;(r=n.exec(e))!==null;)t.push([r.index,r.index+r[0].length])};n(/```[\s\S]*?```/g),n(/~~~[\s\S]*?~~~/g),n(/`[^`\n]+`/g);let r=e.match(/^---\r?\n[\s\S]*?\r?\n---/);return r&&t.push([0,r[0].length]),n(/https?:\/\/[^\s)]+/g),n(/\]\([^)]*\)/g),n(/\[\[[^\]]*\]\]/g),n(/\{\{[^}]*\}\}/g),n(/<[^>]+>/g),t}function F(e,t){for(let[n,r]of t)if(e>=n&&e<r)return!0;return!1}function I(e,t){return e.correct(t)?!0:t.includes(`-`)?t.split(`-`).filter(Boolean).every(t=>!!(t.length<2||e.correct(t)||t.endsWith(`s`)&&e.correct(t.slice(0,-1))||t.endsWith(`es`)&&e.correct(t.slice(0,-2)))):!1}function L(e,t){let n=k;if(!n)return[];let r=P(e),i=[],a=/[A-Za-z]+(?:['’-][A-Za-z]+)*/g,o;for(;(o=a.exec(e))!==null;){let e=o[0],a=o.index;if(e.length<2||/\d/.test(e)||e===e.toUpperCase()||t.has(e.toLowerCase())||F(a,r))continue;let s=j.get(e);if(s===void 0&&(s=I(n,e),j.set(e,s)),s)continue;let c=M.get(e);c===void 0&&(c=n.suggest(e).slice(0,5),M.set(e,c)),i.push({from:a,to:a+e.length,word:e,suggestions:c})}return i}self.onmessage=async e=>{let t=e.data;if(t.type===`add`){await A,k&&t.word&&(k.add(t.word),j.delete(t.word));return}if(t.type===`check`){await N(t.customWords??[]);let e=new Set((t.customWords??[]).map(e=>e.toLowerCase())),n=L(t.text,e);self.postMessage({type:`result`,id:t.id,findings:n})}}})();
@@ -1,14 +1,14 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>hdoc edit</title>
8
- <script type="module" crossorigin src="/assets/index-BtxvGZHW.js"></script>
9
- <link rel="stylesheet" crossorigin href="/assets/index-Blewr90z.css">
10
- </head>
11
- <body>
12
- <div id="root"></div>
13
- </body>
14
- </html>
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>hdoc edit</title>
8
+ <script type="module" crossorigin src="/assets/index-BtxvGZHW.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/assets/index-Blewr90z.css">
10
+ </head>
11
+ <body>
12
+ <div id="root"></div>
13
+ </body>
14
+ </html>
package/hdoc-build-db.js CHANGED
@@ -1,275 +1,275 @@
1
- (() => {
2
- const path = require("node:path");
3
- const hdoc_index = require(path.join(__dirname, "hdoc-db.js"));
4
- const database = require("better-sqlite3");
5
-
6
- const db_schema = {
7
- hdoc_index: [
8
- "resource_url UNINDEXED",
9
- "book_id",
10
- "book_audience UNINDEXED",
11
- "book_tags",
12
- "doc_title",
13
- "doc_content",
14
- "doc_preview UNINDEXED",
15
- "doc_family_id",
16
- "doc_md5_hash UNINDEXED",
17
- "doc_lastmod",
18
- "doc_status",
19
- "doc_keywords",
20
- // 0=document, 1=api_ref, 2=db_ref, 3=etl_ref, 4=mcp_ref
21
- "doc_type UNINDEXED",
22
- // Raw markdown source of the document (HTML sources are converted)
23
- "doc_md UNINDEXED",
24
- ],
25
- hdoc_meta: [
26
- "resource_url",
27
- "book_id",
28
- "contributor_count INTEGER UNINDEXED",
29
- "edit_url UNINDEXED",
30
- "last_commit UNINDEXED",
31
- "pdf_size INTEGER UNINDEXED",
32
- ],
33
- hdoc_contributors: [
34
- "resource_url",
35
- "book_id",
36
- "login",
37
- "name",
38
- "avatar UNINDEXED",
39
- "url UNINDEXED",
40
- ],
41
- hdoc_redirects: [
42
- "resource_url",
43
- "location_url",
44
- "http_code INTEGER UNINDEXED",
45
- ],
46
- // Semantic search embeddings, generated by hdoc-build-embeddings.js.
47
- // The docs service merges these into its sqlite-vec index at publish
48
- hdoc_embeddings: [
49
- "resource_url",
50
- "chunk_seq INTEGER",
51
- "chunk_text",
52
- "embedding BLOB",
53
- "model",
54
- "dims INTEGER",
55
- ],
56
- };
57
-
58
- exports.create_table = (db, table, cols, virtual, fts5) => {
59
- const table_created = hdoc_index.create_table(
60
- db,
61
- table,
62
- cols,
63
- virtual,
64
- fts5,
65
- );
66
- if (table_created !== null) {
67
- return `\nError creating table: ${table_created}`;
68
- }
69
- console.log(`\nTable created: ${table}`);
70
- return null;
71
- };
72
-
73
- exports.create_db = function (db_path, doc_id) {
74
- const response = {
75
- error: null,
76
- db: null,
77
- };
78
- console.log("\nPerforming SQlite index creation...");
79
- const db_name = path.join(db_path, doc_id, "index.db");
80
- response.db = new database(db_name);
81
- response.db.pragma('encoding="UTF-8"');
82
- console.log(`\nDatabase created: ${db_name}`);
83
-
84
- // Create tables
85
- for (const key in db_schema) {
86
- if (Object.hasOwn(db_schema, key)) {
87
- const virtual = key === "hdoc_index";
88
- const fts5 = key === "hdoc_index";
89
- const table_created_error = this.create_table(
90
- response.db,
91
- key,
92
- db_schema[key],
93
- virtual,
94
- fts5,
95
- );
96
- if (table_created_error !== null) {
97
- console.error(table_created_error);
98
- }
99
- }
100
- }
101
- return response;
102
- };
103
-
104
- exports.populate_redirects = (db, redirect_records, _verbose = false) => {
105
- const response = {
106
- success: true,
107
- errors: [],
108
- index_success_count: 0,
109
- };
110
-
111
- // Prepare once, insert all in one transaction
112
- const cols = db_schema.hdoc_redirects.map(c => c.replace(/\b(UNINDEXED|INTEGER)\b/g, "").trim());
113
- const stmt = db.prepare(`INSERT INTO hdoc_redirects (${cols.join(", ")}) VALUES (${cols.map(() => "?").join(", ")})`);
114
-
115
- const run_all = db.transaction(() => {
116
- for (const record of redirect_records) {
117
- try {
118
- stmt.run(record.url, record.location ? record.location : "", record.code);
119
- response.index_success_count++;
120
- } catch (e) {
121
- response.success = false;
122
- response.errors.push(`Redirect record creation failed - ${record.url}: ${e}`);
123
- }
124
- }
125
- });
126
-
127
- try {
128
- run_all();
129
- } catch (e) {
130
- response.success = false;
131
- response.errors.push(`Redirect index transaction failed: ${e}`);
132
- }
133
-
134
- console.log(
135
- `\nRedirect Index Build Complete: ${response.index_success_count} document records created.`,
136
- );
137
- return response;
138
- };
139
-
140
- exports.populate_index = (
141
- db,
142
- doc_id,
143
- book_config,
144
- index_records,
145
- verbose = false,
146
- ) => {
147
- const response = {
148
- success: false,
149
- index_success_count: 0,
150
- error: "",
151
- };
152
-
153
- if (!book_config.tags) book_config.tags = [];
154
-
155
- // Book-level content type from hdocbook.json bookType:
156
- // 0=document, 1=api_ref, 2=db_ref, 3=etl_ref, 4=mcp_ref
157
- // Bound as BigInt: better-sqlite3 binds JS numbers as REAL, and FTS5
158
- // columns have no affinity to coerce them back to INTEGER
159
- const book_doc_type = BigInt(
160
- Number.isInteger(book_config.bookType) ? book_config.bookType : 0,
161
- );
162
-
163
- // Build a prepared statement from a schema entry once, reusing it for every row.
164
- // Previously insert_record() called db.prepare() on every single insert.
165
- const make_stmt = (table) => {
166
- const cols = db_schema[table].map(c => c.replace(/\b(UNINDEXED|INTEGER)\b/g, "").trim());
167
- return db.prepare(`INSERT INTO ${table} (${cols.join(", ")}) VALUES (${cols.map(() => "?").join(", ")})`);
168
- };
169
- const stmt_index = make_stmt("hdoc_index");
170
- const stmt_meta = make_stmt("hdoc_meta");
171
- const stmt_contrib = make_stmt("hdoc_contributors");
172
-
173
- // A single transaction batches all disk flushes into one — critical for
174
- // FTS5 which otherwise re-indexes on every individual insert.
175
- const run_all = db.transaction(() => {
176
- let curr_file = "";
177
- for (const file of index_records) {
178
- let index_path_name = file.relative_path.replaceAll("\\", "/");
179
- if (
180
- index_path_name.endsWith("/index.md") ||
181
- index_path_name.endsWith("/index.html") ||
182
- index_path_name.endsWith("/index.htm")
183
- ) {
184
- index_path_name = index_path_name.substring(0, index_path_name.lastIndexOf("/"));
185
- }
186
- index_path_name = `/${index_path_name.replace(path.extname(file.relative_path), "")}`;
187
-
188
- let inserted_row_id = null;
189
- const index_content_path = file.index_html.id !== null
190
- ? `${index_path_name}#${file.index_html.id}`
191
- : index_path_name;
192
-
193
- if (!file.inline) {
194
- try {
195
- const info = stmt_index.run(
196
- index_content_path,
197
- doc_id,
198
- book_config.audience.join(","),
199
- book_config.tags.join(","),
200
- file.index_html.fm_props.title,
201
- file.index_html.text,
202
- file.index_html.preview,
203
- book_config.productFamily,
204
- file.md5,
205
- file.lastmod,
206
- file.status,
207
- file.keywords,
208
- book_doc_type,
209
- file.doc_md ?? "",
210
- );
211
- inserted_row_id = info.lastInsertRowid;
212
- } catch (e) {
213
- console.error(`Index record creation failed - ${doc_id}/${file.index_html.fm_props.title}: ${e}`);
214
- continue;
215
- }
216
- }
217
-
218
- if (curr_file === index_path_name) continue;
219
- curr_file = index_path_name;
220
-
221
- try {
222
- const meta_info = stmt_meta.run(
223
- index_path_name,
224
- doc_id,
225
- file.metadata.contributor_count,
226
- file.metadata.edit_url,
227
- file.metadata.last_commit,
228
- file.pdf_size,
229
- );
230
- if (verbose) {
231
- console.log(`Inserted index record ${inserted_row_id}: ${doc_id} - ${file.index_html.fm_props.title}`);
232
- console.log(`Inserted index metadata record for index ID: ${meta_info.lastInsertRowid}`);
233
- }
234
- } catch (e) {
235
- console.error(`Index metadata record creation failed - ${doc_id}/${inserted_row_id}/${file.index_html.fm_props.title}: ${e}`);
236
- continue;
237
- }
238
-
239
- for (const contrib of file.contributors) {
240
- try {
241
- const cont_info = stmt_contrib.run(
242
- index_path_name,
243
- doc_id,
244
- contrib.login,
245
- contrib.name,
246
- contrib.avatar_url,
247
- contrib.html_url,
248
- );
249
- if (verbose) {
250
- console.log(`Inserted document contributor record ${cont_info.lastInsertRowid}`);
251
- }
252
- } catch (e) {
253
- console.error(`Index document contributor record creation failed - ${doc_id}/${inserted_row_id}/${file.index_html.fm_props.title}: ${e}`);
254
- }
255
- }
256
-
257
- response.index_success_count++;
258
- }
259
- });
260
-
261
- try {
262
- run_all();
263
- } catch (e) {
264
- response.error = e.message;
265
- console.error(`Index build transaction failed: ${e}`);
266
- return response;
267
- }
268
-
269
- response.success = true;
270
- console.log(
271
- `\nIndex Build Complete: ${response.index_success_count} document index records created.`,
272
- );
273
- return response;
274
- };
275
- })();
1
+ (() => {
2
+ const path = require("node:path");
3
+ const hdoc_index = require(path.join(__dirname, "hdoc-db.js"));
4
+ const database = require("better-sqlite3");
5
+
6
+ const db_schema = {
7
+ hdoc_index: [
8
+ "resource_url UNINDEXED",
9
+ "book_id",
10
+ "book_audience UNINDEXED",
11
+ "book_tags",
12
+ "doc_title",
13
+ "doc_content",
14
+ "doc_preview UNINDEXED",
15
+ "doc_family_id",
16
+ "doc_md5_hash UNINDEXED",
17
+ "doc_lastmod",
18
+ "doc_status",
19
+ "doc_keywords",
20
+ // 0=document, 1=api_ref, 2=db_ref, 3=etl_ref, 4=mcp_ref
21
+ "doc_type UNINDEXED",
22
+ // Raw markdown source of the document (HTML sources are converted)
23
+ "doc_md UNINDEXED",
24
+ ],
25
+ hdoc_meta: [
26
+ "resource_url",
27
+ "book_id",
28
+ "contributor_count INTEGER UNINDEXED",
29
+ "edit_url UNINDEXED",
30
+ "last_commit UNINDEXED",
31
+ "pdf_size INTEGER UNINDEXED",
32
+ ],
33
+ hdoc_contributors: [
34
+ "resource_url",
35
+ "book_id",
36
+ "login",
37
+ "name",
38
+ "avatar UNINDEXED",
39
+ "url UNINDEXED",
40
+ ],
41
+ hdoc_redirects: [
42
+ "resource_url",
43
+ "location_url",
44
+ "http_code INTEGER UNINDEXED",
45
+ ],
46
+ // Semantic search embeddings, generated by hdoc-build-embeddings.js.
47
+ // The docs service merges these into its sqlite-vec index at publish
48
+ hdoc_embeddings: [
49
+ "resource_url",
50
+ "chunk_seq INTEGER",
51
+ "chunk_text",
52
+ "embedding BLOB",
53
+ "model",
54
+ "dims INTEGER",
55
+ ],
56
+ };
57
+
58
+ exports.create_table = (db, table, cols, virtual, fts5) => {
59
+ const table_created = hdoc_index.create_table(
60
+ db,
61
+ table,
62
+ cols,
63
+ virtual,
64
+ fts5,
65
+ );
66
+ if (table_created !== null) {
67
+ return `\nError creating table: ${table_created}`;
68
+ }
69
+ console.log(`\nTable created: ${table}`);
70
+ return null;
71
+ };
72
+
73
+ exports.create_db = function (db_path, doc_id) {
74
+ const response = {
75
+ error: null,
76
+ db: null,
77
+ };
78
+ console.log("\nPerforming SQlite index creation...");
79
+ const db_name = path.join(db_path, doc_id, "index.db");
80
+ response.db = new database(db_name);
81
+ response.db.pragma('encoding="UTF-8"');
82
+ console.log(`\nDatabase created: ${db_name}`);
83
+
84
+ // Create tables
85
+ for (const key in db_schema) {
86
+ if (Object.hasOwn(db_schema, key)) {
87
+ const virtual = key === "hdoc_index";
88
+ const fts5 = key === "hdoc_index";
89
+ const table_created_error = this.create_table(
90
+ response.db,
91
+ key,
92
+ db_schema[key],
93
+ virtual,
94
+ fts5,
95
+ );
96
+ if (table_created_error !== null) {
97
+ console.error(table_created_error);
98
+ }
99
+ }
100
+ }
101
+ return response;
102
+ };
103
+
104
+ exports.populate_redirects = (db, redirect_records, _verbose = false) => {
105
+ const response = {
106
+ success: true,
107
+ errors: [],
108
+ index_success_count: 0,
109
+ };
110
+
111
+ // Prepare once, insert all in one transaction
112
+ const cols = db_schema.hdoc_redirects.map(c => c.replace(/\b(UNINDEXED|INTEGER)\b/g, "").trim());
113
+ const stmt = db.prepare(`INSERT INTO hdoc_redirects (${cols.join(", ")}) VALUES (${cols.map(() => "?").join(", ")})`);
114
+
115
+ const run_all = db.transaction(() => {
116
+ for (const record of redirect_records) {
117
+ try {
118
+ stmt.run(record.url, record.location ? record.location : "", record.code);
119
+ response.index_success_count++;
120
+ } catch (e) {
121
+ response.success = false;
122
+ response.errors.push(`Redirect record creation failed - ${record.url}: ${e}`);
123
+ }
124
+ }
125
+ });
126
+
127
+ try {
128
+ run_all();
129
+ } catch (e) {
130
+ response.success = false;
131
+ response.errors.push(`Redirect index transaction failed: ${e}`);
132
+ }
133
+
134
+ console.log(
135
+ `\nRedirect Index Build Complete: ${response.index_success_count} document records created.`,
136
+ );
137
+ return response;
138
+ };
139
+
140
+ exports.populate_index = (
141
+ db,
142
+ doc_id,
143
+ book_config,
144
+ index_records,
145
+ verbose = false,
146
+ ) => {
147
+ const response = {
148
+ success: false,
149
+ index_success_count: 0,
150
+ error: "",
151
+ };
152
+
153
+ if (!book_config.tags) book_config.tags = [];
154
+
155
+ // Book-level content type from hdocbook.json bookType:
156
+ // 0=document, 1=api_ref, 2=db_ref, 3=etl_ref, 4=mcp_ref
157
+ // Bound as BigInt: better-sqlite3 binds JS numbers as REAL, and FTS5
158
+ // columns have no affinity to coerce them back to INTEGER
159
+ const book_doc_type = BigInt(
160
+ Number.isInteger(book_config.bookType) ? book_config.bookType : 0,
161
+ );
162
+
163
+ // Build a prepared statement from a schema entry once, reusing it for every row.
164
+ // Previously insert_record() called db.prepare() on every single insert.
165
+ const make_stmt = (table) => {
166
+ const cols = db_schema[table].map(c => c.replace(/\b(UNINDEXED|INTEGER)\b/g, "").trim());
167
+ return db.prepare(`INSERT INTO ${table} (${cols.join(", ")}) VALUES (${cols.map(() => "?").join(", ")})`);
168
+ };
169
+ const stmt_index = make_stmt("hdoc_index");
170
+ const stmt_meta = make_stmt("hdoc_meta");
171
+ const stmt_contrib = make_stmt("hdoc_contributors");
172
+
173
+ // A single transaction batches all disk flushes into one — critical for
174
+ // FTS5 which otherwise re-indexes on every individual insert.
175
+ const run_all = db.transaction(() => {
176
+ let curr_file = "";
177
+ for (const file of index_records) {
178
+ let index_path_name = file.relative_path.replaceAll("\\", "/");
179
+ if (
180
+ index_path_name.endsWith("/index.md") ||
181
+ index_path_name.endsWith("/index.html") ||
182
+ index_path_name.endsWith("/index.htm")
183
+ ) {
184
+ index_path_name = index_path_name.substring(0, index_path_name.lastIndexOf("/"));
185
+ }
186
+ index_path_name = `/${index_path_name.replace(path.extname(file.relative_path), "")}`;
187
+
188
+ let inserted_row_id = null;
189
+ const index_content_path = file.index_html.id !== null
190
+ ? `${index_path_name}#${file.index_html.id}`
191
+ : index_path_name;
192
+
193
+ if (!file.inline) {
194
+ try {
195
+ const info = stmt_index.run(
196
+ index_content_path,
197
+ doc_id,
198
+ book_config.audience.join(","),
199
+ book_config.tags.join(","),
200
+ file.index_html.fm_props.title,
201
+ file.index_html.text,
202
+ file.index_html.preview,
203
+ book_config.productFamily,
204
+ file.md5,
205
+ file.lastmod,
206
+ file.status,
207
+ file.keywords,
208
+ book_doc_type,
209
+ file.doc_md ?? "",
210
+ );
211
+ inserted_row_id = info.lastInsertRowid;
212
+ } catch (e) {
213
+ console.error(`Index record creation failed - ${doc_id}/${file.index_html.fm_props.title}: ${e}`);
214
+ continue;
215
+ }
216
+ }
217
+
218
+ if (curr_file === index_path_name) continue;
219
+ curr_file = index_path_name;
220
+
221
+ try {
222
+ const meta_info = stmt_meta.run(
223
+ index_path_name,
224
+ doc_id,
225
+ file.metadata.contributor_count,
226
+ file.metadata.edit_url,
227
+ file.metadata.last_commit,
228
+ file.pdf_size,
229
+ );
230
+ if (verbose) {
231
+ console.log(`Inserted index record ${inserted_row_id}: ${doc_id} - ${file.index_html.fm_props.title}`);
232
+ console.log(`Inserted index metadata record for index ID: ${meta_info.lastInsertRowid}`);
233
+ }
234
+ } catch (e) {
235
+ console.error(`Index metadata record creation failed - ${doc_id}/${inserted_row_id}/${file.index_html.fm_props.title}: ${e}`);
236
+ continue;
237
+ }
238
+
239
+ for (const contrib of file.contributors) {
240
+ try {
241
+ const cont_info = stmt_contrib.run(
242
+ index_path_name,
243
+ doc_id,
244
+ contrib.login,
245
+ contrib.name,
246
+ contrib.avatar_url,
247
+ contrib.html_url,
248
+ );
249
+ if (verbose) {
250
+ console.log(`Inserted document contributor record ${cont_info.lastInsertRowid}`);
251
+ }
252
+ } catch (e) {
253
+ console.error(`Index document contributor record creation failed - ${doc_id}/${inserted_row_id}/${file.index_html.fm_props.title}: ${e}`);
254
+ }
255
+ }
256
+
257
+ response.index_success_count++;
258
+ }
259
+ });
260
+
261
+ try {
262
+ run_all();
263
+ } catch (e) {
264
+ response.error = e.message;
265
+ console.error(`Index build transaction failed: ${e}`);
266
+ return response;
267
+ }
268
+
269
+ response.success = true;
270
+ console.log(
271
+ `\nIndex Build Complete: ${response.index_success_count} document index records created.`,
272
+ );
273
+ return response;
274
+ };
275
+ })();