Repository navigation
Expand file tree
/
Copy pathdocs-redirect.js
More file actions
47 lines (45 loc) · 2.16 KB
/
Copy pathdocs-redirect.js
File metadata and controls
47 lines (45 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Generated by make site-docs in coddy-project/coddy-agent from docs/nav.yaml.
// GitHub Pages serves 404.html for every address that is not a file; this
// script turns /docs/<path> into the page on GitHub and /docs/<path>.md into
// its raw Markdown, keeping the fragment, and /<lang>/docs/<path> into the
// translation under docs/<lang>/ (LANGS). Root pages of the repository that
// the map includes are listed in ROOT; they are not translated.
(function () {
var BLOB = "https://github.com/coddy-project/coddy-agent/blob/main/";
var RAW = "https://raw.githubusercontent.com/coddy-project/coddy-agent/main/";
var ROOT = {"AGENTS":"AGENTS.md","CONTRIBUTING":"CONTRIBUTING.md","DESIGN":"DESIGN.md"};
var LANGS = ["ru"];
function coddyDocsTarget(pathname, hash, anchors) {
var m = /^\/(?:([a-z]{2})\/)?docs(?:\/(.*))?$/.exec(pathname || "");
if (!m) return null;
var lang = m[1] && LANGS.indexOf(m[1]) >= 0 ? m[1] : "";
if (m[1] && !lang) return null;
var p = (m[2] || "").replace(/\/+$/, "");
hash = hash || "";
var dir = "docs/" + (lang ? lang + "/" : "");
if (p === "") return BLOB + dir + "README.md" + hash;
var raw = /\.md$/.test(p);
var slug = raw ? p.slice(0, -3) : p;
if (lang && hash && anchors && anchors[slug]) {
var key = hash.slice(1);
try { key = decodeURIComponent(key); } catch (e) { /* a malformed escape stays as written */ }
var local = anchors[slug][key.toLowerCase()];
if (local) hash = "#" + local;
}
var file = ROOT[slug] || (dir + slug + ".md");
return (raw ? RAW : BLOB) + file + hash;
}
if (typeof window !== "undefined") {
window.coddyDocsTarget = coddyDocsTarget;
var go = function (anchors) {
var target = coddyDocsTarget(window.location.pathname, window.location.hash, anchors);
if (target) window.location.replace(target);
};
var t = /^\/([a-z]{2})\/docs\//.exec(window.location.pathname);
if (t && LANGS.indexOf(t[1]) >= 0 && window.location.hash && typeof fetch === "function") {
fetch("/docs-anchors-" + t[1] + ".json").then(function (r) { return r.json(); }).then(go, function () { go(null); });
} else {
go(null);
}
}
})();