From fcd5d2807d2bab68c6776e031e85d65fe88a6f7a Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Wed, 16 Feb 2022 00:39:14 +0000
Subject: [PATCH] feat: dynamically fetch indices
---
layouts/partials/popover.html | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/layouts/partials/popover.html b/layouts/partials/popover.html
index d9cc941..35f0738 100644
--- a/layouts/partials/popover.html
+++ b/layouts/partials/popover.html
@@ -1,4 +1,7 @@
+{{if $.Site.Data.config.enableLinkPreview}}
<script>
+async function run() {
+ const {content} = await fetchData()
function htmlToElement(html) {
const template = document.createElement('template')
html = html.trim()
@@ -6,10 +9,11 @@
return template.content.firstChild
}
+ const pathRegex = /\.\.?(\/\.\.)*/
document.addEventListener("DOMContentLoaded", () => {
[...document.getElementsByClassName("internal-link")]
.forEach(li => {
- const linkDest = content[li.dataset.src]
+ const linkDest = content[li.dataset.src.replace(pathRegex, '')]
if (linkDest) {
const popoverElement = `<div class="popover">
<h3>${linkDest.title}</h3>
@@ -26,4 +30,8 @@
}
})
})
-</script>
\ No newline at end of file
+}
+
+run()
+</script>
+{{end}}
\ No newline at end of file
--
Gitblit v1.10.0