Skip to content

Commit 5303062

Browse files
committed
update
1 parent 97e473f commit 5303062

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

docs/app.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ function detectRepoFromLocation() {
4343
return null;
4444
}
4545

46+
function pathFromLocation() {
47+
const params = new URLSearchParams(window.location.search);
48+
const queryPath = params.get("path");
49+
if (queryPath) {
50+
return decodeURIComponent(queryPath);
51+
}
52+
if (window.location.hash.length > 1) {
53+
return decodeURIComponent(window.location.hash.slice(1));
54+
}
55+
return null;
56+
}
57+
58+
function updateLocationWithPath(path) {
59+
const params = new URLSearchParams(window.location.search);
60+
params.set("path", encodeURIComponent(path));
61+
const newUrl = `${window.location.pathname}?${params.toString()}`;
62+
window.history.replaceState({}, "", newUrl);
63+
}
64+
4665
function encodePath(path) {
4766
return path
4867
.split("/")
@@ -156,6 +175,7 @@ async function loadFile(path, meta = {}) {
156175
state.currentPath = path;
157176
updateContentHeader(path);
158177
updateFooter(meta);
178+
updateLocationWithPath(path);
159179

160180
const languageClass = languageForPath(path);
161181
codeBlock.className = languageClass ? `language-${languageClass}` : "";
@@ -358,6 +378,7 @@ async function loadConfig() {
358378
async function init() {
359379
const config = await loadConfig();
360380
const detected = detectRepoFromLocation();
381+
const initialPath = pathFromLocation();
361382

362383
state.repoOwner = config.repoOwner || detected?.owner || "your-github-username";
363384
state.repoName = config.repoName || detected?.repo || "your-repo-name";
@@ -402,6 +423,9 @@ async function init() {
402423
}
403424
});
404425

426+
if (initialPath) {
427+
state.currentPath = initialPath;
428+
}
405429
loadFile(state.currentPath, { type: "file" });
406430
}
407431

0 commit comments

Comments
 (0)