fix relative pathing for dynamic fetch

This commit is contained in:
Jacky Zhao 2022-02-15 22:54:20 -05:00
parent 8e85e274f6
commit 3b3e6ec3b2
5 changed files with 63 additions and 45 deletions

View file

@ -26,24 +26,33 @@
<!-- Preload page vars -->
<script>
const fetchData = async () => {
const promises = [
fetch("/linkIndex.json")
.then(data => data.json())
.then(data => ({
index: data.index,
links: data.links,
})),
fetch("/contentIndex.json")
.then(data => data.json()),
]
const [{index, links}, content] = await Promise.all(promises)
return ({
index,
links,
content,
})
}
let saved = false
const fetchData = async () => {
if (saved) {
return saved
} else {
const promises = [
fetch("{{ .Site.BaseURL }}/linkIndex.json")
.then(data => data.json())
.then(data => ({
index: data.index,
links: data.links,
})),
fetch("{{ .Site.BaseURL }}/contentIndex.json")
.then(data => data.json()),
]
const [{index, links}, content] = await Promise.all(promises)
const res = ({
index,
links,
content,
})
saved = res
return res
}
}
fetchData()
</script>
</head>
{{ template "_internal/google_analytics.html" . }}