bookshelf-doc/static/find/find.js

23 lines
599 B
JavaScript
Raw Normal View History

2022-02-20 17:12:49 +00:00
import { SITE_ROOT } from "../site-root.js";
import { declSearch } from "../search.js";
2022-02-20 17:38:12 +00:00
async function findRedirect(query, isSource) {
return declSearch(query).then((results) => {
window.location.replace(isSource? results[0].source : results[0].link);
}).catch(() => {
window.location.replace(`${SITE_ROOT}404.html`);
});
}
2022-02-20 17:12:49 +00:00
let splits = window.location.href.split("#");
if (splits.length < 2) {
window.location.replace(`${SITE_ROOT}/404.html`);
}
2022-02-20 17:38:12 +00:00
if (splits[1].endsWith("/src")) {
findRedirect(splits[1].replace("/src", ""), true);
} else {
findRedirect(splits[1], false);
}