head

package
v4.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 5 Imported by: 0

README

GWC | Head Library

GoWebComponents (GWC)

High-Level Overview

The head library manages document head metadata integration used by GWC renderers and routing flows.

Public APIs

github.com/monstercameron/GoWebComponents/head (package head)
  • Functions: AlternateLinks, Compose, Hreflang, LinkRel, Merge, MetaName, MetaProperty, OpenGraph, Render, RenderJSONLD, RenderToString, Resolve, ResourceHints, Robots, SocialTags, Twitter
  • Types: AlternateLink, Document, JSONLDBlock, MergeOptions, ResourceHint, RouteLayer, SocialMetadata
  • Variables: none
  • Constants: none

Subfiles And Purpose

  • doc.go - Package-level Go documentation
  • head.go - Core implementation for head
  • head_additional_test.go - Tests for head_additional behavior
  • head_test.go - Tests for head behavior

File Map

head/
|-- doc.go
|-- head.go
|-- head_additional_test.go
\-- head_test.go

Documentation

Overview

Package head provides optional SSR head-management helpers built on the public html, router, and ui packages.

Core router metadata remains the source of truth for title, description, and canonical URL. This companion package layers a higher-level SSR composition surface on top of that managed slice for robots tags, social tags, alternate locale links, resource hints, JSON-LD, and other explicit head markup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlternateLinks(parseLinks ...AlternateLink) ui.Node

AlternateLinks renders alternate and hreflang link tags.

func Compose

func Compose(parseMetadata router.Metadata, parseExtras ...ui.Node) ui.Node

Compose combines router-managed metadata with optional explicit head tags.

func Hreflang

func Hreflang(parseHrefLang, parseHref string) ui.Node

Hreflang renders an alternate locale link tag.

func LinkRel

func LinkRel(parseRel, parseHref string) ui.Node

LinkRel renders a link tag for a relationship and target URL.

func MetaName

func MetaName(parseName, parseContent string) ui.Node

MetaName renders a meta tag with a name-based attribute.

func MetaProperty

func MetaProperty(parseProperty, parseContent string) ui.Node

MetaProperty renders a meta tag with a property-based attribute.

func OpenGraph

func OpenGraph(parseField, parseContent string) ui.Node

OpenGraph renders an Open Graph meta tag for the given field.

func RenderJSONLD

func RenderJSONLD(parseValue any, parseScriptID string) (string, error)

RenderJSONLD renders one JSON-LD script block for direct insertion into SSR head markup.

func RenderToString

func RenderToString(parseDocument Document) (string, error)

RenderToString emits a full SSR head fragment using router-managed metadata plus companion-owned helpers.

func ResourceHints

func ResourceHints(parseHints ...ResourceHint) ui.Node

ResourceHints renders a bundle of explicit resource hint link tags.

func Robots

func Robots(parseContent string) ui.Node

Robots renders a robots meta tag.

func SocialTags

func SocialTags(parseMetadata SocialMetadata) ui.Node

SocialTags renders a small common set of Open Graph and Twitter card tags.

func Twitter

func Twitter(parseField, parseContent string) ui.Node

Twitter renders a Twitter/X card meta tag for the given field.

func UseHead

func UseHead(parseDoc Document)

UseHead is a no-op on native/SSR builds: there is no live document to mutate. Server-side head output is produced by RenderToString. The wasm build (use_head_wasm.go) applies the Document to the live document head on the client.

Types

type AlternateLink struct {
	Href     string
	HrefLang string
	Media    string
	Type     string
	Title    string
}

AlternateLink describes one alternate route or locale URL.

type Document

type Document struct {
	Metadata      router.Metadata
	Robots        string
	Social        SocialMetadata
	Alternates    []AlternateLink
	ResourceHints []ResourceHint
	JSONLD        []JSONLDBlock
	Extras        []ui.Node
}

Document describes a higher-level SSR head bundle layered on router metadata.

func Merge

func Merge(parseBase, parseOverride Document, parseOptions ...MergeOptions) Document

Merge combines a base head document with an override document.

func Resolve

func Resolve(parseLayers ...RouteLayer) Document

Resolve folds route layers from parent defaults to leaf overrides.

type JSONLDBlock

type JSONLDBlock struct {
	ID    string
	Value any
}

JSONLDBlock describes one JSON-LD script block.

type MergeOptions

type MergeOptions struct {
	ClearRobots          bool
	ClearSocial          bool
	ReplaceAlternates    bool
	ReplaceResourceHints bool
	ReplaceJSONLD        bool
	ReplaceExtras        bool
}

MergeOptions controls how non-router metadata is composed across route layers.

type ResourceHint

type ResourceHint struct {
	Rel         string
	Href        string
	As          string
	CrossOrigin string
	Type        string
	Media       string
}

ResourceHint describes one explicit resource hint link tag.

type RouteLayer

type RouteLayer struct {
	Document Document
	Merge    MergeOptions
}

RouteLayer describes one route-owned head contribution plus its merge behavior.

type SocialMetadata

type SocialMetadata struct {
	Type        string
	Title       string
	Description string
	ImageURL    string
	URL         string
	TwitterCard string
}

SocialMetadata describes common Open Graph and Twitter card metadata.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL