From 85ae5f4e94af05a992f7fa70b78d2f9fcddc940c Mon Sep 17 00:00:00 2001 From: Damillora Date: Mon, 8 Aug 2022 12:24:59 +0700 Subject: [PATCH] fix: last paragraph disappearing --- src/lib/content/postProcessor.ts | 19 ++++++++++++------- src/routes/[tag]/[slug].svelte | 4 +++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/lib/content/postProcessor.ts b/src/lib/content/postProcessor.ts index 0497d3c..c7baefb 100644 --- a/src/lib/content/postProcessor.ts +++ b/src/lib/content/postProcessor.ts @@ -6,6 +6,7 @@ import stringify from "rehype-stringify"; import { visit } from 'unist-util-visit' import { fromSelector } from 'hast-util-from-selector'; import { generateSizesString, generateSrcsetString } from "./srcset"; +import type { Nullable } from "@tryghost/content-api"; const sizes = [300, 600, 1000, 1500, 2000]; @@ -59,12 +60,16 @@ export const postProcessor: Plugin = () => { }) } } -export const processPostHtml = async (postHtml: string) => { - const processor = unified() - .use(parse) - .use(postProcessor) - .use(stringify); +export const processPostHtml = async (postHtml?: Nullable) => { + if (postHtml) { + const processor = unified() + .use(parse) + .use(postProcessor) + .use(stringify); + + const result = await processor.process(postHtml); + return result.toString(); + } + return "Unable to process post"; - const result = await processor.process(postHtml); - return result.toString(); } \ No newline at end of file diff --git a/src/routes/[tag]/[slug].svelte b/src/routes/[tag]/[slug].svelte index 172aee3..582a2c5 100644 --- a/src/routes/[tag]/[slug].svelte +++ b/src/routes/[tag]/[slug].svelte @@ -8,7 +8,7 @@ error: new Error('Post not found') }; } - const newHtml = await processPostHtml(post.html ?? ''); + const newHtml = await processPostHtml(post.html); post.html = newHtml; const prevPost = await browsePrevPost(post); const nextPost = await browseNextPost(post); @@ -77,6 +77,8 @@ {@html post.html} + +