Skip to content

Commit

Permalink
Handle missing author data. (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
bstopp authored Apr 24, 2024
1 parent 1063ba8 commit fd17bba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions cigaradvisor/blocks/article-teaser/article-teaser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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}`,
};
Expand All @@ -47,7 +48,7 @@ export function buildArticleTeaser(parentElement, article) {
<a class="article-title-link" href="${article.path}" title="${article.heading}">${article.heading}</a>
</h2>
<div class="article-meta">
<a class="article-authorLink" href="${article.author ? article.author.path : ''}" title="By ${(article.author && article.author.name) ? article.author.name : ''}">By ${(article.author && article.author.name) ? article.author.name : ''}</a>
<a class="article-authorLink" href="${author.path || '/author'}" title="By ${author.name || 'Unknown'}">By ${author.name || 'Unknown'}</a>
</div>
</articleheader>
<div class="article-preview">
Expand Down
4 changes: 2 additions & 2 deletions cigaradvisor/blocks/articleheader/articleheader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ 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),
div(
{ 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);
Expand Down

0 comments on commit fd17bba

Please sign in to comment.