Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Reference repeated graph entities by id, not duplicate nodes
In a structured-data graph (JSON-LD / schema.org), define a shared entity such as the Organization once and reference further occurrences by @id, instead of inlining a duplicate node each time. Derive the @id from one helper so the reference can never drift from the node it points at.
Bad example
| 1 | // every article inlines a full copy of the publisher |
| 2 | { publisher: buildOrganizationNode(config.publisher) } |
Explanation (EN)
Inlining the full Organization on every page duplicates the same entity across the document, bloating output and risking divergent copies.
Objašnjenje (HR)
Umetanje cijelog Organization cvora na svaku stranicu duplicira isti entitet kroz dokument, povecava izlaz i riskira razlicite kopije.
Good example
| 1 | const getOrganizationId = (baseUrl) => `${baseUrl}/#organization`; |
| 2 | // identity graph defines the node once; pages reference it: |
| 3 | { publisher: { '@id': getOrganizationId(baseUrl) } } |
Explanation (EN)
A single helper produces the @id used both by the node definition and by every reference, so they cannot drift apart.
Objašnjenje (HR)
Jedna pomocna funkcija proizvodi @id koji koriste i definicija cvora i svaka referenca, pa ne mogu razici.