Pinned 2026 toolchains (Go 1.26, Rust 1.98/edition 2024, Python 3.14 + uv, Node 24, Zig 0.16, NixOS 26.05), postgres 18 / mongo 8, lockfiles built from, non-root runtimes, .dockerignore, per-project LICENSE, READMEs with the git.devai.io clone line, checkout@v7 CI. Security fixes in the legacy Rust APIs (any-password login, self-assigned admin, hard-coded JWT secret), JWT alg/exp/sub enforcement across the blog series, safe markdown links in the frontends, and many smaller bugs — every project was built, run and exercised end to end. Adds scripts/publish.sh + a CI publish job that splits every folder into its own repo at git.devai.io/templates/<folder>. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01128fhuZbgivaSJvtMf4s1G
50 lines
1.7 KiB
JavaScript
50 lines
1.7 KiB
JavaScript
const quoteEl = document.getElementById("quote");
|
|
const authorEl = document.getElementById("author");
|
|
const button = document.getElementById("new");
|
|
const statusEl = document.getElementById("status");
|
|
|
|
let quotes = [];
|
|
let lastIndex = -1;
|
|
|
|
// fetch() a LOCAL data file — the exact pattern you'd use for a live API. Swap
|
|
// "quotes.json" for a real URL and the rest of this function stays the same.
|
|
async function loadQuotes() {
|
|
statusEl.textContent = "Loading…";
|
|
|
|
try {
|
|
const res = await fetch("quotes.json");
|
|
if (!res.ok) throw new Error(`Could not load quotes (${res.status})`);
|
|
|
|
quotes = await res.json(); // an array of { text, author }
|
|
if (!Array.isArray(quotes) || quotes.length === 0) {
|
|
statusEl.textContent = "No quotes found.";
|
|
return;
|
|
}
|
|
|
|
statusEl.textContent = "";
|
|
showRandom();
|
|
} catch (err) {
|
|
// Usually this means the page was opened straight from disk (file://),
|
|
// where browsers refuse to fetch() other files. Serve the folder instead.
|
|
statusEl.textContent = "Couldn't load the quotes. Serve this folder with a local server (see the README).";
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
function showRandom() {
|
|
if (quotes.length === 0) return;
|
|
|
|
// Math.random() is 0 to 0.999…; times the length, rounded down, is a valid index.
|
|
let index = Math.floor(Math.random() * quotes.length);
|
|
while (quotes.length > 1 && index === lastIndex) {
|
|
index = Math.floor(Math.random() * quotes.length); // never the same one twice in a row
|
|
}
|
|
lastIndex = index;
|
|
|
|
quoteEl.textContent = quotes[index].text;
|
|
authorEl.textContent = "— " + quotes[index].author;
|
|
}
|
|
|
|
button.addEventListener("click", showRandom);
|
|
|
|
loadQuotes();
|