From fd17bba66e50a2b62db05ba24eb2d8a9a49cec10 Mon Sep 17 00:00:00 2001 From: Bryan Stopp Date: Wed, 24 Apr 2024 12:46:31 -0400 Subject: [PATCH] Handle missing author data. (#309) --- cigaradvisor/blocks/article-teaser/article-teaser.js | 7 ++++--- cigaradvisor/blocks/articleheader/articleheader.js | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cigaradvisor/blocks/article-teaser/article-teaser.js b/cigaradvisor/blocks/article-teaser/article-teaser.js index dc5100a..f06e7b5 100644 --- a/cigaradvisor/blocks/article-teaser/article-teaser.js +++ b/cigaradvisor/blocks/article-teaser/article-teaser.js @@ -5,6 +5,7 @@ import { // eslint-disable-next-line max-len export function buildArticleTeaser(parentElement, article) { + const author = article.author || {}; const ldjson = { '@context': 'http://schema.org', '@type': 'BlogPosting', @@ -23,8 +24,8 @@ export function buildArticleTeaser(parentElement, article) { dateModified: new Date(article.lastModified * 1000).toISOString(), author: { '@type': 'Person', - name: article.author.name, - url: `https://www.famous-smoke.com${article.author.path}`, + name: author.name || 'Unknown', + url: `https://www.famous-smoke.com${author.path || '/author'}`, }, image: `https://www.famous-smoke.com${article.image}`, }; @@ -47,7 +48,7 @@ export function buildArticleTeaser(parentElement, article) { ${article.heading}
- +
diff --git a/cigaradvisor/blocks/articleheader/articleheader.js b/cigaradvisor/blocks/articleheader/articleheader.js index e584b4b..910dfe2 100644 --- a/cigaradvisor/blocks/articleheader/articleheader.js +++ b/cigaradvisor/blocks/articleheader/articleheader.js @@ -10,7 +10,7 @@ export default async function decorate(block) { const picture = block.querySelector('picture'); const category = await fetchCategoryInfo(config.category); - const author = await fetchAuthorInfo(config.author); + const author = await fetchAuthorInfo(config.author) || {}; const sect = section( {}, div({ class: 'image-wrapper' }, picture), @@ -18,7 +18,7 @@ export default async function decorate(block) { { class: 'article-info' }, div({ class: 'article-category' }, a({ href: config.category }, category.heading)), h1(config.heading), - div({ class: 'article-author' }, a({ href: config.author }, author.name)), + div({ class: 'article-author' }, a({ href: config.author }, author.name || 'Unknown')), ), ); block.replaceChildren(sect);