feat(hero): randomise the three floating cards on every page load
- sample 3 non-repeating projects from the full list with Fisher-Yates shuffle - order inside the stack is randomised too; stays decorative (aria-hidden) - docs: DESIGN.md notes the random sample
This commit is contained in:
1 parent
f9dffbd132
commit
79b147d38f
2 files changed
+13
-4
No files matched your search
+11
-2
@@ -3,6 +3,16 @@
|
||||
import { escapeHtml, hostOf, icon, normalizeUrl } from "../ui.js";
|
||||
import { initReveal, splitWordsHtml } from "../motion.js";
|
||||
|
||||
/** สุ่มลำดับด้วย Fisher–Yates แล้วหยิบมา count ใบ (ไม่ซ้ำ) */
|
||||
function sampleRandom(list, count) {
|
||||
const pool = [...list];
|
||||
for (let i = pool.length - 1; i > 0; i -= 1) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[pool[i], pool[j]] = [pool[j], pool[i]];
|
||||
}
|
||||
return pool.slice(0, Math.max(0, count));
|
||||
}
|
||||
|
||||
export function homeView(ctx) {
|
||||
let root = null;
|
||||
let query = "";
|
||||
@@ -118,8 +128,7 @@ export function homeView(ctx) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="hero__deco" aria-hidden="true">
|
||||
${ctx.data.projects
|
||||
.slice(0, 3)
|
||||
${sampleRandom(ctx.data.projects, 3)
|
||||
.map(
|
||||
(project, index) => `
|
||||
<div class="hero__deco-card" style="--i:${index}">
|
||||
|
||||
Reference in new issue
Block a user