fix: 🐛 Fixes crash when body od newItem is empty
✅ Closes: 525
This commit is contained in:
parent
78b442bac2
commit
3e0fd1474a
|
@ -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
|
||||
|
|
|
@ -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 })
|
||||
|
|
Loading…
Reference in New Issue