|
|
@ -1,44 +1,12 @@ |
|
|
|
import type { MarkdownFileType } from './file'; |
|
|
|
import type { MarkdownFileType } from './file'; |
|
|
|
import type { AuthorFileType } from './author.ts'; |
|
|
|
import type { AuthorFileType } from './author.ts'; |
|
|
|
import { getAllAuthors } from './author.ts'; |
|
|
|
import { getAllAuthors } from './author.ts'; |
|
|
|
import type { GuideFileType } from './guide.ts'; |
|
|
|
import { getCollection, type CollectionEntry } from 'astro:content'; |
|
|
|
import { getAllGuides } from './guide.ts'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface VideoFrontmatter { |
|
|
|
export type VideoFileType = CollectionEntry<'videos'> & { |
|
|
|
title: string; |
|
|
|
|
|
|
|
description: string; |
|
|
|
|
|
|
|
authorId: string; |
|
|
|
|
|
|
|
seo: { |
|
|
|
|
|
|
|
title: string; |
|
|
|
|
|
|
|
description: string; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
isNew: boolean; |
|
|
|
|
|
|
|
duration: string; |
|
|
|
|
|
|
|
date: string; |
|
|
|
|
|
|
|
sitemap: { |
|
|
|
|
|
|
|
priority: number; |
|
|
|
|
|
|
|
changefreq: 'daily' | 'weekly' | 'monthly' | 'yearly'; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
tags: string[]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type VideoFileType = MarkdownFileType<VideoFrontmatter> & { |
|
|
|
|
|
|
|
id: string; |
|
|
|
|
|
|
|
author: AuthorFileType; |
|
|
|
author: AuthorFileType; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Generates id from the given video file |
|
|
|
|
|
|
|
* @param filePath Markdown file path |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @returns unique video identifier |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function videoPathToId(filePath: string): string { |
|
|
|
|
|
|
|
const fileName = filePath.split('/').pop() || ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fileName.replace('.md', ''); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function getVideosByAuthor( |
|
|
|
export async function getVideosByAuthor( |
|
|
|
authorId: string, |
|
|
|
authorId: string, |
|
|
|
): Promise<VideoFileType[]> { |
|
|
|
): Promise<VideoFileType[]> { |
|
|
@ -52,43 +20,38 @@ export async function getVideosByAuthor( |
|
|
|
* @returns Promisifed video files |
|
|
|
* @returns Promisifed video files |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export async function getAllVideos(): Promise<VideoFileType[]> { |
|
|
|
export async function getAllVideos(): Promise<VideoFileType[]> { |
|
|
|
const videos = import.meta.glob<VideoFileType>('/src/data/videos/*.md', { |
|
|
|
const videoEntries = await getCollection('videos'); |
|
|
|
eager: true, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const allAuthors = await getAllAuthors(); |
|
|
|
const allAuthors = await getAllAuthors(); |
|
|
|
|
|
|
|
|
|
|
|
const videoFiles = Object.values(videos); |
|
|
|
const enrichedVideos = videoEntries.map((videoFile) => { |
|
|
|
const enrichedVideos = videoFiles.map((videoFile) => ({ |
|
|
|
const author = allAuthors.find( |
|
|
|
|
|
|
|
(author) => author.slug === videoFile.data.authorId, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!author) { |
|
|
|
|
|
|
|
throw new Error( |
|
|
|
|
|
|
|
`Author with ID ${videoFile.data.authorId} not found for video ${videoFile.data.title}`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
...videoFile, |
|
|
|
...videoFile, |
|
|
|
id: videoPathToId(videoFile.file), |
|
|
|
author, |
|
|
|
author: allAuthors.find( |
|
|
|
}; |
|
|
|
(author) => author.slug === videoFile.frontmatter.authorId, |
|
|
|
}); |
|
|
|
)!, |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return enrichedVideos.sort( |
|
|
|
return enrichedVideos.sort( |
|
|
|
(a, b) => |
|
|
|
(a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(), |
|
|
|
new Date(b.frontmatter.date).valueOf() - |
|
|
|
|
|
|
|
new Date(a.frontmatter.date).valueOf(), |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function getVideoById(id: string): Promise<VideoFileType> { |
|
|
|
export async function getVideoById(id: string): Promise<VideoFileType> { |
|
|
|
const videoFilesMap: Record<string, VideoFileType> = |
|
|
|
const allVideos = await getAllVideos(); |
|
|
|
import.meta.glob<VideoFileType>('../data/videos/*.md', { |
|
|
|
const videoFile = allVideos.find((video) => video.slug === id); |
|
|
|
eager: true, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const videoFile = Object.values(videoFilesMap).find((videoFile) => { |
|
|
|
|
|
|
|
return videoPathToId(videoFile.file) === id; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (!videoFile) { |
|
|
|
if (!videoFile) { |
|
|
|
throw new Error(`Video with ID ${id} not found`); |
|
|
|
throw new Error(`Video with ID ${id} not found`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return videoFile; |
|
|
|
...videoFile, |
|
|
|
|
|
|
|
id: videoPathToId(videoFile.file), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|