fix: last paragraph disappearing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Damillora 2022-08-08 12:24:59 +07:00
parent bba5926af4
commit 85ae5f4e94
2 changed files with 15 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import stringify from "rehype-stringify";
import { visit } from 'unist-util-visit' import { visit } from 'unist-util-visit'
import { fromSelector } from 'hast-util-from-selector'; import { fromSelector } from 'hast-util-from-selector';
import { generateSizesString, generateSrcsetString } from "./srcset"; import { generateSizesString, generateSrcsetString } from "./srcset";
import type { Nullable } from "@tryghost/content-api";
const sizes = [300, 600, 1000, 1500, 2000]; const sizes = [300, 600, 1000, 1500, 2000];
@ -59,12 +60,16 @@ export const postProcessor: Plugin = () => {
}) })
} }
} }
export const processPostHtml = async (postHtml: string) => { export const processPostHtml = async (postHtml?: Nullable<string>) => {
const processor = unified() if (postHtml) {
.use(parse) const processor = unified()
.use(postProcessor) .use(parse)
.use(stringify); .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();
} }

View File

@ -8,7 +8,7 @@
error: new Error('Post not found') error: new Error('Post not found')
}; };
} }
const newHtml = await processPostHtml(post.html ?? ''); const newHtml = await processPostHtml(post.html);
post.html = newHtml; post.html = newHtml;
const prevPost = await browsePrevPost(post); const prevPost = await browsePrevPost(post);
const nextPost = await browseNextPost(post); const nextPost = await browseNextPost(post);
@ -77,6 +77,8 @@
<PostMain> <PostMain>
<GhostStyle> <GhostStyle>
{@html post.html} {@html post.html}
<br/>
</GhostStyle> </GhostStyle>
<svelte:fragment slot="comments" /> <svelte:fragment slot="comments" />
</PostMain> </PostMain>