I sampled the Article markup on 54 pages. Every headline matched its h1, and two descriptions contain a typed-out unicode escape

2026-12-01来源 dev.toEnglish

On 27 November I added schema.org Article markup to the content page templates of CogniPrep: provider hubs, test pages, employer guides, test-type pages and interview guides. Today I checked it against the live site instead of trusting the unit test. The test passed all along. One finding was a bug the test could not see.

The helper

The whole thing is one function that takes a headline, a path and a few optional fields, and returns the object:

export function articleSchema({ headline, description, path, dateModified, about }: ArticleSchemaInput) { const url = `${BASE_URL}${path}`; return { '@context': 'https://schema.org', '@type': 'Article', headline, ...(description && { description }), url, ...(dateModified && { dateModified }), ...(about && { about }), // author, publisher, mainEntityOfPage }; } 

Two decisions in it are deliberate. Optional fields are spread in only when the page has them, so a page that keeps no review date emits no dateModified at all instead of today's date. And the test says so in its name: it leaves out optional fields the page does not have rather than inventing them. The same rule I wrote about in an earlier post is now enforced by a function signature.

One type change came with it. The provider hub's heading prop used to be a React node, so a page could pass markup. It is now a plain string, with a comment saying why: it is also the Article headline. Reusing one value for the visible heading and the markup is how you make them unable to drift apart.

What I measured

I pulled the live sitemap, which has 1,155 URLs, grouped them by path shape, and fetched six random pages from each group with a browser user agent. Then I parsed every application/ld+json block and compared the Article's headline with the page's h1.

  • Nine page shapes emit an Article: provider hubs, game and test pages, test types, employer guides, interview guides, answer pages, cheating guides, the application tracker pages and the assessment centre pages. That is 54 sampled pages.
  • On all 54 the headline equals the h1 text exactly.
  • Only 18 of the 54 carry dateModified: the answer pages, the cheating guides and the game pages. Those are the ones that record a review date. The other 36 leave the field out.
  • Blog posts emit BlogPosting and comparison pages emit WebPage, which is intended, not a gap.

You can look at a sample yourself. Open cogniprep.app/tests/numerical-reasoning, run this in the console, and compare the headline with the page title:

[...document.querySelectorAll('script[type="application/ld+json"]')] .map(s => JSON.parse(s.textContent)) .filter(n => n['@type'] === 'Article') 

The bug the test could not see

While reading the descriptions I noticed one that looked wrong. Open cogniprep.app/employers/hsbc, run the same snippet, and read the description. Where an apostrophe belongs, it contains a backslash and the characters u2019. The visible meta description is fine.

The cause is one line in the page source: the structured data description is passed as a JSX attribute, and the author wrote a unicode escape inside it. A JSX attribute string is not a JavaScript string. It does not process escapes, so the backslashes arrive as typed. JSON.stringify then escapes them again on the way out.

Two employer pages have it, HSBC and Allstate, and both have had it since September. The other employer pages write the curly apostrophe directly, which is why this stood out.

Why did nothing catch it? The unit test checks the builder, which receives whatever string it is given. It could never know that the string was wrong. The only check that sees it is one that reads the rendered output, which is what the sampling script did.

Takeaways

  1. A unit test of a schema builder proves the shape. Only a fetch of the live page proves the content.
  2. Put one value behind both the visible heading and the markup. It had zero mismatches in 54 pages.
  3. In JSX attributes, type the character, not an escape. Or use a braced expression, where a normal JavaScript string applies.
  4. Leave a field out when you do not know it. An absent date is honest, and a wrong one is not.

原文:https://www.a8q9.cn/en/article/i-sampled-the-article-markup-on-54-pages-every-headline-matched-its-h1-and-two-d-73cab0.html

相关文章