Skip to content

JSON-LD metadata is skipped when regular meta fields are empty #425

Description

@chyyynh

Version

@extractus/article-extractor@8.1.0

Problem

JSON-LD-only article metadata is not copied into the result when the equivalent regular meta field is empty.

In src/utils/extractLdSchema.js, the current guard is:

if (!entry[key] || !ldJson[attr]) {
  continue
}

This skips exactly when entry[key] is empty. The intended guard appears to be:

if (entry[key] || !ldJson[attr]) {
  continue
}

The same condition is present in 8.0.20.

Reproduction

import { extractFromHtml } from '@extractus/article-extractor'

const html = `<html><head>
<title>Fixture article</title>
<script type="application/ld+json">
${JSON.stringify({
  '@context': 'https://schema.org',
  '@type': 'NewsArticle',
  author: { name: 'JSON Author' },
  datePublished: '2026-01-02T03:04:05Z',
  description: 'JSON description',
  image: 'https://example.com/json.jpg'
})}
</script></head><body><article><h1>Fixture article</h1><p>${'Article text. '.repeat(50)}</p></article></body></html>`

console.log(await extractFromHtml(html, 'https://example.com/story'))

Actual

author, published, and image are empty. description falls back to a generated content excerpt.

Expected

The JSON-LD values should populate fields that were not already populated by regular metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions