chore: clean up parsedcontent types
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { BlogParsedContent, StoryParsedContent } from "./types";
|
||||
import type { AnyParsedContent } from "./types";
|
||||
import readingTime from "reading-time";
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc.js";
|
||||
@@ -28,17 +28,17 @@ function search(obj: Record<string, any>, results: string[] = []) {
|
||||
return results;
|
||||
}
|
||||
|
||||
export function calcReadingTime(doc: BlogParsedContent | StoryParsedContent) {
|
||||
export function calcReadingTime(doc: AnyParsedContent) {
|
||||
let body: string[] = search(doc.body);
|
||||
return readingTime(body.join(" "));
|
||||
}
|
||||
|
||||
export function getPrettyDate(doc: BlogParsedContent | StoryParsedContent) {
|
||||
export function getPrettyDate(doc: AnyParsedContent) {
|
||||
const date = dayjs(doc.date).utc();
|
||||
return date.format("DD MMM YYYY");
|
||||
}
|
||||
|
||||
export function getUtcDate(doc: BlogParsedContent | StoryParsedContent) {
|
||||
export function getUtcDate(doc: AnyParsedContent) {
|
||||
const date = dayjs(doc.date).utc();
|
||||
return date.format("YYYY-MM-DD");
|
||||
}
|
||||
|
2
shared/types.d.ts
vendored
2
shared/types.d.ts
vendored
@@ -24,3 +24,5 @@ interface StoryParsedContent extends ParsedContent {
|
||||
readingTime: ReadingTime;
|
||||
nopreview?: boolean;
|
||||
}
|
||||
|
||||
type AnyParsedContent = BlogParsedContent | StoryParsedContent;
|
||||
|
Reference in New Issue
Block a user