2022-02-22 04:40:14 +00:00
|
|
|
/**
|
|
|
|
* This module is used for the `/find` endpoint.
|
|
|
|
*/
|
|
|
|
|
2022-02-20 17:12:49 +00:00
|
|
|
import { SITE_ROOT } from "../site-root.js";
|
2022-02-22 04:40:14 +00:00
|
|
|
import { DeclarationDataCenter } from "../declaration-data.js";
|
2022-02-20 17:12:49 +00:00
|
|
|
|
2022-02-22 04:40:14 +00:00
|
|
|
async function findRedirect(pattern, isSource) {
|
|
|
|
const dataCenter = await DeclarationDataCenter.init();
|
|
|
|
try {
|
|
|
|
let results = dataCenter.search(pattern);
|
|
|
|
window.location.replace(isSource ? results[0].source : results[0].link);
|
|
|
|
} catch {
|
2022-02-20 17:38:12 +00:00
|
|
|
window.location.replace(`${SITE_ROOT}404.html`);
|
2022-02-22 04:40:14 +00:00
|
|
|
}
|
2022-02-20 17:38:12 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 04:40:14 +00:00
|
|
|
let hash = window.location.hash.split("#");
|
2022-02-20 17:12:49 +00:00
|
|
|
|
2022-02-22 04:40:14 +00:00
|
|
|
if (hash.length == 0) {
|
2022-02-20 17:12:49 +00:00
|
|
|
window.location.replace(`${SITE_ROOT}/404.html`);
|
|
|
|
}
|
|
|
|
|
2022-02-22 04:40:14 +00:00
|
|
|
if (hash[1].endsWith("/src")) {
|
|
|
|
findRedirect(hash.replace("/src", ""), true);
|
2022-02-20 17:38:12 +00:00
|
|
|
} else {
|
2022-02-22 04:40:14 +00:00
|
|
|
findRedirect(hash, false);
|
2022-02-20 17:38:12 +00:00
|
|
|
}
|