@@ -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)`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user