fix(wiki): harden alpha-library CSP by externalizing inline scripts
This commit is contained in:
1 parent
e22e06ac89
commit
d8f88d45da
2 files changed
+54
-47
No files matched your search
@@ -2,20 +2,8 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; script-src 'self' 'unsafe-inline'; img-src 'self' data: https://vibetrading.wiki; font-src 'self' https://fonts.gstatic.com; connect-src 'self' https://api.github.com;">
|
||||
<script>
|
||||
(function () {
|
||||
try {
|
||||
var stored = localStorage.getItem("vibetrading-theme");
|
||||
var resolved = stored === "dark" || stored === "light"
|
||||
? stored
|
||||
: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||
document.documentElement.setAttribute("data-theme", resolved);
|
||||
} catch (e) {
|
||||
document.documentElement.setAttribute("data-theme", "light");
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; script-src 'self'; img-src 'self' data: https://vibetrading.wiki; font-src 'self' https://fonts.gstatic.com; connect-src 'self' https://api.github.com;">
|
||||
<script src="/theme-init.js"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Alpha Library | Vibe-Trading Wiki</title>
|
||||
<meta name="description" content="450+ pre-built quant alphas across four zoos: Qlib158, Kakushadze 101, GTJA191, Academic. One-line CLI to benchmark any zoo on your universe.">
|
||||
@@ -164,38 +152,5 @@ vibe-trading alpha bench --zoo gtja191 --universe csi300 --period 2020-2025</cod
|
||||
<a href="/research-lab/">Research Lab</a>
|
||||
<a href="https://github.com/HKUDS/Vibe-Trading">GitHub</a>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
// Runtime hydration of stats + per-zoo counts from the generated index.json.
|
||||
(function () {
|
||||
fetch("content/index.json", { cache: "default" })
|
||||
.then(function (r) { if (!r.ok) throw new Error("index.json " + r.status); return r.json(); })
|
||||
.then(function (data) {
|
||||
var total = document.getElementById("stat-total");
|
||||
var totalSub = document.getElementById("stat-total-sub");
|
||||
var zoos = document.getElementById("stat-zoos");
|
||||
var gen = document.getElementById("stat-generated");
|
||||
if (total) total.textContent = String(data.total_alphas || 0);
|
||||
if (totalSub) totalSub.textContent = "across " + (data.zoo_count || 0) + " zoos";
|
||||
if (zoos) zoos.textContent = String(data.zoo_count || 0);
|
||||
if (gen && data.generated_at) {
|
||||
try { gen.textContent = new Date(data.generated_at).toISOString().slice(0, 10); }
|
||||
catch (e) { gen.textContent = "unknown"; }
|
||||
}
|
||||
var countEls = Array.prototype.slice.call(document.querySelectorAll(".count[data-zoo]"));
|
||||
(data.zoos || []).forEach(function (z) {
|
||||
var zooId = String(z.zoo_id || "");
|
||||
var el = countEls.find(function (candidate) {
|
||||
return candidate.dataset.zoo === zooId;
|
||||
});
|
||||
if (el) el.textContent = z.count + " alphas";
|
||||
});
|
||||
})
|
||||
.catch(function () {
|
||||
var totalSub = document.getElementById("stat-total-sub");
|
||||
if (totalSub) totalSub.textContent = "manifest not generated yet";
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,52 @@
|
||||
(function () {
|
||||
try {
|
||||
var stored = localStorage.getItem("vibetrading-theme");
|
||||
var resolved = stored === "dark" || stored === "light"
|
||||
? stored
|
||||
: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||
document.documentElement.setAttribute("data-theme", resolved);
|
||||
} catch (e) {
|
||||
document.documentElement.setAttribute("data-theme", "light");
|
||||
}
|
||||
})();
|
||||
|
||||
(function () {
|
||||
function hydrateAlphaStats() {
|
||||
fetch("content/index.json", { cache: "default" })
|
||||
.then(function (r) {
|
||||
if (!r.ok) throw new Error("index.json " + r.status);
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
var total = document.getElementById("stat-total");
|
||||
var totalSub = document.getElementById("stat-total-sub");
|
||||
var zoos = document.getElementById("stat-zoos");
|
||||
var gen = document.getElementById("stat-generated");
|
||||
if (total) total.textContent = String(data.total_alphas || 0);
|
||||
if (totalSub) totalSub.textContent = "across " + (data.zoo_count || 0) + " zoos";
|
||||
if (zoos) zoos.textContent = String(data.zoo_count || 0);
|
||||
if (gen && data.generated_at) {
|
||||
try { gen.textContent = new Date(data.generated_at).toISOString().slice(0, 10); }
|
||||
catch (e) { gen.textContent = "unknown"; }
|
||||
}
|
||||
var countEls = Array.prototype.slice.call(document.querySelectorAll(".count[data-zoo]"));
|
||||
(data.zoos || []).forEach(function (z) {
|
||||
var zooId = String(z.zoo_id || "");
|
||||
var el = countEls.find(function (candidate) {
|
||||
return candidate.dataset.zoo === zooId;
|
||||
});
|
||||
if (el) el.textContent = z.count + " alphas";
|
||||
});
|
||||
})
|
||||
.catch(function () {
|
||||
var totalSub = document.getElementById("stat-total-sub");
|
||||
if (totalSub) totalSub.textContent = "manifest not generated yet";
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", hydrateAlphaStats);
|
||||
} else {
|
||||
hydrateAlphaStats();
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user