fix: 🐛 Fixes crash when body od newItem is empty

 Closes: 525
This commit is contained in:
Kajetan Kazimierczak 2021-11-16 13:33:00 +01:00
parent 78b442bac2
commit 3e0fd1474a
2 changed files with 11 additions and 1 deletions

View File

@ -26,9 +26,16 @@ export const newsItem = ({
imageUrl: bannerImageUrl,
fullImageUrl: `${IMAGE_HOST}${bannerImageUrl}`,
imageAltText: altText,
body: toMarkdown(body),
body: toNonEmptyMarkdownString(body),
})
// Fixes https://github.com/kolplattformen/skolplattformen/issues/525
const toNonEmptyMarkdownString = (str: string): string => {
const res = toMarkdown(str);
if(res?.length == 0 ) return ' '
return res
}
const newsSort = (item1: NewsItem, item2: NewsItem): number => {
const m1 = item1.modified || item1.published
const m2 = item2.modified || item2.published

View File

@ -105,6 +105,9 @@ const overides = {
}
export const toMarkdown = (html?: string): string => {
if(html?.length == 0) return ''
const rearranged = rearrangeWhitespace(html)
const trimmed = clean(rearranged)
const markdown = h2m(trimmed, { overides, converter })