chore: clean up parsedcontent types
This commit is contained in:
parent
006c1494ca
commit
528e09a26f
@ -1,8 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getPrettyDate, getUtcDate } from "~~/shared/metadata";
|
import { getPrettyDate, getUtcDate } from "~~/shared/metadata";
|
||||||
import { BlogParsedContent, StoryParsedContent } from "~~/shared/types";
|
import { AnyParsedContent } from "~~/shared/types";
|
||||||
|
|
||||||
const props = defineProps<{ doc: StoryParsedContent | BlogParsedContent }>();
|
const props = defineProps<{ doc: AnyParsedContent }>();
|
||||||
|
|
||||||
const prettyDate = getPrettyDate(props.doc);
|
const prettyDate = getPrettyDate(props.doc);
|
||||||
const utcDate = getUtcDate(props.doc);
|
const utcDate = getUtcDate(props.doc);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { StoryParsedContent, BlogParsedContent } from "@/shared/types";
|
import type { AnyParsedContent } from "@/shared/types";
|
||||||
import { calcReadingTime } from "@/shared/metadata";
|
import { calcReadingTime } from "@/shared/metadata";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
post: StoryParsedContent | BlogParsedContent;
|
post: AnyParsedContent;
|
||||||
type: "stories" | "blog";
|
type: "stories" | "blog";
|
||||||
highlighttags?: string[];
|
highlighttags?: string[];
|
||||||
}>();
|
}>();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { type StoryParsedContent } from "@/shared/types";
|
import type { StoryParsedContent } from "@/shared/types";
|
||||||
import { calcReadingTime } from "@/shared/metadata";
|
import { calcReadingTime } from "@/shared/metadata";
|
||||||
|
|
||||||
const docs = await queryContent<StoryParsedContent>("/stories")
|
const docs = await queryContent<StoryParsedContent>("/stories")
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { BlogParsedContent, StoryParsedContent } from "@/shared/types";
|
import type { AnyParsedContent } from "@/shared/types";
|
||||||
import { calcReadingTime } from "@/shared/metadata";
|
import { calcReadingTime } from "@/shared/metadata";
|
||||||
|
|
||||||
type GeneralParsedContent = BlogParsedContent | StoryParsedContent;
|
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
// definePageMeta({
|
// definePageMeta({
|
||||||
// layout: "withtop",
|
// layout: "withtop",
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// we're not using ContentDoc because i need control
|
// we're not using ContentDoc because i need control
|
||||||
const doc = await queryContent<GeneralParsedContent>(route.path).findOne();
|
const doc = await queryContent<AnyParsedContent>(route.path).findOne();
|
||||||
const type = route.path.startsWith("/stories")
|
const type = route.path.startsWith("/stories")
|
||||||
? "stories"
|
? "stories"
|
||||||
: route.path.startsWith("/blog")
|
: route.path.startsWith("/blog")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import type { BlogParsedContent, StoryParsedContent } from "./types";
|
import type { AnyParsedContent } from "./types";
|
||||||
import readingTime from "reading-time";
|
import readingTime from "reading-time";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import utc from "dayjs/plugin/utc.js";
|
import utc from "dayjs/plugin/utc.js";
|
||||||
@ -28,17 +28,17 @@ function search(obj: Record<string, any>, results: string[] = []) {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calcReadingTime(doc: BlogParsedContent | StoryParsedContent) {
|
export function calcReadingTime(doc: AnyParsedContent) {
|
||||||
let body: string[] = search(doc.body);
|
let body: string[] = search(doc.body);
|
||||||
return readingTime(body.join(" "));
|
return readingTime(body.join(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPrettyDate(doc: BlogParsedContent | StoryParsedContent) {
|
export function getPrettyDate(doc: AnyParsedContent) {
|
||||||
const date = dayjs(doc.date).utc();
|
const date = dayjs(doc.date).utc();
|
||||||
return date.format("DD MMM YYYY");
|
return date.format("DD MMM YYYY");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUtcDate(doc: BlogParsedContent | StoryParsedContent) {
|
export function getUtcDate(doc: AnyParsedContent) {
|
||||||
const date = dayjs(doc.date).utc();
|
const date = dayjs(doc.date).utc();
|
||||||
return date.format("YYYY-MM-DD");
|
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;
|
readingTime: ReadingTime;
|
||||||
nopreview?: boolean;
|
nopreview?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AnyParsedContent = BlogParsedContent | StoryParsedContent;
|
||||||
|
Loading…
Reference in New Issue
Block a user