mirror of
https://github.com/danog/sass-site.git
synced 2024-11-27 04:24:50 +01:00
231bc2b807
* main: Fix remaining blog issues First round of blog review. addressed style review comments sort out permalinks sort out permalinks Remove extra console log add author and date to individual blogs add blog.11tydate.yml file truncate html and date filters more blog edits components all working, need author and date subtitle
30 lines
913 B
TypeScript
30 lines
913 B
TypeScript
import {
|
|
format as formatBase,
|
|
formatDistanceToNow as formatDistanceBase,
|
|
} from 'date-fns';
|
|
|
|
/**
|
|
* Returns the formatted date string in the given format.
|
|
*
|
|
* @see https://date-fns.org/docs/format
|
|
*/
|
|
export const format = (date: string, pattern = 'd MMMM yyyy') =>
|
|
formatBase(new Date(date), pattern);
|
|
|
|
/**
|
|
* Returns the distance between the given date and now in words.
|
|
*
|
|
* @see https://date-fns.org/docs/formatDistanceToNow
|
|
*/
|
|
export const formatDistanceToNow = (date: string) =>
|
|
formatDistanceBase(new Date(date));
|
|
|
|
/* 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('format', format);
|
|
eleventyConfig.addLiquidFilter('formatDistanceToNow', formatDistanceToNow);
|
|
}
|