Add comprehensive SEO and OpenGraph meta tags to shared layout templates#2909
Conversation
- Adds title, description, canonical link, and favicon variations to `headdata.gohtml` and `openGraphPreview.gohtml`. - Updates `OpenGraph` and `OpenGraphData` structs to include fields for expiration, publish, modification timestamps, as well as site name and updated time. - Implements receiver methods to safely format and output these values as HTML meta tags using the required layout.
|
👋 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. |
| if og.SiteName == "" { | ||
| return "" | ||
| } | ||
| return template.HTML(fmt.Sprintf(`<meta property="og:site_name" content="%s" />`, og.SiteName)) |
There was a problem hiding this comment.
@jules don't we need to escape this? (and other ones too.)
There was a problem hiding this comment.
Good catch. I've wrapped the string values in html.EscapeString for these and the other newly added meta tag methods.
| <meta property="og:description" content="{{ .Description }}" /> | ||
| {{.ImageMeta}} | ||
| {{.ImageMeta}} | ||
| {{.SecureImageMeta}} |
There was a problem hiding this comment.
Fixed the indentation in headdata.gohtml to use spaces properly like the surrounding lines.
| if d.SiteName == "" { | ||
| return "" | ||
| } | ||
| return template.HTML(fmt.Sprintf(`<meta property="og:site_name" content="%s" />`, d.SiteName)) |
There was a problem hiding this comment.
@jules we should escape this and others, plus isn't this redundant with the other module in common?
There was a problem hiding this comment.
I've applied html.EscapeString to these methods as well. Regarding the redundancy with common.OpenGraph: yes, it is definitely redundant, but OpenGraphData uses template.URL specifically for ImageURL and ContentURL, which are directly relied upon by openGraphPreview.gohtml. Rather than embedding and potentially breaking templates/signatures across the modules (blogs, forum, news, writings) that initialize OpenGraphData, I've just matched the escaping fixes here. If you prefer, we can tackle completely merging them in a follow-up refactoring PR!
|
@jules let's add: Too (with appopriate optionality, ie index, follow, we have private pages.) Can we also get Also can we ensure we have |
- Apply `html.EscapeString` to strings output in OpenGraph template helpers in both `core/common/opengraph_methods.go` and `handlers/share/opengraph.go` to prevent potential HTML injection. - Fix mixed tabs/spaces indentation in `core/templates/site/headdata.gohtml` for proper spacing.
There was a problem hiding this comment.
Yes, sorry about that! I used plan2.md as a scratchpad while investigating and it accidentally got committed. I have removed it from the PR now.
There was a problem hiding this comment.
@jules you may remove plan2.md if it's no longer needed.
There was a problem hiding this comment.
@jules you may remove plan2.md if it's no longer needed.
There was a problem hiding this comment.
Removed plan2.md as requested!
Removes `plan2.md` that was accidentally included in the previous commit.
|
@jules please ensure new additions such as publish date are integrated into the code base such as in to writings and updated into forum |
I've gone through and ensured these are populated properly across the codebase where the timestamps are available. For Additionally, I've populated |
- Maps `writing.Published` to `PublishedTime` in writings handlers. - Maps `thread.Lastaddition` to `UpdatedTime` and `ModifiedTime` in forum thread handlers. - Maps `blog.Written` to `PublishedTime` in blog handlers. - Maps `post.Occurred` to `PublishedTime` in news handlers. - Injects `SiteName` into `OpenGraph` data where available (faq, privateforum, writings, news, etc).
Removes accidentally committed scratchpad file.
Ensure proper meta tags are included on as many pages as possible. This includes canonical links, apple-touch-icon, OpenGraph article modified, published and expiry times.
PR created automatically by Jules for task 5813150266798798193 started by @arran4