58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
import { parseFile } from '../file/util.mjs'
|
|
|
|
export function parseArticles(articles) {
|
|
for (let i = 0; i < articles.length; i++) {
|
|
parseArticle(articles[i])
|
|
}
|
|
return articles
|
|
}
|
|
|
|
export function combineFilesWithArticles(articles, files) {
|
|
let articleMap = new Map()
|
|
|
|
articles.forEach(article => {
|
|
article.files = []
|
|
articleMap.set(article.id, article)
|
|
})
|
|
files.forEach(file => {
|
|
articleMap.get(file.id).files.push(parseFile(file))
|
|
})
|
|
}
|
|
|
|
export function parseArticle(article) {
|
|
if (!article) {
|
|
return null
|
|
}
|
|
if (article.content) {
|
|
if (article.content[0] === '{') {
|
|
try {
|
|
article.content = JSON.parse(article.content)
|
|
} catch (err) {
|
|
article.content = {
|
|
time: new Date().getTime(),
|
|
blocks: [
|
|
{id: '1', type: 'paragraph', data: { text: 'Error parsing article content: ' + err.message }},
|
|
],
|
|
version: '2.25.0'
|
|
}
|
|
}
|
|
} else {
|
|
article.content = {
|
|
time: new Date().getTime(),
|
|
blocks: [
|
|
{id: '1', type: 'htmlraw', data: { html: article.content }},
|
|
],
|
|
version: '2.25.0'
|
|
}
|
|
}
|
|
}
|
|
if (article.banner_path) {
|
|
article.banner_path = 'https://cdn.nfp.is' + article.banner_path
|
|
article.banner_alt_prefix = 'https://cdn.nfp.is' + article.banner_alt_prefix
|
|
}
|
|
if (article.media_path) {
|
|
article.media_path = 'https://cdn.nfp.is' + article.media_path
|
|
article.media_alt_prefix = 'https://cdn.nfp.is' + article.media_alt_prefix
|
|
}
|
|
return article
|
|
} |