From 8902d9e9095e6c704910c542620ec65b3d52f91e Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Tue, 5 Nov 2024 16:21:44 +0100 Subject: [PATCH] [BUGFIX] Also apply premalink URI normalization for rstAnchor case Replacing "typo3/cms-xxx" with "typo3-cms-xxx" needs to happen at an earlier place. --- .../typo3-docs-theme/assets/js/link-reference-modal.js | 7 ++++--- packages/typo3-docs-theme/resources/public/js/theme.min.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/typo3-docs-theme/assets/js/link-reference-modal.js b/packages/typo3-docs-theme/assets/js/link-reference-modal.js index f9bd1446d..76a84663e 100644 --- a/packages/typo3-docs-theme/assets/js/link-reference-modal.js +++ b/packages/typo3-docs-theme/assets/js/link-reference-modal.js @@ -20,15 +20,16 @@ function generateShortUri(linkReferenceModal, section, headerText, rstAnchor, filename) { const urlPrefix = 'https://docs.typo3.org/permalink/'; const interlinkTarget = linkReferenceModal.dataset.interlinkShortcode || 'somemanual'; + // Replaces a link like "typo3/cms-sys-note" to "typo3-cms-sys-note" (https://docs.typo3.org/permalink/typo3-cms-sys-note:for-editors) + const adjustedInterlinkTarget = interlinkTarget.replaceAll('/', '-', interlinkTarget); + if (rstAnchor) { - return urlPrefix + `${interlinkTarget}:${rstAnchor}`; + return urlPrefix + `${adjustedInterlinkTarget}:${rstAnchor}`; } if (filename === '') { return ''; } - // Replaces a link like "typo3/cms-sys-note" to "typo3-cms-sys-note" (https://docs.typo3.org/permalink/typo3-cms-sys-note:for-editors) - const adjustedInterlinkTarget = interlinkTarget.replaceAll('/', '-', interlinkTarget); // @todo - check how anchor hashes + filenames work with redirects? Other edge cases? return urlPrefix + `${adjustedInterlinkTarget}:${filename}#${section?.id || ''}`; } diff --git a/packages/typo3-docs-theme/resources/public/js/theme.min.js b/packages/typo3-docs-theme/resources/public/js/theme.min.js index 78b1fda35..bab4b4f35 100644 --- a/packages/typo3-docs-theme/resources/public/js/theme.min.js +++ b/packages/typo3-docs-theme/resources/public/js/theme.min.js @@ -15,4 +15,4 @@ class AllDocumentationMenu extends HTMLElement{MAINMENU_JSON_URL="https://docs.t  TER - `),r(i))})})(),(()=>{const u="#permalink-uri",p="#permalink-short",m="#permalink-html";function h(o){const n=o.querySelector("#permalink-alert-success");var e=o.querySelectorAll(".copy-button");navigator.clipboard&&navigator.clipboard.writeText?e.forEach(e=>{e.addEventListener("click",function(){var e,t,a=this.getAttribute("data-target"),a=o.querySelector("#"+a);a?(n.classList.remove("d-none"),n.innerHTML=`Snippet ${e=a.value,t=document.createElement("div"),t.textContent=e,t.innerHTML} was copied to your clipboard.`,navigator.clipboard.writeText(a.value)):console.warn("Cannot copy link as no input is available!")})}):(console.info('"navigator.clipboard.writeText" is not available. Update to a modern browser to copy code to the system\'s clipboard'),e.forEach(e=>e.disabled=!0))}const g=document.querySelector("#linkReferenceModal");g.addEventListener("show.bs.modal",function(e){var t,a,o,e=e.relatedTarget,n=e.closest("section"),r=e.dataset.id||(n?n.dataset.rstAnchor:null),i=e.closest("h1, h2, h3, h4, h5, h6, dt"),i=i?i.innerText:"",s=e.dataset.rstcode,e=e.title,l=(l=g,c=r||s,l=l.querySelector(".alert-permalink-rst"),c?l.classList.add("d-none"):l.classList.remove("d-none"),c=n,l=r,"null"===window.location.origin||"file://"===window.location.origin?null:l?""+window.location.origin+window.location.pathname+"#"+l:""+window.location.origin+window.location.pathname+"#"+(c?.id||"")),c=g.dataset.currentFilename,d=s||(s=g,o=n,t=i,d=r,a=c,s=s.dataset.interlinkShortcode||"somemanual",d?`:ref:\`${t} <${s}:${d}>\``:""===a?"":`:doc:\`${t} <${s}:${a}#${o?.id||""}>\``),r=(t=g,s=n,a=r,o=c,n="https://docs.typo3.org/permalink/",t=t.dataset.interlinkShortcode||"somemanual",a?n+t+":"+a:""===o?"":n+t.replaceAll("/","-",t)+`:${o}#`+(s?.id||""));c=g,n=i,s=l,i=d,l=r,(r=e)&&(c.querySelector("h5").innerHTML=r),null===s?(c.querySelector(u).value="",c.querySelector(m).value="",c.querySelector(p).value=""):(c.querySelector(u).value=s,c.querySelector(p).value=l,c.querySelector(m).value=`${n}`),r=c.querySelector("#permalink-rst"),l=r.closest("div"),""===i?l.classList.add("d-none"):(l.classList.remove("d-none"),r.value=i),h(g)})})(),(()=>{"use strict";function a(e){e.preventDefault();const t=e.currentTarget.parentElement.parentElement;e=t.parentElement.parentElement.querySelectorAll("li.active");Array.from(e).forEach(e=>{e!==t&&e.classList.remove("active")}),t.classList.toggle("active")}{const o=document.getElementById("toc-toggle");o.addEventListener("click",()=>{return e=o,(t=document.getElementById("toc-collapse")).classList.toggle("show"),void e.setAttribute("aria-expanded",t.classList.contains("show"));var e,t},!0)}var e;e=document.getElementsByClassName("main_menu"),Array.from(e).forEach(e=>{e=e.getElementsByTagName("a");Array.from(e).forEach(e=>{var t;e.nextSibling&&((t=document.createElement("span")).classList.add("toctree-expand"),t.setAttribute("tabindex","0"),t.addEventListener("click",a,!0),t.addEventListener("keydown",e=>{"Enter"===e.key&&a(e)},!0),e.prepend(t))})})})(),window.addEventListener("load",()=>{var e,t,a=window.location.pathname.match(/^\/(c|m|p|h|other)\/[A-Za-z0-9\-_]+\/[A-Za-z0-9\-_]+\/[A-Za-z0-9\-.]+\/[A-Za-z0-9\-]+\/(Changelog\/[A-Za-z0-9\-.]+\/)?/),a=a?a[0]:null;a&&(e=document.getElementById("searchscope"),(t=document.createElement("option")).value=a,t.text="Search current",e.add(t))}),(()=>{"use strict";const e=Array.from(document.querySelectorAll('.nav-item > [role="tab"]'));function r(e){return e.innerHTML.trim()}document.addEventListener("shown.bs.tab",function(o){const n=r(o.target);e.filter(e=>{var t=r(e)===n,a=e===o.target,e="true"===e.getAttribute("aria-selected");return t&&!a&&!e}).forEach(e=>{new bootstrap.Tab(e).show()})})})(),(()=>{"use strict";const u="A_Default",p=1e5,n=document.getElementById("toc-version");function a(e,o){var t=document.createElement("dl"),n={"de-de":"German","de-at":"German (Austria)","de-ch":"German (Switzerland)","en-gb":"English","fr-fr":"French","ru-ru":"Russian"};if(n["en-us"]=u,"object"!=typeof o)console.log("AJAX version selector API: Request failed, no JSON returned."),e.innerHTML="

Versions unavailable.

";else{var r,i={currentfile:{},singlefile:{}};for(r in o){var s=o[r];let e=s.language,t=s.version;var l,c=n[e.toLocaleLowerCase()];c&&(e=c);let a="3_named";"main"===t?a="1_main":(c=t.trim(),l=parseFloat(c),isNaN(l)||Number(c)!==l||(t=t.split(".").map(e=>+e+p).join("."),a="2_numeric")),i.currentfile[e]||(i.currentfile[e]={},i.singlefile[e]={}),i.singlefile[e][a]||(i.currentfile[e][a]={},i.singlefile[e][a]={}),i.singlefile[e][a][t]||(i.currentfile[e][a][t]={},i.singlefile[e][a][t]={}),i.currentfile[e][a][t]=s.url,i.singlefile[e][a][t]=s.singleUrl}var a=function t(a){{if(null===a||"object"!=typeof a||Array.isArray(a))return a;{const o={},e=Object.keys(a).filter(e=>!isNaN(e)).sort((e,t)=>t-e),n=Object.keys(a).filter(e=>isNaN(e)).sort(),r=[...e,...n];return r.forEach(e=>{o[e]=t(a[e])}),o}}}(i),d="",d=(d+=m("currentfile",a))+m("singlefile",a);t.innerHTML=d,e.innerHTML="",e.appendChild(t)}}function m(t,a){let o="";for(var n in"singlefile"===t&&(o+="

In one file:"),a[t]){var e,r,i;for(i in n!=u&&(e=Object.keys(a[t][n])[0],r=Object.keys(a[t][n][e])[0],o+='
'+n+"
"),a[t][n])for(var s in a[t][n][i]){let e=s;"2_numeric"===i&&(e=s.split(".").map(e=>+e-p).join(".")),o+='
'+e+"
"}}return"singlefile"===t&&(o+="

"),o}function t(){var e=document.getElementById("toc-version-wrapper");const t=document.getElementById("toc-version-options");e.classList.toggle("toc-version-wrapper-active"),t.dataset.ready||async function(){let e=document.URL,t="https://docs.typo3.org/services/versionsJson.php?url=";n.getAttribute("data-override-url-self")&&(e=n.getAttribute("data-override-url-self"),t=n.getAttribute("data-override-url-proxy"),console.log("AJAX version selector API: Developer mode enabled. Adjust data-override-url-self to simulate different menus. More information: https://docs.typo3.org/other/t3docs/render-guides/main/en-us/Developer/AjaxVersions.html"),console.log("Currently: "+e),console.log("The API PROXY is currently served from: "+t));var a=t+encodeURI(e);try{var o=await fetch(a);return o.ok?o.json():(console.log("AJAX version selector API: Request failure or empty response."),"")}catch(e){return console.log("AJAX version selector API: Request failed, likely CORS issue. Read the documentation to configure a proxy."),""}}().then(e=>{""===e&&(e="

No data available.

"),a(t,e),t.dataset.ready="true"})}n&&(n.addEventListener("click",t),n.addEventListener("keypress",e=>{"Enter"===e.key&&t()}))})(); \ No newline at end of file + `),r(i))})})(),(()=>{const u="#permalink-uri",p="#permalink-short",m="#permalink-html";function h(o){const n=o.querySelector("#permalink-alert-success");var e=o.querySelectorAll(".copy-button");navigator.clipboard&&navigator.clipboard.writeText?e.forEach(e=>{e.addEventListener("click",function(){var e,t,a=this.getAttribute("data-target"),a=o.querySelector("#"+a);a?(n.classList.remove("d-none"),n.innerHTML=`Snippet ${e=a.value,t=document.createElement("div"),t.textContent=e,t.innerHTML} was copied to your clipboard.`,navigator.clipboard.writeText(a.value)):console.warn("Cannot copy link as no input is available!")})}):(console.info('"navigator.clipboard.writeText" is not available. Update to a modern browser to copy code to the system\'s clipboard'),e.forEach(e=>e.disabled=!0))}const g=document.querySelector("#linkReferenceModal");g.addEventListener("show.bs.modal",function(e){var t,a,o,e=e.relatedTarget,n=e.closest("section"),r=e.dataset.id||(n?n.dataset.rstAnchor:null),i=e.closest("h1, h2, h3, h4, h5, h6, dt"),i=i?i.innerText:"",s=e.dataset.rstcode,e=e.title,l=(l=g,c=r||s,l=l.querySelector(".alert-permalink-rst"),c?l.classList.add("d-none"):l.classList.remove("d-none"),c=n,l=r,"null"===window.location.origin||"file://"===window.location.origin?null:l?""+window.location.origin+window.location.pathname+"#"+l:""+window.location.origin+window.location.pathname+"#"+(c?.id||"")),c=g.dataset.currentFilename,d=s||(s=g,o=n,t=i,d=r,a=c,s=s.dataset.interlinkShortcode||"somemanual",d?`:ref:\`${t} <${s}:${d}>\``:""===a?"":`:doc:\`${t} <${s}:${a}#${o?.id||""}>\``),r=(t=g,s=n,a=r,o=c,n="https://docs.typo3.org/permalink/",t=(t=t.dataset.interlinkShortcode||"somemanual").replaceAll("/","-",t),a?n+t+":"+a:""===o?"":n+t+`:${o}#`+(s?.id||""));c=g,n=i,s=l,i=d,l=r,(r=e)&&(c.querySelector("h5").innerHTML=r),null===s?(c.querySelector(u).value="",c.querySelector(m).value="",c.querySelector(p).value=""):(c.querySelector(u).value=s,c.querySelector(p).value=l,c.querySelector(m).value=`${n}`),r=c.querySelector("#permalink-rst"),l=r.closest("div"),""===i?l.classList.add("d-none"):(l.classList.remove("d-none"),r.value=i),h(g)})})(),(()=>{"use strict";function a(e){e.preventDefault();const t=e.currentTarget.parentElement.parentElement;e=t.parentElement.parentElement.querySelectorAll("li.active");Array.from(e).forEach(e=>{e!==t&&e.classList.remove("active")}),t.classList.toggle("active")}{const o=document.getElementById("toc-toggle");o.addEventListener("click",()=>{return e=o,(t=document.getElementById("toc-collapse")).classList.toggle("show"),void e.setAttribute("aria-expanded",t.classList.contains("show"));var e,t},!0)}var e;e=document.getElementsByClassName("main_menu"),Array.from(e).forEach(e=>{e=e.getElementsByTagName("a");Array.from(e).forEach(e=>{var t;e.nextSibling&&((t=document.createElement("span")).classList.add("toctree-expand"),t.setAttribute("tabindex","0"),t.addEventListener("click",a,!0),t.addEventListener("keydown",e=>{"Enter"===e.key&&a(e)},!0),e.prepend(t))})})})(),window.addEventListener("load",()=>{var e,t,a=window.location.pathname.match(/^\/(c|m|p|h|other)\/[A-Za-z0-9\-_]+\/[A-Za-z0-9\-_]+\/[A-Za-z0-9\-.]+\/[A-Za-z0-9\-]+\/(Changelog\/[A-Za-z0-9\-.]+\/)?/),a=a?a[0]:null;a&&(e=document.getElementById("searchscope"),(t=document.createElement("option")).value=a,t.text="Search current",e.add(t))}),(()=>{"use strict";const e=Array.from(document.querySelectorAll('.nav-item > [role="tab"]'));function r(e){return e.innerHTML.trim()}document.addEventListener("shown.bs.tab",function(o){const n=r(o.target);e.filter(e=>{var t=r(e)===n,a=e===o.target,e="true"===e.getAttribute("aria-selected");return t&&!a&&!e}).forEach(e=>{new bootstrap.Tab(e).show()})})})(),(()=>{"use strict";const u="A_Default",p=1e5,n=document.getElementById("toc-version");function a(e,o){var t=document.createElement("dl"),n={"de-de":"German","de-at":"German (Austria)","de-ch":"German (Switzerland)","en-gb":"English","fr-fr":"French","ru-ru":"Russian"};if(n["en-us"]=u,"object"!=typeof o)console.log("AJAX version selector API: Request failed, no JSON returned."),e.innerHTML="

Versions unavailable.

";else{var r,i={currentfile:{},singlefile:{}};for(r in o){var s=o[r];let e=s.language,t=s.version;var l,c=n[e.toLocaleLowerCase()];c&&(e=c);let a="3_named";"main"===t?a="1_main":(c=t.trim(),l=parseFloat(c),isNaN(l)||Number(c)!==l||(t=t.split(".").map(e=>+e+p).join("."),a="2_numeric")),i.currentfile[e]||(i.currentfile[e]={},i.singlefile[e]={}),i.singlefile[e][a]||(i.currentfile[e][a]={},i.singlefile[e][a]={}),i.singlefile[e][a][t]||(i.currentfile[e][a][t]={},i.singlefile[e][a][t]={}),i.currentfile[e][a][t]=s.url,i.singlefile[e][a][t]=s.singleUrl}var a=function t(a){{if(null===a||"object"!=typeof a||Array.isArray(a))return a;{const o={},e=Object.keys(a).filter(e=>!isNaN(e)).sort((e,t)=>t-e),n=Object.keys(a).filter(e=>isNaN(e)).sort(),r=[...e,...n];return r.forEach(e=>{o[e]=t(a[e])}),o}}}(i),d="",d=(d+=m("currentfile",a))+m("singlefile",a);t.innerHTML=d,e.innerHTML="",e.appendChild(t)}}function m(t,a){let o="";for(var n in"singlefile"===t&&(o+="

In one file:"),a[t]){var e,r,i;for(i in n!=u&&(e=Object.keys(a[t][n])[0],r=Object.keys(a[t][n][e])[0],o+='
'+n+"
"),a[t][n])for(var s in a[t][n][i]){let e=s;"2_numeric"===i&&(e=s.split(".").map(e=>+e-p).join(".")),o+='
'+e+"
"}}return"singlefile"===t&&(o+="

"),o}function t(){var e=document.getElementById("toc-version-wrapper");const t=document.getElementById("toc-version-options");e.classList.toggle("toc-version-wrapper-active"),t.dataset.ready||async function(){let e=document.URL,t="https://docs.typo3.org/services/versionsJson.php?url=";n.getAttribute("data-override-url-self")&&(e=n.getAttribute("data-override-url-self"),t=n.getAttribute("data-override-url-proxy"),console.log("AJAX version selector API: Developer mode enabled. Adjust data-override-url-self to simulate different menus. More information: https://docs.typo3.org/other/t3docs/render-guides/main/en-us/Developer/AjaxVersions.html"),console.log("Currently: "+e),console.log("The API PROXY is currently served from: "+t));var a=t+encodeURI(e);try{var o=await fetch(a);return o.ok?o.json():(console.log("AJAX version selector API: Request failure or empty response."),"")}catch(e){return console.log("AJAX version selector API: Request failed, likely CORS issue. Read the documentation to configure a proxy."),""}}().then(e=>{""===e&&(e="

No data available.

"),a(t,e),t.dataset.ready="true"})}n&&(n.addEventListener("click",t),n.addEventListener("keypress",e=>{"Enter"===e.key&&t()}))})(); \ No newline at end of file