Skip to content

Commit f50339c

Browse files
committed
fix(html): resolve search links from docs root
1 parent 275805a commit f50339c

4 files changed

Lines changed: 8 additions & 28 deletions

File tree

src/html/templates/pages/search.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ const Fuse = window.Fuse;
33
const searchInput = document.querySelector("#searchbar");
44
const contentDiv = document.querySelector("#content");
55
const searchResultsDiv = document.querySelector("#searchResults");
6-
const currentFile =
7-
document.querySelector("meta[name='doc-current-file']").attributes
8-
.getNamedItem("content").value;
9-
const pathToRoot = "../".repeat(
10-
currentFile ? (currentFile.split("/").length + 1) : 0,
11-
);
6+
const rootUrl = new URL(".", document.currentScript.src);
127
searchInput.removeAttribute("style");
138

149
const SEARCH_INDEX = window.DENO_DOC_SEARCH_INDEX;
@@ -121,7 +116,7 @@ function renderResults(results) {
121116
}).join("");
122117

123118
html += `<li class="block">
124-
<a href="${pathToRoot}${result.file}/~/${result.name}.html" class="flex rounded-lg gap-4 items-center justify-between py-2 px-3 hover:bg-stone-100 dark:hover:bg-stone-800">
119+
<a href="${rootUrl.href}${result.file === "." ? "" : `${result.file}/`}~/${result.name}.html" class="flex rounded-lg gap-4 items-center justify-between py-2 px-3 hover:bg-stone-100 dark:hover:bg-stone-800">
125120
<div class="flex items-center gap-2.5">
126121
<div class="docNodeKindIcon">
127122
${kind}

tests/snapshots/html_test__html_doc_dts-13.snap

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ const Fuse = window.Fuse;
77
const searchInput = document.querySelector("#searchbar");
88
const contentDiv = document.querySelector("#content");
99
const searchResultsDiv = document.querySelector("#searchResults");
10-
const currentFile =
11-
document.querySelector("meta[name='doc-current-file']").attributes
12-
.getNamedItem("content").value;
13-
const pathToRoot = "../".repeat(
14-
currentFile ? (currentFile.split("/").length + 1) : 0,
15-
);
10+
const rootUrl = new URL(".", document.currentScript.src);
1611
searchInput.removeAttribute("style");
1712

1813
const SEARCH_INDEX = window.DENO_DOC_SEARCH_INDEX;
@@ -125,7 +120,7 @@ function renderResults(results) {
125120
}).join("");
126121
127122
html += `<li class="block">
128-
<a href="${pathToRoot}${result.file}/~/${result.name}.html" class="flex rounded-lg gap-4 items-center justify-between py-2 px-3 hover:bg-stone-100 dark:hover:bg-stone-800">
123+
<a href="${rootUrl.href}${result.file === "." ? "" : `${result.file}/`}~/${result.name}.html" class="flex rounded-lg gap-4 items-center justify-between py-2 px-3 hover:bg-stone-100 dark:hover:bg-stone-800">
129124
<div class="flex items-center gap-2.5">
130125
<div class="docNodeKindIcon">
131126
${kind}

tests/snapshots/html_test__html_doc_files_multiple-72.snap

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ const Fuse = window.Fuse;
77
const searchInput = document.querySelector("#searchbar");
88
const contentDiv = document.querySelector("#content");
99
const searchResultsDiv = document.querySelector("#searchResults");
10-
const currentFile =
11-
document.querySelector("meta[name='doc-current-file']").attributes
12-
.getNamedItem("content").value;
13-
const pathToRoot = "../".repeat(
14-
currentFile ? (currentFile.split("/").length + 1) : 0,
15-
);
10+
const rootUrl = new URL(".", document.currentScript.src);
1611
searchInput.removeAttribute("style");
1712

1813
const SEARCH_INDEX = window.DENO_DOC_SEARCH_INDEX;
@@ -125,7 +120,7 @@ function renderResults(results) {
125120
}).join("");
126121
127122
html += `<li class="block">
128-
<a href="${pathToRoot}${result.file}/~/${result.name}.html" class="flex rounded-lg gap-4 items-center justify-between py-2 px-3 hover:bg-stone-100 dark:hover:bg-stone-800">
123+
<a href="${rootUrl.href}${result.file === "." ? "" : `${result.file}/`}~/${result.name}.html" class="flex rounded-lg gap-4 items-center justify-between py-2 px-3 hover:bg-stone-100 dark:hover:bg-stone-800">
129124
<div class="flex items-center gap-2.5">
130125
<div class="docNodeKindIcon">
131126
${kind}

tests/snapshots/html_test__html_doc_files_single-12.snap

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ const Fuse = window.Fuse;
77
const searchInput = document.querySelector("#searchbar");
88
const contentDiv = document.querySelector("#content");
99
const searchResultsDiv = document.querySelector("#searchResults");
10-
const currentFile =
11-
document.querySelector("meta[name='doc-current-file']").attributes
12-
.getNamedItem("content").value;
13-
const pathToRoot = "../".repeat(
14-
currentFile ? (currentFile.split("/").length + 1) : 0,
15-
);
10+
const rootUrl = new URL(".", document.currentScript.src);
1611
searchInput.removeAttribute("style");
1712

1813
const SEARCH_INDEX = window.DENO_DOC_SEARCH_INDEX;
@@ -125,7 +120,7 @@ function renderResults(results) {
125120
}).join("");
126121
127122
html += `<li class="block">
128-
<a href="${pathToRoot}${result.file}/~/${result.name}.html" class="flex rounded-lg gap-4 items-center justify-between py-2 px-3 hover:bg-stone-100 dark:hover:bg-stone-800">
123+
<a href="${rootUrl.href}${result.file === "." ? "" : `${result.file}/`}~/${result.name}.html" class="flex rounded-lg gap-4 items-center justify-between py-2 px-3 hover:bg-stone-100 dark:hover:bg-stone-800">
129124
<div class="flex items-center gap-2.5">
130125
<div class="docNodeKindIcon">
131126
${kind}

0 commit comments

Comments
 (0)