1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/tools/website/utils/news.ts

23 lines
737 B
TypeScript
Raw Normal View History

2022-06-03 13:31:42 +02:00
/* eslint-disable import/prefer-default-export */
import { FrontMatter } from './frontMatter';
2022-06-03 13:31:42 +02:00
import { basename } from 'path';
const moment = require('moment');
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');
};
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
}
};