diff --git a/astro.config.mjs b/astro.config.mjs index a0fc5a3..0956632 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -5,6 +5,7 @@ import svelte from "@astrojs/svelte"; import mdx from "@astrojs/mdx"; import sitemap from "@astrojs/sitemap"; import tailwindcss from "@tailwindcss/vite"; +import { execFileSync } from "node:child_process"; import { existsSync } from "node:fs"; import { rename, rmdir } from "node:fs/promises"; import { DEFAULT_LOCALE, LOCALES } from "./src/i18n/routing.ts"; @@ -71,6 +72,23 @@ const CF_BEACON_DEFAULT = // "what is live?" maps straight to a commit. const BUILD_COMMIT = process.env.WORKERS_CI_COMMIT_SHA ?? process.env.GITHUB_SHA ?? null; +// The poli0981/content commit this build's src/content points at: the gitlink recorded in +// HEAD, so it is right even when the submodule checkout itself is missing or dirty. The admin +// compares it with the content repo's head to tell "merged" from "live"; /api/health reports +// it next to the site commit. null when git or the gitlink isn't there. +function contentCommit() { + try { + const sha = execFileSync("git", ["rev-parse", "HEAD:src/content"], { + encoding: "utf8", + stdio: ["ignore", "pipe", "ignore"], + }).trim(); + return /^[0-9a-f]{40}$/.test(sha) ? sha : null; + } catch { + return null; + } +} +const CONTENT_COMMIT = contentCommit(); + // https://astro.build/config export default defineConfig({ site: "https://poli0981.dev", @@ -166,7 +184,10 @@ export default defineConfig({ // Tailwind v4 is wired through the Vite plugin (NOT the legacy @astrojs/tailwind). vite: { plugins: [tailwindcss()], - define: { __BUILD_COMMIT__: JSON.stringify(BUILD_COMMIT) }, + define: { + __BUILD_COMMIT__: JSON.stringify(BUILD_COMMIT), + __CONTENT_COMMIT__: JSON.stringify(CONTENT_COMMIT), + }, }, // Self-hosted fonts via the built-in Fonts API. Subsets include `vietnamese`. diff --git a/src/components/admin/ActivityLog.svelte b/src/components/admin/ActivityLog.svelte index 11fd791..9ad41c1 100644 --- a/src/components/admin/ActivityLog.svelte +++ b/src/components/admin/ActivityLog.svelte @@ -21,6 +21,7 @@ "gallery.save": "Lưu album", "gallery.delete": "Xoá album", publish: "Xuất bản", + "publish.auto": "Tự xuất bản", "denylist.add": "Chặn IP", "denylist.remove": "Bỏ chặn IP", }; diff --git a/src/components/admin/ContentList.svelte b/src/components/admin/ContentList.svelte index 4a82e42..239db4e 100644 --- a/src/components/admin/ContentList.svelte +++ b/src/components/admin/ContentList.svelte @@ -71,7 +71,8 @@ function create() { if (!newPath || taken) return; const params = new URLSearchParams({ new: collection, slug: slug.trim(), lang: newLang }); - if (collection === "stories") params.set("series", series.trim()); + // No series = a one-shot story (stories/.md). + if (collection === "stories" && series.trim()) params.set("series", series.trim()); location.href = `/admin/edit/?${params}`; } @@ -86,7 +87,7 @@

Nội dung

-

Lưu là commit vào repo nội dung; bấm “Xuất bản” để đưa lên site.

+

Lưu hoặc xoá là commit vào repo nội dung rồi tự xuất bản lên site (thường 10–15 phút).

@@ -108,7 +109,10 @@ {#if collection === "stories"} - + {/if}