mirror of
https://github.com/kogakure/website-astro-stefanimhoff.de.git
synced 2026-02-04 04:25:28 +00:00
feat: add Journal page
This commit is contained in:
9
src/utils/date.ts
Normal file
9
src/utils/date.ts
Normal 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
5
src/utils/index.ts
Normal 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';
|
||||
13
src/utils/remark-reading-time.ts
Normal file
13
src/utils/remark-reading-time.ts
Normal 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
6
src/utils/word-count.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export const wordCount = (text: string) => {
|
||||
const clean = text.replace(/<\/?[^>]+(>|$)/g, '');
|
||||
const numberOfWords = clean.split(/\s/g).length;
|
||||
|
||||
return numberOfWords;
|
||||
};
|
||||
Reference in New Issue
Block a user