Roadmap to becoming a developer in 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB

import type { MarkdownFileType } from './file';
export interface VideoFrontmatter {
title: string;
description: string;
author: {
name: string;
url: string;
imageUrl: string;
};
seo: {
title: string;
description: string;
};
isNew: boolean;
duration: string;
date: string;
sitemap: {
priority: number;
changefreq: 'daily' | 'weekly' | 'monthly' | 'yealry';
};
tags: string[];
}
export type VideoFileType = MarkdownFileType<VideoFrontmatter> & {
id: string;
};
/**
* 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', '');
}
/**
* Gets all the videos sorted by the publishing date
* @returns Promisifed video files
*/
export async function getAllVideos(): Promise<VideoFileType[]> {
const videos = await import.meta.glob<VideoFileType>('/src/videos/*.md', {
eager: true,
});
const videoFiles = Object.values(videos);
const enrichedVideos = videoFiles.map((videoFile) => ({
...videoFile,
id: videoPathToId(videoFile.file),
}));
return enrichedVideos.sort(
(a, b) =>
new Date(b.frontmatter.date).valueOf() -
new Date(a.frontmatter.date).valueOf()
);
}