Skip to content

Commit

Permalink
fix: 🐛 Fixes crash when body od newItem is empty
Browse files Browse the repository at this point in the history
✅ Closes: 525
  • Loading branch information
kajetan-kazimierczak committed Nov 16, 2021
1 parent 78b442b commit 3e0fd14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libs/api-skolplattformen/lib/parse/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libs/api-skolplattformen/lib/parseHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 3e0fd14

Please sign in to comment.