The src/main/addon/DocumentHead.mjs addon currently assumes only a single <script type="application/ld+json"> tag exists in the document's head. This is evident in the getLdJson and setLdJson methods, which use querySelector to find and manipulate the script tag.
As seen in apps/portal/index.html, we now have multiple ld+json schemas (e.g., for the framework itself, for AI-native features, and an FAQ page). The current implementation cannot distinguish between them, leading to incorrect reading and writing of structured data.
This ticket proposes enhancing the DocumentHead addon to properly handle multiple ld+json schemas while maintaining backward compatibility.
Proposed Changes:
The getLdJson and setLdJson methods need to be updated to allow selecting a specific schema, probably via a name or id.
For example, in apps/portal/index.html, we could add a data-schema-name attribute:
<script type="application/ld+json" data-schema-name="runtime-framework">
...
</script>
The addon methods would be updated:
getLdJson({name} = {}):
- If
name is provided, retrieves the JSON from the script with the matching data-schema-name.
- If
name is not provided, it finds the first application/ld+json script and returns its content (maintaining backward compatibility).
setLdJson({name, value}):
- If
name is provided, it updates or creates the script with the matching data-schema-name.
- If
name is not provided, it finds the first application/ld+json script and updates it, or creates a new one if none exists (maintaining backward compatibility).
The update method should also be adjusted to handle named schemas.
Acceptance Criteria:
DocumentHead can read a specific ld+json schema by a unique identifier.
DocumentHead can write to a specific ld+json schema by a unique identifier.
DocumentHead can create a new, uniquely identified ld+json schema.
- When no identifier is provided,
getLdJson and setLdJson default to the current behavior (find first or create).
apps/portal/index.html is updated with unique identifiers for each ld+json script.
The
src/main/addon/DocumentHead.mjsaddon currently assumes only a single<script type="application/ld+json">tag exists in the document's head. This is evident in thegetLdJsonandsetLdJsonmethods, which usequerySelectorto find and manipulate the script tag.As seen in
apps/portal/index.html, we now have multipleld+jsonschemas (e.g., for the framework itself, for AI-native features, and an FAQ page). The current implementation cannot distinguish between them, leading to incorrect reading and writing of structured data.This ticket proposes enhancing the
DocumentHeadaddon to properly handle multipleld+jsonschemas while maintaining backward compatibility.Proposed Changes:
The
getLdJsonandsetLdJsonmethods need to be updated to allow selecting a specific schema, probably via anameorid.For example, in
apps/portal/index.html, we could add adata-schema-nameattribute:<script type="application/ld+json" data-schema-name="runtime-framework"> ... </script>The addon methods would be updated:
getLdJson({name} = {}):nameis provided, retrieves the JSON from the script with the matchingdata-schema-name.nameis not provided, it finds the firstapplication/ld+jsonscript and returns its content (maintaining backward compatibility).setLdJson({name, value}):nameis provided, it updates or creates the script with the matchingdata-schema-name.nameis not provided, it finds the firstapplication/ld+jsonscript and updates it, or creates a new one if none exists (maintaining backward compatibility).The
updatemethod should also be adjusted to handle named schemas.Acceptance Criteria:
DocumentHeadcan read a specificld+jsonschema by a unique identifier.DocumentHeadcan write to a specificld+jsonschema by a unique identifier.DocumentHeadcan create a new, uniquely identifiedld+jsonschema.getLdJsonandsetLdJsondefault to the current behavior (find first or create).apps/portal/index.htmlis updated with unique identifiers for eachld+jsonscript.