【发布时间】:2019-02-20 17:50:57
【问题描述】:
我有一些关联数据 JSON,我想知道当且仅当有第二项时如何将第二项添加到数组中。
在我的例子中,为一篇文章添加一个或两个共同作者。
script(type="application/ld+json").
{
"@context": "http://schema.org",
"@type": "Article",
"headline": "#{article.title}",
"description": "#{article.description}",
"author": [{
"@type": "Person",
"name": "#{article.author && article.author.name}",
"givenName": "#{article.author && article.author.givenName}",
"additionalName": "#{article.author && article.author.additionalName}",
"familyName": "#{article.author && article.author.familyName}",
"email": "#{article.author && article.author.email}",
"jobTitle": "#{article.author && article.author.jobTitle}",
"workLocation": "#{article.author && article.author.workLocation}",
"worksFor": "Company",
"image": "#{article.author && article.author.image}",
"url": "#{article.author && article.author.url}",
"sameAs": !{JSON.stringify(article.author && article.author.sameAs)}
}],
"datePublished": "#{article.date}",
"dateModified": "#{article.updated || article.date}",
"publisher": {
"@type": "Organization",
"name": "Company",
"logo": {
"@type": "ImageObject",
"url": "...logo-url.jpg"
}
},
"image": "#{article.image}",
"url": "#{article.url}"
}
这里的模板语言是 pug。
那么我该如何添加第二个人呢?
"sameAs": !{JSON.stringify(article.author && article.author.sameAs)}
}
if (coauthor) return ,{author-2}
],
"datePublished": "#{article.date}",
【问题讨论】: