Skip to content
Merged

Dev #44

4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:

Expand Down Expand Up @@ -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
Expand All @@ -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`.
18 changes: 12 additions & 6 deletions apps/admin/src/views/GeekDailyEditorPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const errorMessage = ref('');
const successMessage = ref('');
const fieldIssues = ref<Record<string, string>>({});
const suggestedEpisodeNumber = ref(1);
const currentEditorName = ref('');
const currentStaffName = ref('');
const activeWechatTab = ref<'preview' | 'source'>('preview');
const copyFeedback = ref('');
let copyFeedbackTimer: number | null = null;
Expand All @@ -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,
}));
Expand Down Expand Up @@ -168,9 +174,9 @@ const applyRecord = (payload: AdminGeekDailyRecord) => {
const loadCurrentEditor = async () => {
try {
const me = await adminFetch<AdminMePayload>('/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 = '';
}
};

Expand Down Expand Up @@ -345,7 +351,7 @@ onBeforeUnmount(() => {

<div class="geekdaily-meta-item">
<span class="geekdaily-meta-label">本期编辑</span>
<strong class="geekdaily-meta-text">{{ currentEditorLabel }}</strong>
<strong class="geekdaily-meta-text">{{ episodeEditorLabel }}</strong>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions apps/admin/src/views/GeekDailyPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ onMounted(() => {
<div class="table-cell-stack">
<strong>{{ row.title }}</strong>
<div class="muted-row">第 {{ row.episodeNumber }} 期</div>
<div v-if="row.editors.length > 0" class="muted-row">编辑:{{ row.editors.join('、') }}</div>
</div>
</td>
<td><span class="status-pill">{{ formatContentStatus(row.status) }}</span></td>
Expand Down
73 changes: 71 additions & 2 deletions apps/api/src/lib/geekdaily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
})
Expand All @@ -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()),
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/lib/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
18 changes: 18 additions & 0 deletions apps/api/src/routes/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getGeekDailySearchDocuments,
getPublicGeekDailyEpisodeBySlug,
getPublicGeekDailyOverview,
listPublicGeekDailyArchivePage,
listPublicGeekDailyEpisodePreviews,
listPublicGeekDailyEpisodes,
} from '../lib/geekdaily.js';
Expand Down Expand Up @@ -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()));
Expand Down
23 changes: 22 additions & 1 deletion apps/web/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(pathname: string): Promise<T> {
const url = new URL(pathname, `${API_BASE_URL}/`);
const url = getPublicApiUrl(pathname);
const response = await fetch(url, {
headers: {
Accept: 'application/json',
Expand All @@ -44,6 +48,23 @@ export async function fetchPublicApi<T>(pathname: string): Promise<T> {
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');
}
24 changes: 4 additions & 20 deletions apps/web/src/lib/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,6 @@ interface PublicGeekDailyEpisodePayload extends Omit<GeekDailyEpisode, 'items'>
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[];
Expand Down Expand Up @@ -230,10 +215,6 @@ export async function getGeekDailyArchiveOverview() {
return fetchPublicApi<GeekDailyArchiveOverviewPayload>('/api/public/v1/geekdaily/overview');
}

export async function getGeekDailySearchDocuments() {
return fetchPublicApi<GeekDailySearchDocument[]>('/api/public/v1/geekdaily/search');
}

export async function getLatestArticles(count = 3) {
return fetchPublicApi<Article[]>(`/api/public/v1/articles?limit=${count}`);
}
Expand All @@ -243,7 +224,10 @@ export async function getLatestJobs(count = 3) {
}

export async function getLatestGeekDaily(count = 3) {
const episodes = await fetchPublicApi<PublicGeekDailyEpisodePayload[]>(`/api/public/v1/geekdaily?limit=${count}`);
const previews = await fetchPublicApi<PublicGeekDailyPreviewPayload[]>(`/api/public/v1/geekdaily?limit=${count}`);
const episodes = await Promise.all(
previews.map((episode) => fetchPublicApi<PublicGeekDailyEpisodePayload>(`/api/public/v1/geekdaily/${episode.slug}`)),
);
return episodes.map(mapGeekDailyEpisode);
}

Expand Down
Loading
Loading