feat(cards): คลิกการ์ดโรงหนังได้ทั้งใบ (ไม่ใช่แค่ "ดูรายละเอียด")
- assets/card-click.v1.js: event delegation บน <article> → location.assign(a[href^="/cinema/"]) · ยกเว้นปุ่ม/ลิงก์ภายในใบ (ปุ่มแชร์ยังทำงานเอง) และตอนลากเลือกข้อความ · cursor pointer + focus ring ที่ลิงก์ "ดูรายละเอียด" - scripts/apply-card-click.mjs: เติม <script defer> ให้ทุก .html (64 ไฟล์) + โหมด --check - sw.js: precache card-click + VERSION v2.1.3 - docs/card-clickable.md: กติกา ผลทดสอบ และขั้นตอนหลัง re-export
This commit is contained in:
1 parent
3ebfcfea75
commit
c2506b8ed4
68 files changed
+212
-65
No files matched your search
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* ใส่ <script src="/assets/card-click.v1.js" defer> ให้ทุกไฟล์ .html
|
||||
*
|
||||
* ใช้: node scripts/apply-card-click.mjs [--check]
|
||||
* --check = ดูว่ามีไฟล์ไหนยังไม่ถูกใส่ (ไม่เขียนไฟล์)
|
||||
*
|
||||
* ไฟล์นี้มีไว้เพราะรีโปนี้เก็บ "static export" ไม่มี source ให้แก้ component
|
||||
* ถ้า re-export ใหม่ทั้งชุด ให้รันสคริปต์นี้ซ้ำเพื่อเติมสคริปต์กลับเข้าไป
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const TAG = '<script src="/assets/card-click.v1.js" defer></script>';
|
||||
const CHECK = process.argv.includes("--check");
|
||||
const SKIP = new Set(["node_modules", ".git"]);
|
||||
|
||||
function walk(dir, out = []) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
if (SKIP.has(entry.name)) continue;
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) walk(full, out);
|
||||
else if (entry.name.endsWith(".html")) out.push(full);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const files = walk(".");
|
||||
let patched = 0;
|
||||
const missing = [];
|
||||
|
||||
for (const file of files) {
|
||||
const html = fs.readFileSync(file, "utf8");
|
||||
if (html.includes("card-click.v1.js")) continue;
|
||||
missing.push(file);
|
||||
if (CHECK) continue;
|
||||
|
||||
const next = html.includes("</body>")
|
||||
? html.replace("</body>", `${TAG}</body>`)
|
||||
: html + TAG;
|
||||
fs.writeFileSync(file, next);
|
||||
patched++;
|
||||
}
|
||||
|
||||
if (CHECK) {
|
||||
console.log(
|
||||
missing.length === 0
|
||||
? `ครบแล้ว: ${files.length} ไฟล์`
|
||||
: `ยังขาด ${missing.length}/${files.length} ไฟล์:\n${missing.join("\n")}`,
|
||||
);
|
||||
} else {
|
||||
console.log(`เติมสคริปต์แล้ว ${patched} ไฟล์ (จากทั้งหมด ${files.length})`);
|
||||
}
|
||||
Reference in new issue
Block a user