Skip to content

Commit 7ba48df

Browse files
committed
Properly offset the current page when comparing to listing
1 parent af67eac commit 7ba48df

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/resources/formats/html/quarto.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,13 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
146146
function offsetAbsoluteUrl(url) {
147147
const offset = getMeta("quarto:offset");
148148
const baseUrl = new URL(offset, window.location);
149+
149150
const projRelativeUrl = url.replace(baseUrl, "");
150-
return "/" + projRelativeUrl;
151+
if (projRelativeUrl.startsWith("/")) {
152+
return projRelativeUrl;
153+
} else {
154+
return "/" + projRelativeUrl;
155+
}
151156
}
152157

153158
// read a meta tag value
@@ -162,15 +167,18 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
162167
}
163168

164169
async function findAndActivateCategories() {
165-
const thisPath = window.location.pathname;
170+
const currentPagePath = offsetAbsoluteUrl(window.location.href);
166171
const response = await fetch(offsetRelativeUrl("listings.json"));
167172
if (response.status == 200) {
168173
return response.json().then(function (listingPaths) {
169174
const listingHrefs = [];
170175
for (const listingPath of listingPaths) {
171176
const pathWithoutLeadingSlash = listingPath.listing.substring(1);
172177
for (const item of listingPath.items) {
173-
if (item === thisPath || item === thisPath + "index.html") {
178+
if (
179+
item === currentPagePath ||
180+
item === currentPagePath + "index.html"
181+
) {
174182
// Resolve this path against the offset to be sure
175183
// we already are using the correct path to the listing
176184
// (this adjusts the listing urls to be rooted against

0 commit comments

Comments
 (0)