feat: hobby project landing page (PWA + SPA) with admin backoffice
- landing page: welcome hero, live search, project card grid (10 projects from owner list) - warm brown/white theme (fastwork-inspired layout), embedded K2D Thai font - PWA: manifest, PIL-generated icons, versioned service worker with auto-update - backoffice at #/admin: edit name/description/url, reorder, delete, publish - server/publish.mjs: zero-dependency static server + PUT api/projects with validation, JSON write, git commit and push; loopback-only unless ADMIN_TOKEN - docs: README, DESIGN.md (color/type contract), AGENTS.md
This commit is contained in:
1 parent
e55b193644
commit
c00bc62272
35 files changed
+3432
-2
No files matched your search
@@ -0,0 +1,103 @@
|
||||
/* app.js — จุดเริ่มของแอป: โหลดข้อมูล → ผูก router → เรนเดอร์หน้า */
|
||||
|
||||
import { hydrateIcons, toast } from "./ui.js";
|
||||
import { loadProjects, normalizeData } from "./data.js";
|
||||
import { defineRoutes, markActiveNav, onRouteChange, startRouter } from "./router.js";
|
||||
import { homeView } from "./views/home.js";
|
||||
import { adminView } from "./views/admin.js";
|
||||
import "./pwa.js";
|
||||
|
||||
const main = document.getElementById("main");
|
||||
|
||||
const state = {
|
||||
data: normalizeData({}),
|
||||
source: "empty",
|
||||
};
|
||||
|
||||
const ctx = {
|
||||
get data() {
|
||||
return state.data;
|
||||
},
|
||||
get source() {
|
||||
return state.source;
|
||||
},
|
||||
setData(data) {
|
||||
state.data = normalizeData(data);
|
||||
state.source = "server";
|
||||
updateChrome();
|
||||
},
|
||||
async reload() {
|
||||
const result = await loadProjects();
|
||||
state.data = result.data;
|
||||
state.source = result.source;
|
||||
updateChrome();
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
||||
let activeView = null;
|
||||
|
||||
const TITLES = {
|
||||
"/": "โปรเจคอดิเรกของเรา",
|
||||
"/admin": "จัดการข้อมูล · โปรเจคอดิเรก",
|
||||
};
|
||||
|
||||
function renderRoute({ path, view }) {
|
||||
if (activeView && typeof activeView.destroy === "function") activeView.destroy();
|
||||
main.replaceChildren();
|
||||
activeView = view(ctx);
|
||||
activeView.mount(main);
|
||||
markActiveNav(path);
|
||||
document.title = TITLES[path] || TITLES["/"];
|
||||
window.scrollTo({ top: 0, behavior: "auto" });
|
||||
main.focus({ preventScroll: true });
|
||||
}
|
||||
|
||||
function updateChrome() {
|
||||
const site = state.data.site || {};
|
||||
const contact = main?.closest("body")?.querySelector("[data-contact-link]");
|
||||
if (contact) {
|
||||
if (site.contact_email) {
|
||||
contact.href = `mailto:${site.contact_email}`;
|
||||
contact.textContent = site.contact_email;
|
||||
} else {
|
||||
contact.href = "#/admin";
|
||||
contact.textContent = "เพิ่มอีเมลติดต่อได้ในหน้าจัดการ";
|
||||
}
|
||||
}
|
||||
document.querySelectorAll("[data-ssl-note]").forEach((node) => {
|
||||
if (site.ssl_note) node.textContent = site.ssl_note;
|
||||
});
|
||||
}
|
||||
|
||||
function skeleton() {
|
||||
main.innerHTML = `
|
||||
<div class="wrap">
|
||||
<div class="hero" style="min-height:280px"></div>
|
||||
<div class="loading" aria-hidden="true">
|
||||
<div class="skeleton"></div><div class="skeleton"></div><div class="skeleton"></div>
|
||||
</div>
|
||||
<p class="visually-hidden" role="status">กำลังโหลดรายชื่อโปรเจค</p>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
async function boot() {
|
||||
hydrateIcons();
|
||||
skeleton();
|
||||
const result = await loadProjects();
|
||||
state.data = result.data;
|
||||
state.source = result.source;
|
||||
updateChrome();
|
||||
|
||||
defineRoutes({ "/": homeView, "/admin": adminView }, "/");
|
||||
onRouteChange(renderRoute);
|
||||
startRouter();
|
||||
|
||||
if (result.source === "cache") {
|
||||
toast("เปิดแบบออฟไลน์ — แสดงข้อมูลที่บันทึกไว้ในเครื่อง");
|
||||
} else if (result.source === "empty") {
|
||||
toast("อ่านข้อมูลโปรเจคไม่ได้ — เข้าไปเพิ่มรายการได้ที่หน้า “จัดการข้อมูล”", "error");
|
||||
}
|
||||
}
|
||||
|
||||
boot();
|
||||
Reference in new issue
Block a user