feat: add Journal page

This commit is contained in:
Stefan Imhoff
2023-05-31 19:34:46 +02:00
parent 3da1c5c0d2
commit 3a96fd808e
39 changed files with 640 additions and 15 deletions

9
src/utils/date.ts Normal file
View File

@@ -0,0 +1,9 @@
import moment from 'moment';
export const dateToFormat = (date: Date, format = 'MMMM Do, YYYY') => {
return moment(date).format(format);
};
export const dateToISO = (date: Date) => {
return moment(date).format();
};

5
src/utils/index.ts Normal file
View File

@@ -0,0 +1,5 @@
export * from './date';
export * from './remark-reading-time';
export * from './sort-by-date';
export * from './sort-by-sortkey';
export * from './word-count';

View File

@@ -0,0 +1,13 @@
import { toString } from 'mdast-util-to-string';
import getReadingTime from 'reading-time';
import type { Node } from 'unist';
export const remarkReadingTime = () => {
return function (tree: Node, { data }: { data: any }) {
const textOnPage = toString(tree);
const readingTime = getReadingTime(textOnPage);
data.astro.frontmatter.minutesRead = readingTime.text;
};
};

6
src/utils/word-count.ts Normal file
View File

@@ -0,0 +1,6 @@
export const wordCount = (text: string) => {
const clean = text.replace(/<\/?[^>]+(>|$)/g, '');
const numberOfWords = clean.split(/\s/g).length;
return numberOfWords;
};