Skip to content

Commit 65eb245

Browse files
authored
Merge pull request #2447 from strictdoc-project/stanislaw/search
Code climate: Set up a JS linter and reformat some files
2 parents 7573434 + 1c1d9c0 commit 65eb245

File tree

4 files changed

+481
-416
lines changed

4 files changed

+481
-416
lines changed

requirements.check.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ mypy>=0.910,<1.17
55
ruff>=0.9
66
fixit
77

8+
# Lint - JS
9+
jsbeautifier
10+
811
# Unit tests
912
pytest>=6.2.2
1013
# Pytest fixture that provides fake file system for testing code that accesses

strictdoc/export/html/_static/stable_uri_forwarder.js

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,84 +16,84 @@
1616

1717
// Resolve the MID / UID to the correct page / anchor using the projectMap.
1818
function resolveStableUriRedirectUsingProjectMap(anchor) {
19-
for (const [page, nodes] of Object.entries(projectMap)) {
20-
for (const node of nodes) {
21-
if (node['_LINK'].toLowerCase() === anchor.toLowerCase()) {
22-
window.location.replace(page + "#" + node['_LINK']);
23-
return;
24-
}
19+
for (const [page, nodes] of Object.entries(projectMap)) {
20+
for (const node of nodes) {
21+
if (node['_LINK'].toLowerCase() === anchor.toLowerCase()) {
22+
window.location.replace(page + "#" + node['_LINK']);
23+
return;
24+
}
2525

26-
const nodeHasUID = 'UID' in node && typeof node['UID'] === 'string';
27-
if (nodeHasUID && node['UID'].toLowerCase() === anchor.toLowerCase()) {
28-
window.location.replace(page + "#" + node['_LINK']);
29-
return;
30-
}
26+
const nodeHasUID = 'UID' in node && typeof node['UID'] === 'string';
27+
if (nodeHasUID && node['UID'].toLowerCase() === anchor.toLowerCase()) {
28+
window.location.replace(page + "#" + node['_LINK']);
29+
return;
30+
}
3131

32-
const nodeHasMID = 'MID' in node && typeof node['MID'] === 'string';
33-
if (nodeHasMID && node['MID'].toLowerCase() === anchor.toLowerCase()) {
34-
window.location.replace(page + "#" + node['_LINK']);
35-
return;
36-
}
37-
}
32+
const nodeHasMID = 'MID' in node && typeof node['MID'] === 'string';
33+
if (nodeHasMID && node['MID'].toLowerCase() === anchor.toLowerCase()) {
34+
window.location.replace(page + "#" + node['_LINK']);
35+
return;
36+
}
3837
}
38+
}
3939
}
4040

4141
// Dynamically load the projectMap an resolve MID / UID.
4242
function loadProjectMapAndResolveStableUriRedirect(anchor) {
43-
44-
// ProjectMap is loaded, no need to load it again.
45-
if (typeof projectMap !== 'undefined') {
46-
resolveStableUriRedirectUsingProjectMap(anchor);
47-
return;
48-
}
4943

50-
// Get script URL and derive from it the url of project_map.js
51-
const scriptUrl = new URL(document.getElementById("stable_uri_forwarder").src, window.location.href)
52-
const projectMapUrl = new URL('project_map.js', scriptUrl).href;
44+
// ProjectMap is loaded, no need to load it again.
45+
if (typeof projectMap !== 'undefined') {
46+
resolveStableUriRedirectUsingProjectMap(anchor);
47+
return;
48+
}
5349

54-
// Dynamically load project map and resolve
55-
const script = document.createElement("script");
56-
script.src = projectMapUrl;
57-
script.onload = () => resolveStableUriRedirectUsingProjectMap(anchor);
58-
script.onerror = () => {
59-
console.error(`Failed to load project map from ${projectMapUrl}`);
60-
};
61-
document.head.appendChild(script);
50+
// Get script URL and derive from it the url of project_map.js
51+
const scriptUrl = new URL(document.getElementById("stable_uri_forwarder").src, window.location
52+
.href)
53+
const projectMapUrl = new URL('project_map.js', scriptUrl).href;
54+
55+
// Dynamically load project map and resolve
56+
const script = document.createElement("script");
57+
script.src = projectMapUrl;
58+
script.onload = () => resolveStableUriRedirectUsingProjectMap(anchor);
59+
script.onerror = () => {
60+
console.error(`Failed to load project map from ${projectMapUrl}`);
61+
};
62+
document.head.appendChild(script);
6263
}
6364

64-
function processStableUriRedirect(anchor)
65-
{
66-
const exportType = document.querySelector('meta[name="strictdoc-export-type"]')?.content;
65+
function processStableUriRedirect(anchor) {
66+
const exportType = document.querySelector('meta[name="strictdoc-export-type"]')?.content;
6767

68-
if (exportType === 'webserver') {
69-
// For the web server, we let the main_router.py dynamically forward UID to node.
70-
window.location.replace("/UID/" + anchor);
71-
} else if (exportType === 'static') {
72-
// For static exports, we use the project_map.js.
73-
loadProjectMapAndResolveStableUriRedirect(anchor)
74-
}
68+
if (exportType === 'webserver') {
69+
// For the web server, we let the main_router.py dynamically forward UID to node.
70+
window.location.replace("/UID/" + anchor);
71+
} else if (exportType === 'static') {
72+
// For static exports, we use the project_map.js.
73+
loadProjectMapAndResolveStableUriRedirect(anchor)
74+
}
7575
}
7676

7777

7878
// In case an anchor is present at content load time.
7979
document.addEventListener("DOMContentLoaded", () => {
80-
const anchorParam = new URLSearchParams(window.location.search).get("a");
81-
if (anchorParam) {
82-
processStableUriRedirect(anchorParam)
83-
return
84-
}
80+
const anchorParam = new URLSearchParams(window.location.search).get("a");
81+
if (anchorParam) {
82+
processStableUriRedirect(anchorParam)
83+
return
84+
}
8585

86-
// for legacy link support
87-
const anchorHash = window.location.hash.substring(1);
88-
if (anchorHash) {
89-
processStableUriRedirect(anchorHash)
90-
}
86+
// for legacy link support
87+
const anchorHash = window.location.hash.substring(1);
88+
if (anchorHash) {
89+
processStableUriRedirect(anchorHash)
90+
}
9191
});
9292

9393
// In case an anchor is added manually afterwards (eases testing).
9494
window.addEventListener("hashchange", () => {
95-
const anchor = window.location.hash.substring(1);
96-
if (anchor) {
97-
processStableUriRedirect(anchor)
98-
}
95+
const anchor = window.location.hash.substring(1);
96+
if (anchor) {
97+
processStableUriRedirect(anchor)
98+
}
9999
});

0 commit comments

Comments
 (0)