chore(publish): replace source tree with static export at repo root
Publish the prerendered static export (index.html, 404.html, cinema/,
c/, about/, for-cinemas/, for-film-lovers/, assets/, images/, og/,
sitemap.xml, robots.txt) as the site root and remove the React Router
+ Nitro source tree from this branch. Source remains available in
history at 0548772.
Note: public/sw.js here reports VERSION v2.0.5 while the removed source
tree (v2.1.0) was newer, and .gitignore was not carried over.
This commit is contained in:
1 parent
05487728a7
commit
e6c4ebff48
394 files changed
+3977
-37891
No files matched your search
@@ -1,99 +0,0 @@
|
||||
/**
|
||||
* ลำดับการ์ดโรงหนังหน้าแรกแบบ "สลับทุกวัน"
|
||||
*
|
||||
* เงื่อนไขที่ต้องรับประกัน: โรงหนึ่งจะไม่ได้อยู่ตำแหน่งการ์ดเดิมสองวันติดกัน
|
||||
* วิธี: สร้าง permutation ฐานจากรายการ (คงที่ทุกวัน — เปลี่ยนเมื่อแอดมินสลับลำดับ)
|
||||
* แล้ว "หมุน" (rotate) ด้วย offset รายวันที่ไม่เป็น 0 และไม่ซ้ำกับเมื่อวาน
|
||||
* - หมุนด้วย k ใด ๆ ที่ 1 ≤ k ≤ n-1 → ทุกโรงเลื่อนตำแหน่ง เป็นไปไม่ได้ที่จะอยู่ที่เดิม
|
||||
* - offset = 1 + (จำนวนวัน % (n-1)) → ค่าอยู่ใน 1..n-1 และวันติดกันไม่มีทางเท่ากัน
|
||||
* ผลพลอยได้: ทุกคนเห็นลำดับเดียวกันในวันเดียวกัน (ไม่เกิด hydration mismatch)
|
||||
* และไม่ต้องเก็บ state เพิ่ม — คำนวณจากวันที่ล้วน ๆ
|
||||
*/
|
||||
|
||||
const DAY_MS = 86_400_000;
|
||||
|
||||
/** คีย์วันที่แบบ UTC (YYYY-MM-DD) — ใช้ร่วมกันทั้ง SSR และ client */
|
||||
export function dayKey(date: Date = new Date()): string {
|
||||
return date.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
function daysSinceEpoch(key: string): number {
|
||||
const parsed = Date.parse(`${key}T00:00:00Z`);
|
||||
return Number.isFinite(parsed) ? Math.floor(parsed / DAY_MS) : 0;
|
||||
}
|
||||
|
||||
/** hash 32-bit แบบ deterministic (ใช้ seed ของ permutation ฐาน) */
|
||||
function hashText(text: string): number {
|
||||
let hash = 2166136261;
|
||||
for (let index = 0; index < text.length; index += 1) {
|
||||
hash ^= text.charCodeAt(index);
|
||||
hash = Math.imul(hash, 16777619);
|
||||
}
|
||||
return hash >>> 0;
|
||||
}
|
||||
|
||||
/** PRNG แบบ mulberry32 — ผลซ้ำได้ทุกเครื่องด้วย seed เดียวกัน */
|
||||
function createRandom(seed: number): () => number {
|
||||
let state = seed >>> 0;
|
||||
return () => {
|
||||
state = (state + 0x6d2b79f5) >>> 0;
|
||||
let t = state;
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
/** Fisher–Yates ด้วย seeded random */
|
||||
function seededShuffle<T>(items: T[], seed: number): T[] {
|
||||
const random = createRandom(seed);
|
||||
const result = [...items];
|
||||
for (let i = result.length - 1; i > 0; i -= 1) {
|
||||
const j = Math.floor(random() * (i + 1));
|
||||
[result[i], result[j]] = [result[j], result[i]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** หมุนอาร์เรย์ไปทางซ้าย k ตำแหน่ง */
|
||||
function rotate<T>(items: T[], by: number): T[] {
|
||||
if (items.length === 0) return [];
|
||||
const offset = ((by % items.length) + items.length) % items.length;
|
||||
return [...items.slice(offset), ...items.slice(0, offset)];
|
||||
}
|
||||
|
||||
/**
|
||||
* ลำดับของวันนั้น ๆ
|
||||
* @param items รายการ (เรียงตามลำดับที่แอดมินจัดไว้)
|
||||
* @param idOf ตัวระบุของแต่ละรายการ (ใช้ทำ seed ให้ permutation ฐานนิ่ง)
|
||||
* @param key วันที่ (YYYY-MM-DD) — ค่าเริ่มต้นคือวันนี้ (UTC)
|
||||
*/
|
||||
export function dailyOrder<T>(
|
||||
items: T[],
|
||||
idOf: (item: T) => string,
|
||||
key: string = dayKey(),
|
||||
): T[] {
|
||||
const count = items.length;
|
||||
if (count < 2) return [...items];
|
||||
|
||||
const baseSeed = hashText(idOf(items[0]) + "|" + items.map(idOf).join("|") + "|v1");
|
||||
const base = seededShuffle(items, baseSeed);
|
||||
|
||||
const days = daysSinceEpoch(key);
|
||||
// n = 2: มี permutation ที่ต่างกันได้แค่ 2 แบบ → สลับวันละครั้ง
|
||||
const offset = count === 2 ? days % 2 : 1 + (((days % (count - 1)) + (count - 1)) % (count - 1));
|
||||
|
||||
return rotate(base, offset);
|
||||
}
|
||||
|
||||
/** ตรวจว่าไม่มีรายการใดอยู่ตำแหน่งเดิมเมื่อเทียบสองวัน (ใช้ในเทสต์) */
|
||||
export function keepsSamePositions<T>(
|
||||
first: T[],
|
||||
second: T[],
|
||||
idOf: (item: T) => string,
|
||||
): string[] {
|
||||
const index = new Map(second.map((item, position) => [idOf(item), position]));
|
||||
return first
|
||||
.filter((item, position) => index.get(idOf(item)) === position)
|
||||
.map(idOf);
|
||||
}
|
||||
Reference in new issue
Block a user