teseo: templ components for SEO #906
indaco
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
It looks great! I think you could probably strip a layer or two out to save some allocations: For example, where you have: // ToJsonLd converts the WebPage struct to a JSON-LD `templ.Component`.
func (wp *WebPage) ToJsonLd() templ.Component {
wp.ensureDefaults()
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
id := fmt.Sprintf("%s-%s", "webpage", teseo.GenerateUniqueKey())
return templ.JSONScript(id, wp).WithType("application/ld+json").Render(ctx, w)
})
} You could have: // ToJsonLd converts the WebPage struct to a JSON-LD `templ.Component`.
func (wp *WebPage) ToJsonLd() templ.Component {
wp.ensureDefaults()
id := fmt.Sprintf("%s-%s", "webpage", teseo.GenerateUniqueKey())
return templ.JSONScript(id, wp).WithType("application/ld+json")
} If you're sure that func (wp *WebPage) Render(ctx context.Context, w io.Writer) error {
wp.ensureDefaults()
id := fmt.Sprintf("%s-%s", "webpage", teseo.GenerateUniqueKey())
return templ.JSONScript(id, wp).WithType("application/ld+json").Render(ctx, w)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
teseo
provides a comprehensive list of SEO-related data types that adhere to Schema.org JSON-LD, OpenGraph and TwitterCard specifications, with methods to easily generatetempl
components or standardtemplate/html
output from them.The repo is here - https://github.com/indaco/teseo
I would greatly appreciate if someone could test it and share feedbacks and any issues you encounter.
Hope someone will find it useful.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions