computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
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.4 KiB
62 lines
1.4 KiB
import type { MarkdownFileType } from './file'; |
|
|
|
export interface GuideFrontmatter { |
|
title: string; |
|
description: string; |
|
author: { |
|
name: string; |
|
url: string; |
|
imageUrl: string; |
|
}; |
|
canonicalUrl?: string; |
|
seo: { |
|
title: string; |
|
description: string; |
|
}; |
|
isNew: boolean; |
|
type: 'visual' | 'textual'; |
|
date: string; |
|
sitemap: { |
|
priority: number; |
|
changefreq: 'daily' | 'weekly' | 'monthly' | 'yealry'; |
|
}; |
|
tags: string[]; |
|
} |
|
|
|
export type GuideFileType = MarkdownFileType<GuideFrontmatter> & { |
|
id: string; |
|
}; |
|
|
|
/** |
|
* Generates id from the given guide file |
|
* @param filePath Markdown file path |
|
* |
|
* @returns unique guide identifier |
|
*/ |
|
function guidePathToId(filePath: string): string { |
|
const fileName = filePath.split('/').pop() || ''; |
|
|
|
return fileName.replace('.md', ''); |
|
} |
|
|
|
/** |
|
* Gets all the guides sorted by the publishing date |
|
* @returns Promisifed guide files |
|
*/ |
|
export async function getAllGuides(): Promise<GuideFileType[]> { |
|
const guides = await import.meta.glob<GuideFileType>('/src/guides/*.md', { |
|
eager: true, |
|
}); |
|
|
|
const guideFiles = Object.values(guides); |
|
const enrichedGuides = guideFiles.map((guideFile) => ({ |
|
...guideFile, |
|
id: guidePathToId(guideFile.file), |
|
})); |
|
|
|
return enrichedGuides.sort( |
|
(a, b) => |
|
new Date(b.frontmatter.date).valueOf() - |
|
new Date(a.frontmatter.date).valueOf() |
|
); |
|
}
|
|
|