diff --git a/AGENTS.md b/AGENTS.md index b0b12c5..7310c09 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -33,5 +33,7 @@ Examples: - Use `docs/admin-data-model.md` for backend tables, workflow states, and validation-critical constraints. - Use `docs/implementation-plan.md` for delivery phases and milestone expectations. - Use `docs/acceptance-criteria.md` and `docs/quality-assurance.md` for review and validation standards. +- Use `docs/deployment.md` for rollout steps, build settings, and remote operations. +- Use `docs/production-config.md` for the current production inventory, domains, Workers, server paths, and config ownership. - Use `docs/launch-checklist.md` for launch routes, health checks, domain preparation, and observability notes. -- Use `docs/local-development.md` for transition-era local setup notes and current prototype commands. +- Use `docs/local-development.md` for current local setup, service commands, and archive import notes. diff --git a/README.md b/README.md index e95865e..82b839b 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,9 @@ The target architecture is no longer a headless CMS workflow. - `docs/implementation-plan.md`: development phases and milestone plan - `docs/acceptance-criteria.md`: module-level acceptance criteria for product, content, and operations - `docs/quality-assurance.md`: browser checks, automated checks, sample content, and release validation flow -- `docs/local-development.md`: current local prototype notes and migration-era development guidance +- `docs/local-development.md`: current local setup, service commands, and archive import notes - `docs/deployment.md`: Worker, Docker Compose, Tunnel, and rollout commands for production +- `docs/production-config.md`: production inventory, hostnames, Workers, server paths, and config ownership - `docs/launch-checklist.md`: launch-critical routes, domain preparation, health checks, and observability baseline ## Local Development @@ -64,7 +65,6 @@ Current reality in this repository: - the public Astro site is implemented and runnable today - the custom admin workspace and Hono API are the primary local stack - PostgreSQL, Drizzle seed data, and the bootstrapped operator account are all runnable from this repo -- legacy Directus files remain only as migration-era reference material Install dependencies: @@ -110,13 +110,6 @@ Default local operator account after `pnpm local:bootstrap`: - email: `admin@rebase.local` - password: `RebaseAdmin123456!` -Legacy transition commands are still available if you need to inspect the old prototype artifacts: - -- `pnpm cms:logs`: inspect Directus prototype logs -- `pnpm cms:down`: stop the local prototype containers -- `pnpm cms:health`: verify the temporary prototype health path -- `pnpm cms:reset`: recreate the local prototype database and baseline - If you receive a refreshed `geekdaily.csv`, regenerate the committed archive SQL with: ```bash @@ -138,6 +131,8 @@ Release policy: - merge `dev` into `main` only when the release candidate is validated - production deployment should track `main`, not `dev` +Remote API and service operations can be run through `ops/manage.sh`. + ## Repository Conventions Agent workflow conventions are documented in `AGENTS.md`. diff --git a/apps/admin/src/views/GeekDailyEditorPage.vue b/apps/admin/src/views/GeekDailyEditorPage.vue index 31f012d..6c2b463 100644 --- a/apps/admin/src/views/GeekDailyEditorPage.vue +++ b/apps/admin/src/views/GeekDailyEditorPage.vue @@ -58,7 +58,7 @@ const errorMessage = ref(''); const successMessage = ref(''); const fieldIssues = ref>({}); const suggestedEpisodeNumber = ref(1); -const currentEditorName = ref(''); +const currentStaffName = ref(''); const activeWechatTab = ref<'preview' | 'source'>('preview'); const copyFeedback = ref(''); let copyFeedbackTimer: number | null = null; @@ -71,10 +71,16 @@ const episodeSuggestionHint = computed(() => ); const derivedTitle = computed(() => (form.episodeNumber > 0 ? `极客日报#${form.episodeNumber}` : '极客日报#')); const statusLabel = computed(() => formatContentStatus(form.status)); -const currentEditorLabel = computed(() => currentEditorName.value || '当前编辑'); +const episodeEditorLabel = computed(() => { + if (record.value) { + return record.value.editors.length > 0 ? record.value.editors.join('、') : '待补充'; + } + + return currentStaffName.value || '待补充'; +}); const wechatInput = computed(() => ({ episodeNumber: form.episodeNumber, - editorName: currentEditorLabel.value, + editorName: episodeEditorLabel.value, bodyMarkdown: form.bodyMarkdown, items: form.items, })); @@ -168,9 +174,9 @@ const applyRecord = (payload: AdminGeekDailyRecord) => { const loadCurrentEditor = async () => { try { const me = await adminFetch('/api/admin/v1/me'); - currentEditorName.value = me.staffAccount?.displayName ?? me.user?.name ?? ''; + currentStaffName.value = me.staffAccount?.displayName ?? me.user?.name ?? ''; } catch { - currentEditorName.value = ''; + currentStaffName.value = ''; } }; @@ -345,7 +351,7 @@ onBeforeUnmount(() => {
本期编辑 - {{ currentEditorLabel }} + {{ episodeEditorLabel }}
diff --git a/apps/admin/src/views/GeekDailyPage.vue b/apps/admin/src/views/GeekDailyPage.vue index b36516c..4ec082e 100644 --- a/apps/admin/src/views/GeekDailyPage.vue +++ b/apps/admin/src/views/GeekDailyPage.vue @@ -175,6 +175,7 @@ onMounted(() => {
{{ row.title }}
第 {{ row.episodeNumber }} 期
+
编辑:{{ row.editors.join('、') }}
{{ formatContentStatus(row.status) }} diff --git a/apps/api/src/lib/geekdaily.ts b/apps/api/src/lib/geekdaily.ts index d5681f8..278c833 100644 --- a/apps/api/src/lib/geekdaily.ts +++ b/apps/api/src/lib/geekdaily.ts @@ -152,6 +152,15 @@ const resolveEpisodeEditors = (actor: AuditActor, fallback: unknown = []) => { return getEditors(fallback); }; +const resolveStoredEpisodeEditors = (currentEditors: unknown, actor: AuditActor, fallback: unknown = []) => { + const persistedEditors = getEditors(currentEditors); + if (persistedEditors.length > 0) { + return persistedEditors; + } + + return resolveEpisodeEditors(actor, fallback); +}; + const coerceDate = (value: Date | string | null | undefined) => { const date = value instanceof Date ? value : value ? new Date(value) : new Date(); return Number.isNaN(date.getTime()) ? new Date() : date; @@ -222,6 +231,11 @@ interface ListAdminGeekDailyEpisodesInput extends PaginationInput { status?: ContentStatus; } +interface ListPublicGeekDailyArchiveInput extends PaginationInput { + year?: number; + tag?: string; +} + const countItemsByEpisodeIds = async (episodeIds: string[]) => { const db = getDb(); if (episodeIds.length === 0) { @@ -282,6 +296,7 @@ export const listAdminGeekDailyEpisodes = async ( slug: getGeekDailyEpisodeSlug(row.episodeNumber), episodeNumber: row.episodeNumber, title: row.title, + editors: getEditors(row.editorsJson), status: row.status, publishedAt: toIsoString(row.publishedAt) ?? new Date().toISOString(), itemCount: itemCounts.get(row.id) ?? 0, @@ -344,7 +359,7 @@ export const updateAdminGeekDailyEpisode = async (id: string, input: GeekDailyEp } await ensureEpisodeNumberAvailable(input.episodeNumber, id); - const editors = resolveEpisodeEditors(actor, current.editors); + const editors = resolveStoredEpisodeEditors(current.editors, actor, input.editors); await db .update(geekdailyEpisodes) @@ -383,7 +398,7 @@ export const publishAdminGeekDailyEpisode = async (id: string, actor: AuditActor if (!current) { throw notFound('GeekDaily episode not found'); } - const editors = resolveEpisodeEditors(actor, current.editors); + const editors = resolveStoredEpisodeEditors(current.editors, actor); await db .update(geekdailyEpisodes) @@ -489,6 +504,58 @@ export const listPublicGeekDailyEpisodePreviews = async (limit = -1) => { }); }; +export const listPublicGeekDailyArchivePage = async (input: ListPublicGeekDailyArchiveInput = {}) => { + const normalizedYear = Number.isFinite(input.year) && (input.year ?? 0) > 0 ? Math.floor(input.year as number) : undefined; + const normalizedTag = input.tag?.trim() ?? ''; + const requestedPageSize = Number.isFinite(input.pageSize) && (input.pageSize ?? 0) > 0 ? Math.floor(input.pageSize as number) : 18; + + return withPublicGeekDailyCache( + `archive:${input.page ?? 1}:${requestedPageSize}:${normalizedYear ?? 'all'}:${normalizedTag || 'all'}`, + async () => { + const db = getDb(); + const where = combineFilters([ + eq(geekdailyEpisodes.status, 'published'), + normalizedYear ? sql`extract(year from ${geekdailyEpisodes.publishedAt})::int = ${normalizedYear}` : undefined, + normalizedTag ? sql`${geekdailyEpisodes.tagsJson} @> ${JSON.stringify([normalizedTag])}::jsonb` : undefined, + ]); + + const countRow = await db.select({ value: count() }).from(geekdailyEpisodes).where(where); + const totalItems = countRow[0]?.value ?? 0; + const pagination = resolvePagination( + { + page: input.page, + pageSize: requestedPageSize, + }, + totalItems, + ); + const rows = + totalItems === 0 + ? [] + : await db + .select({ + id: geekdailyEpisodes.id, + episodeNumber: geekdailyEpisodes.episodeNumber, + title: geekdailyEpisodes.title, + summary: geekdailyEpisodes.summary, + editorsJson: geekdailyEpisodes.editorsJson, + tagsJson: geekdailyEpisodes.tagsJson, + publishedAt: geekdailyEpisodes.publishedAt, + }) + .from(geekdailyEpisodes) + .where(where) + .orderBy(desc(geekdailyEpisodes.episodeNumber)) + .limit(pagination.pageSize) + .offset(pagination.offset); + const itemsByEpisode = await loadItemsByEpisodeIds(rows.map((row) => row.id)); + + return { + items: rows.map((row) => mapPublicEpisodePreview(row, itemsByEpisode.get(row.id) ?? [])), + meta: buildPaginatedMeta(pagination), + }; + }, + ); +}; + export const getPublicGeekDailyEpisodeBySlug = async (slug: string) => { return withPublicGeekDailyCache(`episode:${slug}`, async () => { const row = await getEpisodeRecordBySlug(slug); @@ -542,6 +609,7 @@ export const getGeekDailySearchDocuments = async () => { episodeNumber: geekdailyEpisodes.episodeNumber, title: geekdailyEpisodes.title, summary: geekdailyEpisodes.summary, + editorsJson: geekdailyEpisodes.editorsJson, tagsJson: geekdailyEpisodes.tagsJson, publishedAt: geekdailyEpisodes.publishedAt, }) @@ -558,6 +626,7 @@ export const getGeekDailySearchDocuments = async () => { episodeNumber: row.episodeNumber, title: row.title, summary: row.summary, + editors: getEditors(row.editorsJson), tags: getTags(row.tagsJson), publishedAt, year: String(new Date(publishedAt).getUTCFullYear()), diff --git a/apps/api/src/lib/site.ts b/apps/api/src/lib/site.ts index 1e1506b..2458d79 100644 --- a/apps/api/src/lib/site.ts +++ b/apps/api/src/lib/site.ts @@ -264,6 +264,7 @@ export const getPublicSiteConfig = async () => { { label: '首页', href: '/' }, { label: '极客日报', href: '/geekdaily' }, { label: 'Who-Is-Hiring', href: '/who-is-hiring' }, + { label: '文章', href: '/articles' }, { label: '活动', href: '/events' }, { label: '贡献者们', href: '/contributors' }, { label: '关于Rebase', href: '/about' }, diff --git a/apps/api/src/routes/public.ts b/apps/api/src/routes/public.ts index 04273ec..aa2d992 100644 --- a/apps/api/src/routes/public.ts +++ b/apps/api/src/routes/public.ts @@ -8,6 +8,7 @@ import { getGeekDailySearchDocuments, getPublicGeekDailyEpisodeBySlug, getPublicGeekDailyOverview, + listPublicGeekDailyArchivePage, listPublicGeekDailyEpisodePreviews, listPublicGeekDailyEpisodes, } from '../lib/geekdaily.js'; @@ -150,6 +151,23 @@ publicRoutes.get('/geekdaily/overview', async (c) => { return c.json(ok(await getPublicGeekDailyOverview())); }); +publicRoutes.get('/geekdaily/archive', async (c) => { + const rawYear = c.req.query('year'); + const year = rawYear && /^\d{4}$/.test(rawYear) ? Number.parseInt(rawYear, 10) : undefined; + const tag = c.req.query('tag')?.trim() ?? ''; + const page = getPositiveLimit(c.req.query('page'), 1); + const pageSize = getPositiveLimit(c.req.query('pageSize'), 18); + const result = await listPublicGeekDailyArchivePage({ + page, + pageSize, + year, + tag, + }); + + c.header('Cache-Control', publicCacheControl); + return c.json(ok(result.items, result.meta)); +}); + publicRoutes.get('/geekdaily/search', async (c) => { c.header('Cache-Control', publicCacheControl); return c.json(ok(await getGeekDailySearchDocuments())); diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index c15203a..03bb0c6 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -21,8 +21,12 @@ export function getApiBaseUrl() { return API_BASE_URL; } +export function getPublicApiUrl(pathname: string) { + return new URL(pathname, `${API_BASE_URL}/`); +} + export async function fetchPublicApi(pathname: string): Promise { - const url = new URL(pathname, `${API_BASE_URL}/`); + const url = getPublicApiUrl(pathname); const response = await fetch(url, { headers: { Accept: 'application/json', @@ -44,6 +48,23 @@ export async function fetchPublicApi(pathname: string): Promise { return payload.data; } +export async function proxyPublicApi(pathname: string) { + const response = await fetch(getPublicApiUrl(pathname), { + headers: { + Accept: 'application/json', + }, + }); + + const headers = new Headers(); + headers.set('content-type', response.headers.get('content-type') ?? 'application/json; charset=utf-8'); + headers.set('cache-control', response.headers.get('cache-control') ?? 'public, max-age=300, stale-while-revalidate=3600'); + + return new Response(response.body, { + status: response.status, + headers, + }); +} + export async function fetchApiReady() { return fetchPublicApi<{ status: string; checks: { database: string; auth: string } }>('/ready'); } diff --git a/apps/web/src/lib/content.ts b/apps/web/src/lib/content.ts index 2d72830..fe99e69 100644 --- a/apps/web/src/lib/content.ts +++ b/apps/web/src/lib/content.ts @@ -55,21 +55,6 @@ interface PublicGeekDailyEpisodePayload extends Omit items: PublicGeekDailyItemPayload[]; } -interface GeekDailySearchDocument { - slug: string; - episodeNumber: number; - title: string; - summary: string; - tags: string[]; - publishedAt: string; - year: string; - items: Array<{ - title: string; - authorName: string; - summary: string; - }>; -} - interface GeekDailyArchiveOverviewPayload { totalEpisodes: number; years: number[]; @@ -230,10 +215,6 @@ export async function getGeekDailyArchiveOverview() { return fetchPublicApi('/api/public/v1/geekdaily/overview'); } -export async function getGeekDailySearchDocuments() { - return fetchPublicApi('/api/public/v1/geekdaily/search'); -} - export async function getLatestArticles(count = 3) { return fetchPublicApi(`/api/public/v1/articles?limit=${count}`); } @@ -243,7 +224,10 @@ export async function getLatestJobs(count = 3) { } export async function getLatestGeekDaily(count = 3) { - const episodes = await fetchPublicApi(`/api/public/v1/geekdaily?limit=${count}`); + const previews = await fetchPublicApi(`/api/public/v1/geekdaily?limit=${count}`); + const episodes = await Promise.all( + previews.map((episode) => fetchPublicApi(`/api/public/v1/geekdaily/${episode.slug}`)), + ); return episodes.map(mapGeekDailyEpisode); } diff --git a/apps/web/src/lib/rss.ts b/apps/web/src/lib/rss.ts new file mode 100644 index 0000000..254f0b1 --- /dev/null +++ b/apps/web/src/lib/rss.ts @@ -0,0 +1,69 @@ +export interface WebRssItem { + title: string; + link: string; + description: string; + pubDate?: string | Date | null; + guid?: string; +} + +interface WebRssFeedOptions { + title: string; + link: string; + description: string; + language?: string; + items: WebRssItem[]; +} + +const escapeXml = (value: string) => + value + .replaceAll('&', '&') + .replaceAll('<', '<') + .replaceAll('>', '>') + .replaceAll('"', '"') + .replaceAll("'", '''); + +const wrapCdata = (value: string) => `', ']]]]>')}]]>`; + +export const withBaseUrl = (baseUrl: string, pathname: string) => new URL(pathname, baseUrl).toString(); + +export const buildRssXml = (options: WebRssFeedOptions) => { + const language = options.language ?? 'zh-cn'; + const itemsXml = options.items + .map((item) => { + const pubDate = item.pubDate ? new Date(item.pubDate).toUTCString() : null; + + return [ + '', + `${escapeXml(item.title)}`, + `${escapeXml(item.link)}`, + `${escapeXml(item.guid ?? item.link)}`, + `${wrapCdata(item.description)}`, + pubDate ? `${escapeXml(pubDate)}` : '', + '', + ] + .filter(Boolean) + .join(''); + }) + .join(''); + + return [ + '', + '', + '', + `${escapeXml(options.title)}`, + `${escapeXml(options.link)}`, + `${escapeXml(options.description)}`, + `${escapeXml(language)}`, + itemsXml, + '', + '', + ].join(''); +}; + +export const rssResponse = (options: WebRssFeedOptions) => + new Response(buildRssXml(options), { + headers: { + 'content-type': 'application/rss+xml; charset=utf-8', + 'cache-control': 'public, max-age=300, stale-while-revalidate=3600', + }, + }); diff --git a/apps/web/src/pages/api/geekdaily-archive.json.ts b/apps/web/src/pages/api/geekdaily-archive.json.ts new file mode 100644 index 0000000..d8e2a69 --- /dev/null +++ b/apps/web/src/pages/api/geekdaily-archive.json.ts @@ -0,0 +1,9 @@ +import { proxyPublicApi } from '@/lib/api'; + +export async function GET({ request }: { request: Request }) { + const url = new URL(request.url); + const search = url.searchParams.toString(); + const suffix = search ? `?${search}` : ''; + + return proxyPublicApi(`/api/public/v1/geekdaily/archive${suffix}`); +} diff --git a/apps/web/src/pages/api/geekdaily-search.json.ts b/apps/web/src/pages/api/geekdaily-search.json.ts index 1c1d1c9..e8574aa 100644 --- a/apps/web/src/pages/api/geekdaily-search.json.ts +++ b/apps/web/src/pages/api/geekdaily-search.json.ts @@ -1,12 +1,5 @@ -import { getGeekDailySearchDocuments } from '@/lib/content'; +import { proxyPublicApi } from '@/lib/api'; export async function GET() { - const documents = await getGeekDailySearchDocuments(); - - return new Response(JSON.stringify(documents), { - headers: { - 'content-type': 'application/json; charset=utf-8', - 'cache-control': 'public, max-age=300, stale-while-revalidate=3600', - }, - }); + return proxyPublicApi('/api/public/v1/geekdaily/search'); } diff --git a/apps/web/src/pages/articles/rss.xml.ts b/apps/web/src/pages/articles/rss.xml.ts index e4e476a..ddff764 100644 --- a/apps/web/src/pages/articles/rss.xml.ts +++ b/apps/web/src/pages/articles/rss.xml.ts @@ -1,21 +1,20 @@ -import rss from '@astrojs/rss'; import { getLatestArticles, getSiteSettings } from '@/lib/content'; import { getArticlePath } from '@/lib/paths'; +import { rssResponse, withBaseUrl } from '@/lib/rss'; export async function GET() { const [site, articles] = await Promise.all([getSiteSettings(), getLatestArticles(3)]); const items = articles.map((article) => ({ title: article.title, - description: article.summary, + description: `

${article.summary}

`, pubDate: new Date(article.publishedAt), - link: getArticlePath(article.slug), + link: withBaseUrl(site.primaryDomain, getArticlePath(article.slug)), })); - return rss({ + return rssResponse({ title: 'Rebase articles', + link: withBaseUrl(site.primaryDomain, '/articles/rss.xml'), description: 'Latest published articles from Rebase.', - site: site.primaryDomain, items, - customData: 'zh-cn', }); } diff --git a/apps/web/src/pages/events/rss.xml.ts b/apps/web/src/pages/events/rss.xml.ts index 0a6d477..2d8cabc 100644 --- a/apps/web/src/pages/events/rss.xml.ts +++ b/apps/web/src/pages/events/rss.xml.ts @@ -1,6 +1,6 @@ -import rss from '@astrojs/rss'; import { getEvents, getSiteSettings } from '@/lib/content'; import { getEventPath } from '@/lib/paths'; +import { rssResponse, withBaseUrl } from '@/lib/rss'; export async function GET() { const [site, events] = await Promise.all([getSiteSettings(), getEvents()]); @@ -9,16 +9,15 @@ export async function GET() { .slice(0, 3) .map((event) => ({ title: event.title, - description: event.summary, + description: `

${event.summary}

`, pubDate: new Date(event.startAt), - link: getEventPath(event.startAt, event.slug), + link: withBaseUrl(site.primaryDomain, getEventPath(event.startAt, event.slug)), })); - return rss({ + return rssResponse({ title: 'Rebase events', + link: withBaseUrl(site.primaryDomain, '/events/rss.xml'), description: 'Latest event updates from Rebase.', - site: site.primaryDomain, items, - customData: 'zh-cn', }); } diff --git a/apps/web/src/pages/geekdaily/index.astro b/apps/web/src/pages/geekdaily/index.astro index 5ba6944..d0c51a8 100644 --- a/apps/web/src/pages/geekdaily/index.astro +++ b/apps/web/src/pages/geekdaily/index.astro @@ -23,7 +23,10 @@ Astro.response.headers.set('Cache-Control', 'public, max-age=300, stale-while-re >
-

极客日报

+
+

极客日报

+ Issue Archive +

Rebase 极客日报

由社区志愿者持续整理发布,每期收录值得关注的技术内容、推荐人和推荐语,方便你按期回看、检索与订阅。 @@ -100,6 +103,7 @@ Astro.response.headers.set('Cache-Control', 'public, max-age=300, stale-while-re {episode.title}

{episode.summary}

+ {episode.editors.length > 0 &&

编辑:{episode.editors.join('、')}

}
    {episode.items.slice(0, 3).map((item) =>
  • {item.title}
  • )}
@@ -115,6 +119,36 @@ Astro.response.headers.set('Cache-Control', 'public, max-age=300, stale-while-re