sass-site/source/helpers/dates.ts

18 lines
622 B
TypeScript
Raw Normal View History

2023-03-08 21:59:19 +01:00
import formatDistanceToNowBase from 'date-fns/formatDistanceToNow';
/**
* Returns the distance between the given date and now in words.
*
* @see https://date-fns.org/docs/formatDistanceToNow
*/
export const formatDistanceToNow = (date: string) =>
formatDistanceToNowBase(new Date(date));
2023-03-09 23:32:49 +01:00
/* eslint-disable @typescript-eslint/no-unsafe-member-access,
@typescript-eslint/no-unsafe-call,
@typescript-eslint/no-explicit-any */
export default function datesPlugin(eleventyConfig: any) {
// filters...
eleventyConfig.addLiquidFilter('formatDistanceToNow', formatDistanceToNow);
}