2022-06-03 13:31:42 +02:00
|
|
|
/* eslint-disable import/prefer-default-export */
|
|
|
|
|
2023-10-30 13:32:14 +02:00
|
|
|
import { FrontMatter } from './frontMatter';
|
2022-06-03 13:31:42 +02:00
|
|
|
import { basename } from 'path';
|
|
|
|
const moment = require('moment');
|
|
|
|
|
2023-10-30 13:32:14 +02:00
|
|
|
export const getNewsDateString = (info: FrontMatter, mdFilePath: string): string => {
|
2022-06-03 15:03:29 +02:00
|
|
|
return moment(getNewsDate(info, mdFilePath)).format('D MMM YYYY');
|
|
|
|
};
|
|
|
|
|
2023-10-30 13:32:14 +02:00
|
|
|
export const getNewsDate = (info: FrontMatter, mdFilePath: string): Date => {
|
2022-06-03 13:31:42 +02:00
|
|
|
// If the date is set in the metadata, we get it from there. Otherwise we
|
|
|
|
// derive it from the filename (eg. 20220224-release-2-7.md)
|
|
|
|
|
|
|
|
if (info.created) {
|
2022-06-03 15:03:29 +02:00
|
|
|
return info.created;
|
2022-06-03 13:31:42 +02:00
|
|
|
} else {
|
|
|
|
const filenameNoExt = basename(mdFilePath, '.md');
|
|
|
|
const s = filenameNoExt.split('-');
|
2022-06-03 15:03:29 +02:00
|
|
|
return moment.utc(s[0], 'YYYYMMDD').toDate();
|
2022-06-03 13:31:42 +02:00
|
|
|
}
|
|
|
|
};
|