From 85452eb4ed4d41705a74b90ec0b8d3937b7d3963 Mon Sep 17 00:00:00 2001 From: Gleb Date: Thu, 30 Mar 2023 14:56:13 +0300 Subject: [PATCH] to new release --- dist/mdsite.js | 2 +- docs/settings.en.md | 1 + docs/settings.ru.md | 1 + package.json | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/mdsite.js b/dist/mdsite.js index 71f2341..8f4e9c0 100644 --- a/dist/mdsite.js +++ b/dist/mdsite.js @@ -77,4 +77,4 @@ <${B} /> - `}edited(e,t){this.notSaved[e]=t,this.componentContainer.current.classList.add("edited")}saved(e){delete this.notSaved[e]}isEdited(e){return!!this.notSaved[e]}}async function G(){console.info("My Markdown Site, version","0.1.4");const e=window.MMDS,t=await fetch("settings.json").catch((e=>{console.log("Can not access settings.json")})),r=(t&&"200"==t.status?await t.json():"")||window.settings,n=r?Object.assign(e.settings,r):e.settings;e.settings=n;const o=document.getElementById("menu"),a=document.getElementById("content");o&&z(e.makePath(e.settings.menuFile)).then((e=>{o.innerHTML=e.html})).catch((e=>console.log("no sidebar",e))),window.MMDS.settings.scripts.forEach(((t,r)=>{const n=document.createElement("script");n.setAttribute("src",e.settings.userScriptsPath+t),console.info(r,"Loading user script:",t),document.head.appendChild(n)})),e.addUpdater(((t,r)=>{const n=r.html.match(/

(.*?)<\/h1>/i);window.document.title=n?n[1].replace(/<[^>]+>/g,""):e.settings.title+": "+t})),window.document.addEventListener("click",(function(e){const t=e.target,r=t.getAttribute("href")||t.parentNode.getAttribute&&t.parentNode.getAttribute("href")||"";r&&!r.startsWith("data:")&&(console.log("link clicked",r),window.MMDS.go(r),e.preventDefault(),e.stopPropagation())})),window.addEventListener("hashchange",(function(){console.log("hash changed..."),window.MMDS.go(window.location.hash.substring(2))})),window.MMDS.cleanUp=()=>{console.log("removing listeners..."),window.removeEventListener("DOMContentLoaded",G)},a?(a.innerHTML="",L(p(H,{base:e.settings.mdDir}),a)):console.error("Content node not found"),window.location.hash?(history.replaceState({path:window.location.hash.substring(2),isMMMDSstate:!0},null),e.showPath(window.location.hash.substring(2))):(history.replaceState({path:window.MMDS.settings.indexFile,isMMMDSstate:!0},null,"#!"+window.MMDS.settings.indexFile),e.showPath(e.settings.indexFile))}r(7695),window.MMDS=new function(){var e=this;this.version="0.1.4",this.usr={},this.editMode=!1,this.current=null,this.settings={title:"MD Site",mdDir:"md/",indexFile:"index.md",menuFile:"menu.md",scripts:[],editorScript:"mdeditor.js",hideEditor:!1,userScriptsPath:"",usr:{}},this.page404=function(e){return{html:`

${e}

This page is not created yet. Click "edit" to create it.

`,markdown:`\x3c!--${e}--\x3e`}},this.errorPage=(e,t)=>404===t?this.page404(e):"number"==typeof t?{html:"

Error "+t+"

Something went wrong

",markdown:"\x3c!--error--\x3e"}:{html:"

Fatal error

Network down or host unreachable

",markdown:"\x3c!--Fatal error--\x3e"},this.makePath=e=>{const t=window.MMDS.settings.mdDir;return t?t+e:e},this._updaters={},this._handlers={};var t=1;this.makeID=function(){return t+=1},this.addUpdater=e=>(t++,this._updaters[t]=e,t),this.removeUpdater=t=>{delete e._updaters[t]},this.onMany=(e,t)=>e.map((e=>this.on(e,t))),this.on=(e,r)=>(console.log("setting listener",e),t+=1,this._handlers[e]||(this._handlers[e]={}),this._handlers[e][t]=r,t),this.off=(e,t)=>{try{delete this._handlers[e][t]}catch{console.error("Can not delete handler",t,"for",e)}},this.fire=(e,t)=>{this._handlers[e]&&Object.values(this._handlers[e]).forEach((e=>e(t)))},this.once=e=>{e(this)},this.whenActive=t=>{window.addEventListener("focus",(function(){t(e),window.removeEventListener("focus",this)}))},this.updateViews=(e,t)=>{Object.values(this._updaters).forEach((r=>r(e,t))),this.fire("views_updated")},this.refresh=()=>{this.updateViews(this.current.path,this.current.content)},this.reload=()=>{this.showPath(this.current.path,{cache:"reload"}),this.current.path===this.settings.menuFile&&this.action.setMenu(this.settings.menuFile,{cache:"reload"})},this.showContent=(e,t)=>{this.current={path:e,content:t,saved:!0},this.editMode||window.scrollTo(0,0),this.updateViews(e,t),this.fire("ready")},this.showPath=(e,t)=>{const r=document.createElement("div");r.id="loaderAnimation",r.innerHTML=this.settings.loaderText||"loading",r.style.opacity=1,document.body.appendChild(r);const n=this.on("ready",(()=>{r.style.opacity=0,window.setTimeout((()=>r.remove()),300),this.off("ready",n)})),o=this.makePath(e||this.settings.indexFile);return z(o,t).then((t=>{if(t.error)return console.info("Error:",t.error),void this.showContent(e,this.errorPage(e,t.error));this.showContent(e,t)})).catch((t=>{console.info("No such file",o,t),this.showContent(e,this.page404(e))}))},this.go=e=>(console.log("Incoming path",e),e.match(/^(http|ftp)(s)?\:/i)?(console.info("External link",e),this.cleanUp(),void(window.location=e)):e.match(/\.(md|mkd|mdwn|mdown|mdtxt|mdtext|markdown)$/i)?(e=e||this.settings.indexFile,console.info("Link to other page",e),this.showPath(e),void history.pushState({path:e,isMMMDSstate:!0},null,"#!"+e)):(console.info("Internal link, but not page",e),this.cleanUp(),void(window.location=this.makePath(e)))),this.action={edit:()=>{this.editMode=!0,function(){console.log("MMMDS editor, version","0.1.4");const e=document.getElementById("content"),t=p(H,{base:window.MMDS.settings.mdDir,path:window.MMDS.current.path||"",content:window.MMDS.current.content});L(null,e),L(t,e)}()},save:()=>{console.info("Saving without editing"),U(this.current.path,this.current.content.markdown)},setMenu:(e,t)=>{const r=document.getElementById("menu");e&&z(this.makePath(this.settings.menuFile),t).then((e=>{r.innerHTML=e.html,this.fire("redraw","menu")})).catch((e=>console.log("no sidebar",e)))}}},"loading"!=document.readyState?G():window.addEventListener("DOMContentLoaded",G)})()})(); \ No newline at end of file + `}edited(e,t){this.notSaved[e]=t,this.componentContainer.current.classList.add("edited")}saved(e){delete this.notSaved[e]}isEdited(e){return!!this.notSaved[e]}}async function G(){console.info("My Markdown Site, version","0.1.5");const e=window.MMDS,t=await fetch("settings.json").catch((e=>{console.log("Can not access settings.json")})),r=(t&&"200"==t.status?await t.json():"")||window.settings,n=r?Object.assign(e.settings,r):e.settings;e.settings=n;const o=document.getElementById("menu"),a=document.getElementById("content");o&&z(e.makePath(e.settings.menuFile)).then((e=>{o.innerHTML=e.html})).catch((e=>console.log("no sidebar",e))),window.MMDS.settings.scripts.forEach(((t,r)=>{const n=document.createElement("script");n.setAttribute("src",e.settings.userScriptsPath+t),console.info(r,"Loading user script:",t),document.head.appendChild(n)})),e.addUpdater(((t,r)=>{const n=r.html.match(/

(.*?)<\/h1>/i);window.document.title=n?n[1].replace(/<[^>]+>/g,""):e.settings.title+": "+t})),window.document.addEventListener("click",(function(e){const t=e.target,r=t.getAttribute("href")||t.parentNode.getAttribute&&t.parentNode.getAttribute("href")||"";r&&!r.startsWith("data:")&&(console.log("link clicked",r),window.MMDS.go(r),e.preventDefault(),e.stopPropagation())})),window.addEventListener("hashchange",(function(){console.log("hash changed..."),window.MMDS.go(window.location.hash.substring(2))})),window.MMDS.cleanUp=()=>{console.log("removing listeners..."),window.removeEventListener("DOMContentLoaded",G)},a?(a.innerHTML="",L(p(H,{base:e.settings.mdDir}),a)):console.error("Content node not found"),window.location.hash?(history.replaceState({path:window.location.hash.substring(2),isMMMDSstate:!0},null),e.showPath(window.location.hash.substring(2))):(history.replaceState({path:window.MMDS.settings.indexFile,isMMMDSstate:!0},null,"#!"+window.MMDS.settings.indexFile),e.showPath(e.settings.indexFile))}r(7695),window.MMDS=new function(){var e=this;this.version="0.1.5",this.usr={},this.editMode=!1,this.current=null,this.settings={title:"MD Site",mdDir:"md/",indexFile:"index.md",menuFile:"menu.md",scripts:[],editorScript:"mdeditor.js",hideEditor:!1,userScriptsPath:"",usr:{}},this.page404=function(e){return{html:`

${e}

This page is not created yet. Click "edit" to create it.

`,markdown:`\x3c!--${e}--\x3e`}},this.errorPage=(e,t)=>404===t?this.page404(e):"number"==typeof t?{html:"

Error "+t+"

Something went wrong

",markdown:"\x3c!--error--\x3e"}:{html:"

Fatal error

Network down or host unreachable

",markdown:"\x3c!--Fatal error--\x3e"},this.makePath=e=>{const t=window.MMDS.settings.mdDir;return t?t+e:e},this._updaters={},this._handlers={};var t=1;this.makeID=function(){return t+=1},this.addUpdater=e=>(t++,this._updaters[t]=e,t),this.removeUpdater=t=>{delete e._updaters[t]},this.onMany=(e,t)=>e.map((e=>this.on(e,t))),this.on=(e,r)=>(console.log("setting listener",e),t+=1,this._handlers[e]||(this._handlers[e]={}),this._handlers[e][t]=r,t),this.off=(e,t)=>{try{delete this._handlers[e][t]}catch{console.error("Can not delete handler",t,"for",e)}},this.fire=(e,t)=>{this._handlers[e]&&Object.values(this._handlers[e]).forEach((e=>e(t)))},this.once=e=>{e(this)},this.whenActive=t=>{window.addEventListener("focus",(function(){t(e),window.removeEventListener("focus",this)}))},this.updateViews=(e,t)=>{Object.values(this._updaters).forEach((r=>r(e,t))),this.fire("views_updated")},this.refresh=()=>{this.updateViews(this.current.path,this.current.content)},this.reload=()=>{this.showPath(this.current.path,{cache:"reload"}),this.current.path===this.settings.menuFile&&this.action.setMenu(this.settings.menuFile,{cache:"reload"})},this.showContent=(e,t)=>{this.current={path:e,content:t,saved:!0},this.editMode||window.scrollTo(0,0),this.updateViews(e,t),this.fire("ready")},this.showPath=(e,t)=>{const r=document.createElement("div");r.id="loaderAnimation",r.innerHTML=this.settings.loaderText||"loading",r.style.opacity=1,document.body.appendChild(r);const n=this.on("ready",(()=>{r.style.opacity=0,window.setTimeout((()=>r.remove()),300),this.off("ready",n)})),o=this.makePath(e||this.settings.indexFile);return z(o,t).then((t=>{if(t.error)return console.info("Error:",t.error),void this.showContent(e,this.errorPage(e,t.error));this.showContent(e,t)})).catch((t=>{console.info("No such file",o,t),this.showContent(e,this.page404(e))}))},this.go=e=>(console.log("Incoming path",e),e.match(/^(http|ftp)(s)?\:/i)?(console.info("External link",e),this.cleanUp(),void(window.location=e)):e.match(/\.(md|mkd|mdwn|mdown|mdtxt|mdtext|markdown)$/i)?(e=e||this.settings.indexFile,console.info("Link to other page",e),this.showPath(e),void history.pushState({path:e,isMMMDSstate:!0},null,"#!"+e)):(console.info("Internal link, but not page",e),this.cleanUp(),void(window.location=this.makePath(e)))),this.action={edit:()=>{this.editMode=!0,function(){console.log("MMMDS editor, version","0.1.5");const e=document.getElementById("content"),t=p(H,{base:window.MMDS.settings.mdDir,path:window.MMDS.current.path||"",content:window.MMDS.current.content});L(null,e),L(t,e)}()},save:()=>{console.info("Saving without editing"),U(this.current.path,this.current.content.markdown)},setMenu:(e,t)=>{const r=document.getElementById("menu");e&&z(this.makePath(this.settings.menuFile),t).then((e=>{r.innerHTML=e.html,this.fire("redraw","menu")})).catch((e=>console.log("no sidebar",e)))}}},"loading"!=document.readyState?G():window.addEventListener("DOMContentLoaded",G)})()})(); \ No newline at end of file diff --git a/docs/settings.en.md b/docs/settings.en.md index c2be0d3..51ee40e 100644 --- a/docs/settings.en.md +++ b/docs/settings.en.md @@ -36,6 +36,7 @@ Please, note: if the `settings.json` present, all settings, defined in `index.ht | usr | {} | User scripts settings dictionary | | editorFile* | "mdeditor.js" | Path to editor script | | userScriptsPath* | "" | Path to user scripts | +| loaderText | "loading" | Text to display, while page is loading | [Settings explained] * experimental diff --git a/docs/settings.ru.md b/docs/settings.ru.md index 9e836f4..55ed1c9 100644 --- a/docs/settings.ru.md +++ b/docs/settings.ru.md @@ -38,6 +38,7 @@ | usr | {} | Словарь настроек пользовательских скриптов | | editorFile* | "mdeditor.js" | Путь, из которого будет загружаться скрипт редактора | | userScriptsPath* | "" | Путь, из которого будут загружаться пользовательские скрипты | +| loaderText | "loading" | Текст, отображаемый в процессе загрузки страницы | [Настройки, подробно] * экспериментальная опция diff --git a/package.json b/package.json index 7bffc05..d65964d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "md-site", - "version": "0.1.4", + "version": "0.1.5", "description": "", "scripts": { "test": "echo \"Error: no test specified\" && exit 1",