From 9ca710fd98dc64bf2c94707fe6f65b458d386be2 Mon Sep 17 00:00:00 2001 From: Mara-Li Date: Wed, 3 Jan 2024 02:09:15 +0100 Subject: [PATCH 1/3] Update misc.js A tester --- src/js/misc.js | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/src/js/misc.js b/src/js/misc.js index 15aaffd..f1d0957 100644 --- a/src/js/misc.js +++ b/src/js/misc.js @@ -23,42 +23,31 @@ if (header_links) { * @param {string} alt * @param {number} originalWidth * @param {number} originalHeight - * @returns number[] + * @returns {width: number, height: number} */ function getHeightWidth(alt, originalWidth, originalHeight) { - const heightXwidthReg = new RegExp("\\d+x\\d+"); const widthReg = new RegExp("\\d+"); - if (alt.match(heightXwidthReg)) { - const width = parseInt(alt.split("x")[0]); - const height = parseInt(alt.split("x")[1]); - return [width, height]; - } else if (alt.match(widthReg)) { + if (alt.match(/\d+x\d+/i)) { + let width = parseInt(alt.split("x")[0]); + width = width > 0 ? width : originalWidth + let height = parseInt(alt.split("x")[1]); + height = height > 0 ? height : originalHeight + return {width, height}; + } else if (alt.match(/\d+/i)) { const width = parseInt(alt.match(widthReg)[0]); - return [width, originalHeight]; - } else { - return [originalWidth, originalHeight]; - } + return {width, height: originalHeight]; + } + return {width: originalWidth, height: originalHeight}; } for (const i of document.querySelectorAll("img")) { - const regAlt = new RegExp("\\|"); const alt = i.alt; - if (alt.match(regAlt)) { - const altSplitted = alt.split("|"); - for (const part of altSplitted) { - if (part.match(new RegExp("\\d+", "g"))) { - var size = getHeightWidth(part, i.width, i.height); - i.width = size[0] > 0 ? size[0] : i.width; - i.height = size[1] > 0 ? size[1] : i.height; - var partReg = new RegExp(`\\${part}`); - i.alt = alt.replace(partReg, ""); - } - } - } else if (alt !== i.title && alt.match(/^\d+(x\d+)?|\|\d+(x\d+)/g)) { - const size = getHeightWidth(alt, i.width, i.height); - i.width = size[0] > 0 ? size[0] : i.width; - i.height = size[1] > 0 ? size[1] : i.height; - i.alt = alt.replace(/^\d+(x\d+)?|\|\d+(x\d+)?/gi, ""); + const resize = /^\d+(x\d+)?|\|\d+(x\d+)/gi + if (alt.match(resize) && alt != i.title) { + const {width, height} = getHeightWidth(part, i.width, i.height); + i.width = width; + i.height = height; + i.alt = alt.replace(resize, ""); } } From f1940baad9e881c674896dfab4b9dbf78aec2d12 Mon Sep 17 00:00:00 2001 From: Mara-Li Date: Wed, 3 Jan 2024 02:12:00 +0000 Subject: [PATCH 2/3] fix: typo --- src/js/misc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/misc.js b/src/js/misc.js index f1d0957..7ad6fbe 100644 --- a/src/js/misc.js +++ b/src/js/misc.js @@ -35,8 +35,8 @@ function getHeightWidth(alt, originalWidth, originalHeight) { return {width, height}; } else if (alt.match(/\d+/i)) { const width = parseInt(alt.match(widthReg)[0]); - return {width, height: originalHeight]; - } + return {width, height: originalHeight}; + } return {width: originalWidth, height: originalHeight}; } From 1d3424f94ae19b5414d1387b5ad5de842c3a6394 Mon Sep 17 00:00:00 2001 From: Mara-Li Date: Wed, 3 Jan 2024 02:12:19 +0000 Subject: [PATCH 3/3] chore: gulp --- dist/javascript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/javascript.js b/dist/javascript.js index 9509792..41a063f 100644 --- a/dist/javascript.js +++ b/dist/javascript.js @@ -1 +1 @@ -function parseURL(e,t){let r="",n="";return 0===t?(r=e.href,n=e.title):1===t&&(r=e.src,n=e.alt),(r=(r=r.match(/index$/)?r.replace(/index$/,""):r).includes("%5C")?r.replace(/%5C/g,"/"):r).match(/\.md\/$/)&&(r=r.replace(/\.md\/$/,"/")),r=decodeURI(r),0===t?(e.href=r,0===(e.title=n).length&&(n=e.innerText,e.title=n)):1===t&&(e.src=r,e.alt=n),{title:n,ref:r,url:e}}function checkIfInternalLinksExists(t,r,n,i){let l=n.href.replace(n.host,"").replace(/http(s)?:(\/){1,3}/gi,"").replace(/^\//,"");l=0===l.trim().length?"./":decodeURI(l).toLowerCase();var e=document.querySelector('meta[name="site_url"]').content,o=e.split("/").filter(e=>0e.json()).then(e=>{if(e.forEach(e=>{decodeURI(e.url).toLowerCase()===l&&i.push(l.replace(/\/$/,""))}),!(i=[...new Set(i)]).includes(l.replace(/\/$/,""))&&"./"!==l){e=document.createElement("div");e.innerHTML=r,e.classList.add("not_found"),e.setAttribute("href",t);try{n.parentNode.replaceChild(e,n)}catch(e){console.log(e)}}}).catch(e=>{console.log(e)}),i}window.MathJax={tex:{inlineMath:[["\\(","\\)"]],displayMath:[["\\[","\\]"]],processEscapes:!0,processEnvironments:!0},options:{ignoreHtmlClass:".*|",processHtmlClass:"arithmatex"}},document$.subscribe(()=>{MathJax.typesetPromise()});let history=[];const ht=document.querySelectorAll("article a:not(img, .headerlink)");for(const u of ht)0{e.forEach(e=>{"attributes"===e.type&&chirpy.setAttribute("data-chirpy-theme",mkDocsChirpyTranslator[mkDocs.dataset.mdColorScheme])})});w.observe(mkDocs,{attributes:!0,attributeFilter:["data-md-color-scheme"]})}const header_links=document.querySelectorAll('a[href*="#"]');if(header_links)for(var i=0;i *:not(.highlight)"),embed_id_regex=/\^\w+\s*$/gi;for(const N of article){const O=N.innerText.match(embed_id_regex);O&&(N.innerHTML=N.innerText.replace(O,""))}document.innerText=article;const cite=document.querySelectorAll(".citation");if(cite)for(i=0;i{e.href.endsWith(".css")&&t.push(e.href)});const r=e.contentDocument||e.contentWindow.document;t.forEach(e=>{var t=document.createElement("link");t.rel="stylesheet",t.href=e,t.type="text/css",r.head.appendChild(t)});var e=document.querySelector("[data-md-color-scheme]");"default"===e.getAttribute("data-md-color-scheme")?r.body.setAttribute("class","light"):(r.body.setAttribute("class","dark"),e=getComputedStyle(e).getPropertyValue("--md-default-bg-color"),r.body.style.setProperty("--md-default-bg-color",e)),r.body.classList.add("graph-view")}};const paletteSwitcher1=document.getElementById("__palette_1"),paletteSwitcher2=document.getElementById("__palette_2"),isMermaidPage=document.querySelector(".mermaid"),blogURL=(isMermaidPage&&(paletteSwitcher1.addEventListener("change",()=>{location.reload()}),paletteSwitcher2.addEventListener("change",()=>{location.reload()})),document.querySelector('meta[name="site_url"]')?document.querySelector('meta[name="site_url"]').content:location.origin),position=["top","right","bottom","left"];function brokenImage(e){var t=e?.querySelectorAll("img");if(t)for(let e=0;ee.text()).then(e=>{return(new DOMParser).parseFromString(e,"text/html")}).then(i=>{return i.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function(t){var r=t.id||t.innerText.split("\n")[0].toLowerCase().replaceAll(" ","-");if(0{if(location.href.replace(location.hash,"")===l.reference.href)l.hide(),l.destroy();else{let e=r.querySelector("article");var n=r.querySelector("h1"),n=(n&&"Index"===n.innerText&&(i=decodeURI(r.querySelector('link[rel="canonical"]').href).split("/").filter(e=>e).pop(),n.innerText=i),e=brokenImage(e),document.querySelector('[id^="tippy"]')),i=(n&&n.classList.add("tippy"),l.reference.href.replace(/.*#/,"#"));let t=e;i.startsWith("#")?((e=r.querySelector(`[id="${i.replace("#","")}"]`)).tagName.includes("H")?((n=r.createElement("article")).classList.add("md-content__inner","md-typeset"),n.appendChild(r.querySelector("div."+i.replace("#",""))),t=n,e=t):t=0===e.innerText.replace(i).length?e=r.querySelector("div.citation"):cleanText(e).innerText,l.popper.style.height="auto"):l.popper.style.height=calculateHeight(e),l.popper.placement=position[Math.floor(Math.random()*position.length)],0{console.log(e),l.hide(),l.destroy()})}})}catch{console.log("tippy error, ignore it")} \ No newline at end of file +function parseURL(e,t){let r="",n="";return 0===t?(r=e.href,n=e.title):1===t&&(r=e.src,n=e.alt),(r=(r=r.match(/index$/)?r.replace(/index$/,""):r).includes("%5C")?r.replace(/%5C/g,"/"):r).match(/\.md\/$/)&&(r=r.replace(/\.md\/$/,"/")),r=decodeURI(r),0===t?(e.href=r,0===(e.title=n).length&&(n=e.innerText,e.title=n)):1===t&&(e.src=r,e.alt=n),{title:n,ref:r,url:e}}function checkIfInternalLinksExists(t,r,n,i){let l=n.href.replace(n.host,"").replace(/http(s)?:(\/){1,3}/gi,"").replace(/^\//,"");l=0===l.trim().length?"./":decodeURI(l).toLowerCase();var e=document.querySelector('meta[name="site_url"]').content,o=e.split("/").filter(e=>0e.json()).then(e=>{if(e.forEach(e=>{decodeURI(e.url).toLowerCase()===l&&i.push(l.replace(/\/$/,""))}),!(i=[...new Set(i)]).includes(l.replace(/\/$/,""))&&"./"!==l){e=document.createElement("div");e.innerHTML=r,e.classList.add("not_found"),e.setAttribute("href",t);try{n.parentNode.replaceChild(e,n)}catch(e){console.log(e)}}}).catch(e=>{console.log(e)}),i}window.MathJax={tex:{inlineMath:[["\\(","\\)"]],displayMath:[["\\[","\\]"]],processEscapes:!0,processEnvironments:!0},options:{ignoreHtmlClass:".*|",processHtmlClass:"arithmatex"}},document$.subscribe(()=>{MathJax.typesetPromise()});let history=[];const ht=document.querySelectorAll("article a:not(img, .headerlink)");for(const u of ht)0{e.forEach(e=>{"attributes"===e.type&&chirpy.setAttribute("data-chirpy-theme",mkDocsChirpyTranslator[mkDocs.dataset.mdColorScheme])})});w.observe(mkDocs,{attributes:!0,attributeFilter:["data-md-color-scheme"]})}const header_links=document.querySelectorAll('a[href*="#"]');if(header_links)for(var i=0;i *:not(.highlight)"),embed_id_regex=/\^\w+\s*$/gi;for(const M of article){const N=M.innerText.match(embed_id_regex);N&&(M.innerHTML=M.innerText.replace(N,""))}document.innerText=article;const cite=document.querySelectorAll(".citation");if(cite)for(i=0;i{e.href.endsWith(".css")&&t.push(e.href)});const r=e.contentDocument||e.contentWindow.document;t.forEach(e=>{var t=document.createElement("link");t.rel="stylesheet",t.href=e,t.type="text/css",r.head.appendChild(t)});var e=document.querySelector("[data-md-color-scheme]");"default"===e.getAttribute("data-md-color-scheme")?r.body.setAttribute("class","light"):(r.body.setAttribute("class","dark"),e=getComputedStyle(e).getPropertyValue("--md-default-bg-color"),r.body.style.setProperty("--md-default-bg-color",e)),r.body.classList.add("graph-view")}};const paletteSwitcher1=document.getElementById("__palette_1"),paletteSwitcher2=document.getElementById("__palette_2"),isMermaidPage=document.querySelector(".mermaid"),blogURL=(isMermaidPage&&(paletteSwitcher1.addEventListener("change",()=>{location.reload()}),paletteSwitcher2.addEventListener("change",()=>{location.reload()})),document.querySelector('meta[name="site_url"]')?document.querySelector('meta[name="site_url"]').content:location.origin),position=["top","right","bottom","left"];function brokenImage(e){var t=e?.querySelectorAll("img");if(t)for(let e=0;ee.text()).then(e=>{return(new DOMParser).parseFromString(e,"text/html")}).then(i=>{return i.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function(t){var r=t.id||t.innerText.split("\n")[0].toLowerCase().replaceAll(" ","-");if(0{if(location.href.replace(location.hash,"")===l.reference.href)l.hide(),l.destroy();else{let e=r.querySelector("article");var n=r.querySelector("h1"),n=(n&&"Index"===n.innerText&&(i=decodeURI(r.querySelector('link[rel="canonical"]').href).split("/").filter(e=>e).pop(),n.innerText=i),e=brokenImage(e),document.querySelector('[id^="tippy"]')),i=(n&&n.classList.add("tippy"),l.reference.href.replace(/.*#/,"#"));let t=e;i.startsWith("#")?((e=r.querySelector(`[id="${i.replace("#","")}"]`)).tagName.includes("H")?((n=r.createElement("article")).classList.add("md-content__inner","md-typeset"),n.appendChild(r.querySelector("div."+i.replace("#",""))),t=n,e=t):t=0===e.innerText.replace(i).length?e=r.querySelector("div.citation"):cleanText(e).innerText,l.popper.style.height="auto"):l.popper.style.height=calculateHeight(e),l.popper.placement=position[Math.floor(Math.random()*position.length)],0{console.log(e),l.hide(),l.destroy()})}})}catch{console.log("tippy error, ignore it")} \ No newline at end of file