Update
This commit is contained in:
@ -1,10 +1,6 @@
|
||||
import { promises as fs } from "fs";
|
||||
import { dirname } from "path";
|
||||
import {
|
||||
Episode,
|
||||
fetchAllEpisodes,
|
||||
performDatabaseIntegrityFixes,
|
||||
} from "./database.js";
|
||||
import { fetchEpisodesWithFeedInfo } from "./database.js";
|
||||
import path from "node:path";
|
||||
import fsSync from "node:fs";
|
||||
import { config } from "./config.js";
|
||||
@ -18,7 +14,7 @@ function escapeXml(text: string): string {
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function createItemXml(episode: Episode): string {
|
||||
function createItemXml(episode: any): string {
|
||||
const fileUrl = `${config.podcast.baseUrl}/podcast_audio/${path.basename(episode.audioPath)}`;
|
||||
const pubDate = new Date(episode.createdAt).toUTCString();
|
||||
|
||||
@ -35,10 +31,28 @@ function createItemXml(episode: Episode): string {
|
||||
console.warn(`Could not get file size for ${episode.audioPath}:`, error);
|
||||
}
|
||||
|
||||
// Build enhanced description with feed and article info
|
||||
let description = episode.title;
|
||||
if (episode.feedTitle || episode.articleTitle || episode.articleLink) {
|
||||
description += "\n\n";
|
||||
if (episode.feedTitle) {
|
||||
description += `フィード: ${episode.feedTitle}\n`;
|
||||
}
|
||||
if (episode.articleTitle && episode.articleTitle !== episode.title) {
|
||||
description += `元記事: ${episode.articleTitle}\n`;
|
||||
}
|
||||
if (episode.articlePubDate) {
|
||||
description += `記事公開日: ${new Date(episode.articlePubDate).toLocaleString("ja-JP")}\n`;
|
||||
}
|
||||
if (episode.articleLink) {
|
||||
description += `元記事URL: ${episode.articleLink}`;
|
||||
}
|
||||
}
|
||||
|
||||
return `
|
||||
<item>
|
||||
<title><![CDATA[${escapeXml(episode.title)}]]></title>
|
||||
<description><![CDATA[${escapeXml(episode.title)}]]></description>
|
||||
<description><![CDATA[${escapeXml(description)}]]></description>
|
||||
<author>${escapeXml(config.podcast.author)}</author>
|
||||
<category>${escapeXml(config.podcast.categories)}</category>
|
||||
<language>${config.podcast.language}</language>
|
||||
@ -46,15 +60,17 @@ function createItemXml(episode: Episode): string {
|
||||
<enclosure url="${escapeXml(fileUrl)}" length="${fileSize}" type="audio/mpeg" />
|
||||
<guid>${escapeXml(fileUrl)}</guid>
|
||||
<pubDate>${pubDate}</pubDate>
|
||||
${episode.articleLink ? `<link>${escapeXml(episode.articleLink)}</link>` : ""}
|
||||
</item>`;
|
||||
}
|
||||
|
||||
export async function updatePodcastRSS(): Promise<void> {
|
||||
try {
|
||||
const episodes: Episode[] = await fetchAllEpisodes();
|
||||
// Use episodes with feed info for enhanced descriptions
|
||||
const episodesWithFeedInfo = await fetchEpisodesWithFeedInfo();
|
||||
|
||||
// Filter episodes to only include those with valid audio files
|
||||
const validEpisodes = episodes.filter((episode) => {
|
||||
const validEpisodes = episodesWithFeedInfo.filter((episode) => {
|
||||
try {
|
||||
const audioPath = path.join(
|
||||
config.paths.podcastAudioDir,
|
||||
@ -68,7 +84,7 @@ export async function updatePodcastRSS(): Promise<void> {
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Found ${episodes.length} episodes, ${validEpisodes.length} with valid audio files`,
|
||||
`Found ${episodesWithFeedInfo.length} episodes, ${validEpisodes.length} with valid audio files`,
|
||||
);
|
||||
|
||||
const lastBuildDate = new Date().toUTCString();
|
||||
|
Reference in New Issue
Block a user