@@ -7,6 +7,7 @@ import { getIngestConfigFromEnv } from "../src/lib/config";
|
||||
import type { ContentCache, ContentItem } from "../src/lib/content/types";
|
||||
import { readInstagramEmbedPosts } from "../src/lib/ingest/instagram";
|
||||
import { fetchPodcastRss } from "../src/lib/ingest/podcast";
|
||||
import { fetchWordpressContent } from "../src/lib/ingest/wordpress";
|
||||
import { fetchYoutubeViaApi, fetchYoutubeViaRss } from "../src/lib/ingest/youtube";
|
||||
|
||||
function log(msg: string) {
|
||||
@@ -39,6 +40,16 @@ async function main() {
|
||||
const generatedAt = new Date().toISOString();
|
||||
|
||||
const all: ContentItem[] = [];
|
||||
const outPath = path.join(process.cwd(), "content", "cache", "content.json");
|
||||
|
||||
// Read the existing cache so we can keep last-known-good sections if a source fails.
|
||||
let existing: ContentCache | undefined;
|
||||
try {
|
||||
const raw = await fs.readFile(outPath, "utf8");
|
||||
existing = JSON.parse(raw) as ContentCache;
|
||||
} catch {
|
||||
existing = undefined;
|
||||
}
|
||||
|
||||
// YouTube
|
||||
if (!cfg.youtubeChannelId) {
|
||||
@@ -85,12 +96,35 @@ async function main() {
|
||||
log(`Instagram: embed list failed (${String(e)})`);
|
||||
}
|
||||
|
||||
// WordPress (optional; powers /blog)
|
||||
let wordpress: ContentCache["wordpress"] = { posts: [], pages: [], categories: [] };
|
||||
if (!cfg.wordpressBaseUrl) {
|
||||
log("WordPress: skipped (missing WORDPRESS_BASE_URL)");
|
||||
wordpress = existing?.wordpress || wordpress;
|
||||
} else {
|
||||
try {
|
||||
const wp = await fetchWordpressContent({
|
||||
baseUrl: cfg.wordpressBaseUrl,
|
||||
username: cfg.wordpressUsername,
|
||||
appPassword: cfg.wordpressAppPassword,
|
||||
});
|
||||
wordpress = wp;
|
||||
log(
|
||||
`WordPress: wp-json ok (${wp.posts.length} posts, ${wp.pages.length} pages, ${wp.categories.length} categories)`,
|
||||
);
|
||||
} catch (e) {
|
||||
log(`WordPress: wp-json failed (${String(e)})`);
|
||||
// Keep last-known-good WP content if present, otherwise fall back to empty.
|
||||
wordpress = existing?.wordpress || wordpress;
|
||||
}
|
||||
}
|
||||
|
||||
const cache: ContentCache = {
|
||||
generatedAt,
|
||||
items: dedupe(all),
|
||||
wordpress,
|
||||
};
|
||||
|
||||
const outPath = path.join(process.cwd(), "content", "cache", "content.json");
|
||||
await writeAtomic(outPath, JSON.stringify(cache, null, 2));
|
||||
log(`Wrote cache: ${outPath} (${cache.items.length} total items)`);
|
||||
}
|
||||
|
||||
27
site/scripts/verify-blog-build.ts
Normal file
27
site/scripts/verify-blog-build.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { access, readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { readContentCache } from "../src/lib/content/cache";
|
||||
|
||||
async function main() {
|
||||
const distPath = path.join(process.cwd(), "dist", "blog", "index.html");
|
||||
await access(distPath);
|
||||
|
||||
const html = await readFile(distPath, "utf8");
|
||||
|
||||
const cache = await readContentCache();
|
||||
const posts = cache.wordpress?.posts || [];
|
||||
|
||||
if (posts.length === 0) {
|
||||
if (!html.includes("No blog posts yet.")) {
|
||||
throw new Error("Expected /blog empty state to be present when no WordPress posts exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(String(e));
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user