40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import yaml from 'js-yaml'
|
|
import matter from 'gray-matter'
|
|
|
|
const PODCAST_DIR = path.join(process.cwd(), 'content', 'podcast')
|
|
const POSTS_DIR = path.join(process.cwd(), 'content', 'posts')
|
|
|
|
const podFiles = fs.readdirSync(PODCAST_DIR).filter(f => f.startsWith('ep-') && f.endsWith('.yaml')).sort()
|
|
const postFiles = fs.readdirSync(POSTS_DIR).filter(f => f.endsWith('.md')).sort()
|
|
|
|
const podcasts = podFiles.map(f => {
|
|
const content = fs.readFileSync(path.join(PODCAST_DIR, f), 'utf8')
|
|
const doc = yaml.load(content)
|
|
return { filename: f, ...doc }
|
|
})
|
|
|
|
const posts = postFiles.map(f => {
|
|
const content = fs.readFileSync(path.join(POSTS_DIR, f), 'utf8')
|
|
const data = matter(content)
|
|
return { filename: f, title: data.data.title, date: data.data.date, body: data.content }
|
|
})
|
|
|
|
console.log("=== PODCASTS ===")
|
|
podcasts.forEach(p => {
|
|
console.log(`\nID: ${p.id} | Date: ${p.date} | Title: ${p.title}`)
|
|
// Find matching post by title similarity or keywords
|
|
const cleanTitle = p.title.replace(/^\d{3}:\s*/, '').toLowerCase()
|
|
const matches = posts.filter(post => {
|
|
const pTitle = (post.title || '').toLowerCase()
|
|
const pBody = (post.body || '').toLowerCase()
|
|
return pTitle.includes(cleanTitle) || pBody.includes(cleanTitle) || (post.title && cleanTitle.includes(post.title.toLowerCase()))
|
|
})
|
|
if (matches.length > 0) {
|
|
matches.forEach(m => console.log(` -> MATCHED POST: [${m.filename}] Date: ${m.date} | Title: ${m.title}`))
|
|
} else {
|
|
console.log(` -> NO MATCHING POST FOUND`)
|
|
}
|
|
})
|