Implement content generation
This commit is contained in:
10
src/utils/articles.ts
Normal file
10
src/utils/articles.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Парсит дату из ID статьи (формат: "2019-05-01-slug").
|
||||
*/
|
||||
export function parseDateFromId(id: string): Date {
|
||||
const match = id.match(/^(\d{4})-(\d{2})-(\d{2})-/);
|
||||
if (!match) {
|
||||
throw new Error(`Cannot parse date from article id: ${id}`);
|
||||
}
|
||||
return new Date(`${match[1]}-${match[2]}-${match[3]}`);
|
||||
}
|
||||
Reference in New Issue
Block a user