This repository was archived by the owner on Oct 12, 2026. It is now read-only.
Repository navigation
feat: add truthful public page structured data #19
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { readFileSync } from "node:fs" | ||
| import { fileURLToPath } from "node:url" | ||
| import { dirname, join } from "node:path" | ||
|
|
||
| const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..") | ||
| const read = (p) => readFileSync(join(ROOT, p), "utf8") | ||
|
|
||
| let failures = 0 | ||
| let checks = 0 | ||
| const ok = (cond, msg) => { | ||
| checks++ | ||
| if (cond) console.log(` ok ${msg}`) | ||
| else { | ||
| failures++ | ||
| console.error(` FAIL ${msg}`) | ||
| } | ||
| } | ||
|
|
||
| const PAGES = [ | ||
| { | ||
| file: "public/contact/index.html", | ||
| pageType: "ContactPage", | ||
| label: "contact page" | ||
| }, | ||
| { | ||
| file: "public/promptly/privacy/index.html", | ||
| pageType: "WebPage", | ||
| label: "Promptly privacy policy page" | ||
| } | ||
| ] | ||
|
|
||
| const ORG_ID = "https://tinystudio.in/#organization" | ||
| const ORG_NAME = "Tiny Studio" | ||
|
|
||
| const titleOf = (html) => { | ||
| const m = html.match(/<title>([^<]*)<\/title>/i) | ||
| return m ? m[1].trim() : "" | ||
| } | ||
| const descriptionOf = (html) => { | ||
| const m = html.match(/<meta\b[^>]*name="description"[^>]*content="([^"]*)"[^>]*>/i) | ||
| return m ? m[1] : "" | ||
| } | ||
| const canonicalOf = (html) => { | ||
| const m = html.match(/<link\s+rel="canonical"\s+href="([^"]*)">/i) | ||
| return m ? m[1] : "" | ||
| } | ||
| const jsonLdBlocksOf = (html) => | ||
| [...html.matchAll(/<script\s+type="application\/ld\+json"[^>]*>([\s\S]*?)<\/script>/gi)].map( | ||
| (m) => m[1] | ||
| ) | ||
|
|
||
| console.log("test-public-structured-data: JSON-LD structured data on public pages") | ||
|
|
||
| for (const { file, pageType, label } of PAGES) { | ||
| console.log(`A. ${file}`) | ||
| const html = read(file) | ||
| const blocks = jsonLdBlocksOf(html) | ||
|
|
||
| ok(blocks.length === 1, `${label} has exactly one application/ld+json block`) | ||
| if (blocks.length !== 1) continue | ||
|
|
||
| let graph | ||
| try { | ||
| graph = JSON.parse(blocks[0]) | ||
| ok(true, `${label} JSON-LD block parses as valid JSON`) | ||
| } catch (err) { | ||
| ok(false, `${label} JSON-LD block parses as valid JSON (${err.message})`) | ||
| continue | ||
| } | ||
|
|
||
| ok(graph["@context"] === "https://schema.org", `${label} uses the schema.org context`) | ||
| ok(Array.isArray(graph["@graph"]), `${label} JSON-LD uses an @graph array`) | ||
|
|
||
| const canonical = canonicalOf(html) | ||
| const title = titleOf(html) | ||
| const description = descriptionOf(html) | ||
| ok(canonical.length > 0, `${label} page declares a canonical URL`) | ||
| ok(title.length > 0, `${label} page declares a title`) | ||
| ok(description.length > 0, `${label} page declares a description`) | ||
|
|
||
| const org = (graph["@graph"] || []).find( | ||
| (node) => node["@type"] === "Organization" && node["@id"] === ORG_ID | ||
| ) | ||
| ok( | ||
| org && org.name === ORG_NAME && org.url === "https://tinystudio.in/", | ||
| `${label} JSON-LD carries the stable Tiny Studio organization reference` | ||
| ) | ||
|
|
||
| const page = (graph["@graph"] || []).find((node) => node["@type"] === pageType) | ||
| ok(page !== undefined, `${label} JSON-LD declares the page as ${pageType}`) | ||
| if (!page) continue | ||
|
|
||
| ok(page.url === canonical, `${label} JSON-LD url matches the page canonical URL`) | ||
| ok(page.name === title, `${label} JSON-LD name matches the page title`) | ||
| ok(page.description === description, `${label} JSON-LD description matches the meta description`) | ||
| ok( | ||
| page["isPartOf"] && page["isPartOf"]["@id"] === "https://tinystudio.in/#website", | ||
| `${label} JSON-LD page is part of the Tiny Studio website` | ||
| ) | ||
| ok( | ||
| page["about"] && page["about"]["@id"] === ORG_ID, | ||
| `${label} JSON-LD page is about the Tiny Studio organization` | ||
| ) | ||
| } | ||
|
|
||
| console.log("B. npm test/ci wiring") | ||
| const pkg = JSON.parse(read("package.json")) | ||
| const wired = pkg.scripts.test.includes("test-public-structured-data.mjs") | ||
| ok(wired, "npm test runs the public structured data test") | ||
| ok( | ||
| pkg.scripts.check === "npm test", | ||
| "npm run check delegates to npm test" | ||
| ) | ||
| ok( | ||
| pkg.scripts.ci.includes("test-public-structured-data.mjs"), | ||
| "npm run ci runs the public structured data test" | ||
| ) | ||
|
|
||
| console.log(`\n${checks} checks, ${failures} failures`) | ||
| process.exit(failures === 0 ? 0 : 1) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consumers that traverse this graph,
aboutidentifies Tiny Studio itself as the subject of an explicitly app-specific Promptly policy, even though the existing product schema defines the relevant entity ashttps://tinystudio.in/promptly/#app. Pointaboutat that app entity and represent Tiny Studio as the publisher instead; otherwise the new metadata misclassifies the policy, and the assertion atscripts/test-public-structured-data.mjs:100-103locks in that mismatch.Useful? React with 👍 / 👎.