Enrich shared pages with JSON-LD structured data#2912
Conversation
Introduces a `JSONLD` struct to dynamically inject `@context` and `@type` fields for rendering `<script type="application/ld+json">` tags on OpenGraph preview pages. - Adds `core/common/jsonld.go` with custom JSON marshaling logic. - Updates `OpenGraph` and `OpenGraphData` structs to support a `JSONLD` field. - Implements `JSONLDScript()` method to safely output the script tag. - Plumbs `WithJSONLD` option into all `handlers/*/shared_preview.go` components. - Updates `headdata.gohtml` and `openGraphPreview.gohtml` to render the script.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
| // Used by: share.Generate | ||
| type WithGeneratorType string | ||
|
|
||
| // WithJSONLD specifies the JSON-LD struct. |
There was a problem hiding this comment.
@jules it should be constructed from the same data or at the same data level as the other things, so each component will need to be made a with rather than the whole thing sorry.
There was a problem hiding this comment.
I've removed WithJSONLD and added separate component options like WithJSONLDType, WithHeadline, WithDatePublished, WithDateModified, WithAuthorName, WithAuthorURL, and WithImages.
| ModifiedTime *time.Time | ||
| SiteName string | ||
| UpdatedTime *time.Time | ||
| JSONLD interface{} |
There was a problem hiding this comment.
@jules this should be an interface or indicated through some sort of generic wrapper
There was a problem hiding this comment.
I've replaced interface{} with a new generic JSONLDer interface that defines LDType() string and MarshalJSONLD() ([]byte, error).
| ) | ||
|
|
||
| // JSONLD is a concrete struct for LD-JSON data. | ||
| type JSONLD struct { |
There was a problem hiding this comment.
@jules context and type should be implicit, and added during serialization and used to guide deserialization.
I am also expecting interfaces not any or interface{}
There was a problem hiding this comment.
I've refactored core/common/jsonld.go to use specific structs (like Article, BlogPosting) that implement the new JSONLDer interface. These specific structs implicitly provide their @type when serialized and we automatically inject the @context and @type during serialization via marshalWithContextAndType. I also updated deserialization to return an interface rather than parsing untyped generic maps.
|
@jules please ensure that every page that can provide the details are doing so |
1 similar comment
|
@jules please ensure that every page that can provide the details are doing so |
- Converted `JSONLD` from `interface{}` to a strongly-typed `JSONLDer` interface within OpenGraph data structures.
- Implemented `Article`, `NewsArticle`, `BlogPosting`, etc., to intrinsically provide their own `@type` through the `LDType()` method.
- Replaced the single `WithJSONLD` wrapper with multiple component-level generator options (`WithJSONLDType`, `WithHeadline`, `WithDatePublished`, `WithAuthorName`, `WithAuthorURL`, etc.) across `handlers/share/options.go`.
- Restructured `handlers/*/shared_preview.go` to construct structured data iteratively from parameters.
- Implemented robust internal `marshalWithContextAndType` helper to guarantee `@context` and `@type` inclusion during struct serialization.
There was a problem hiding this comment.
@jules WithAuhtor and WithAuthorName look like the same element, can we merge as many of these as possible. We can use sanity checks like "jsonld requires these 2 proprites to be populated" to sort out issues. There are others which are sssentially the same thing, what about 'headline' and 'title'?
There was a problem hiding this comment.
I have consolidated the options by removing WithHeadline and WithAuthorName, standardizing on WithTitle and WithAuthor across the options. The JSON-LD schema builder automatically maps the generic title variable into the Headline structure where needed.
I've gone through the various handler preview packages ( |
All the individual page handlers have been updated to provide fully populated JSONLD fields. |
…w data - Removed redundant `WithHeadline` and `WithAuthorName` options, standardizing on `WithTitle` and `WithAuthor` for both the image generator and the JSON-LD payload. - Enhanced all discrete content handler preview pages (`blogs/`, `news/`, `writings/`, `forum/`, `privateforum/`) to accurately parse and pass structural metrics like publish date, update date, and author attribution to the underlying structured data renderer.
This pull request enriches shared pages (e.g., forum threads, blog posts, news posts) by including JSON-LD structured data.
Features
JSONLDstruct incore/common/jsonld.gowith customMarshalJSONandUnmarshalJSONto automatically inject@context(defaulting to schema.org) and switch schemas based on the@typeproperty.core/common.OpenGraphandhandlers/share.OpenGraphDatatypes to include aJSONLD interface{}field.JSONLDScript() template.HTMLhelpers to safely generate the script tags without manual HTML composition.handlers/share/options.gowith a newWithJSONLDstruct to cleanly pipe structured data into shared previews.shared_preview.gohandlers across the codebase (Forum, Private Forum, Blogs, News, Writings) to support accepting and applying theWithJSONLDoption.{{.JSONLDScript}}invocation directly into the coreheaddata.gohtmlandopenGraphPreview.gohtmltemplates for seamless frontend rendering.PR created automatically by Jules for task 598031918209571218 started by @arran4