Web JSON Schema#386
Open
echen-adobe wants to merge 4 commits intostagefrom
Open
Conversation
|
fullcolorcoder
requested changes
Apr 27, 2026
| @@ -0,0 +1,47 @@ | |||
| function getMeta(name) { | |||
| return document.querySelector(`meta[name="${name}"]`)?.content; | |||
Contributor
There was a problem hiding this comment.
getMeta is doing exactly what getMetadata (and getCachedMetadata) in utils.js already does. Worth importing from there instead of maintaining a parallel implementation — getCachedMetadata would even give you a free memoization benefit for the repeated opt-in check.
| if (getMeta('web-app-schema') !== 'on') return; | ||
| if (document.getElementById('web-application-schema')) return; | ||
| injectWebApplicationSchema(); | ||
| } |
Contributor
There was a problem hiding this comment.
Tests
// test/scripts/utils/web-app-schema.test.js
import { injectWebApplicationSchema, loadWebApplicationSchema } from '../../../express/code/scripts/utils/web-app-schema.js';
describe('loadWebApplicationSchema', () => {
beforeEach(() => {
document.head.innerHTML = '';
document.body.innerHTML = '<main><h1>Test App</h1></main>';
});
it('does not inject when web-app-schema meta is absent', () => {
loadWebApplicationSchema();
expect(document.getElementById('web-application-schema')).to.be.null;
});
it('injects JSON-LD when web-app-schema meta is on', () => {
const meta = document.createElement('meta');
meta.name = 'web-app-schema';
meta.content = 'on';
document.head.appendChild(meta);
loadWebApplicationSchema();
const script = document.getElementById('web-application-schema');
expect(script).to.exist;
const json = JSON.parse(script.textContent);
expect(json['@type']).to.equal('WebApplication');
expect(json.name).to.equal('Test App');
});
it('does not inject a duplicate if script already exists', () => {
const meta = document.createElement('meta');
meta.name = 'web-app-schema';
meta.content = 'on';
document.head.appendChild(meta);
loadWebApplicationSchema();
loadWebApplicationSchema();
expect(document.querySelectorAll('#web-application-schema').length).to.equal(1);
});
});
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds WebApplication JSON-LD (
application/ld+json) for pages that opt in via metadata. The script runs from delayed load, injects a single<script id="web-application-schema">in<head>, and builds name from the main H1 (fallback:document.title), description from the meta description, url from the canonical link (fallback: current URL), and sensible defaults for category, OS, browser requirements, free Offer, and Adobe creator. Authors can tune optional fields (schema-application-category,schema-operating-system,schema-browser-requirements, offer-related metas) and must setweb-app-schematoonto enable injection. Duplicates are avoided if the script tag already exists.Jira Ticket
Resolves: MWPW-188099
Test URLs
Schema demo (branch): https://fqa-schema--da-express-milo--adobecom.aem.live/drafts/echen/schema-demo
Page with schema validation turned off https://fqa-schema--da-express-milo--adobecom.aem.live/express/
Verification Steps
web-app-schemametadata set toon(e.g. the schema demo draft above).<head>and confirm ascriptwithtype="application/ld+json"andid="web-application-schema"whose JSON has@type": "WebApplication"and the expected name, description, and url.Potential Regressions
loadDelayed).