From a3ddb1bde73fa190beb553a3b2b59498671fe09e Mon Sep 17 00:00:00 2001 From: Geoffrey Garrett Date: Wed, 29 Jun 2022 22:39:01 +0200 Subject: [PATCH] fix(code titles): fixed code titles with and without SPA --- layouts/partials/head.html | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index e6b8dc9b6..04b9c0dea 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -76,12 +76,13 @@ const render = () => { // NOTE: everything within this callback will be executed for every page navigation. This is a good place to put JavaScript that loads or modifies data on the page, adds event listeners, etc. If you are only dealing with basic DOM replacement, use the init function - const siteBaseURL = new URL({{$.Site.BaseURL}}); const pathBase = siteBaseURL.pathname; const pathWindow = window.location.pathname; const isHome = pathBase == pathWindow; + + {{if $.Site.Data.config.enableFooter}} const container = document.getElementById("graph-container") // retry if the graph is not ready @@ -99,9 +100,6 @@ {{end}} - {{if $.Site.Data.config.enableCodeBlockTitle -}} - addTitleToCodeBlocks(); - {{- end -}} {{if $.Site.Data.config.enableLinkPreview}} initPopover( @@ -114,6 +112,13 @@ const init = (doc = document) => { // NOTE: everything within this callback will be executed for initial page navigation. This is a good place to put JavaScript that only replaces DOM nodes. + {{if $.Site.Data.config.enableCodeBlockTitle -}} + {{if $.Site.Data.config.enableSPA -}} + addTitleToCodeBlocks(); + {{ else }} + window.addEventListener("DOMContentLoaded", addTitleToCodeBlocks); + {{- end -}} + {{- end -}} {{if $.Site.Data.config.enableLatex}} renderMathInElement(doc.body, { delimiters: [