Documentation
¶
Index ¶
- func BuildURL(baseURL, path string) string
- func ExtractImageURL(tiptapJSON string) string
- func ExtractImageURLFromHTML(htmlContent string) string
- func ExtractPlainText(tiptapJSON string) string
- func ExtractPlainTextFromHTML(htmlContent string) string
- func GetChangeFrequency(postType string) string
- func GetPriority(postType string) string
- func RenderAllSEOMetaTagsAsHTML(metaDescription string, og OpenGraphTags, tc TwitterCardTags) string
- func RenderMetaTags(tags []MetaTag) template.HTML
- func RenderSitemapXML(entries []SitemapEntry) []byte
- func TruncateText(text string, maxLength int) string
- type ArticleStructuredData
- type ContentItem
- type JSONLDContext
- type JSONLDType
- type MetaTag
- type OpenGraphTags
- type Person
- type SitemapAlternate
- type SitemapEntry
- type TipTapDocument
- type TipTapNode
- type TwitterCardTags
- type TwitterCardType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractImageURL ¶
ExtractImageURL finds the first image URL in TipTap JSON content
func ExtractImageURLFromHTML ¶ added in v0.6.0
ExtractImageURLFromHTML finds the first image URL in HTML content. It looks for <img> tags with src attributes pointing to http(s) URLs.
func ExtractPlainText ¶
ExtractPlainText extracts plain text from TipTap JSON content
func ExtractPlainTextFromHTML ¶ added in v0.6.0
ExtractPlainTextFromHTML strips HTML tags and returns plain text.
func GetChangeFrequency ¶
func GetPriority ¶
func RenderAllSEOMetaTagsAsHTML ¶
func RenderAllSEOMetaTagsAsHTML(metaDescription string, og OpenGraphTags, tc TwitterCardTags) string
RenderAllSEOMetaTagsAsHTML renders all SEO meta tags as HTML
func RenderMetaTags ¶
RenderMetaTags renders multiple meta tags as HTML
func RenderSitemapXML ¶ added in v0.2.0
func RenderSitemapXML(entries []SitemapEntry) []byte
RenderSitemapXML renders entries as a sitemaps.org XML <urlset> document. It is what GET /sitemap.xml serves to crawlers (the JSON shape from GetSitemapData is for programmatic callers; crawlers need XML). Each entry's Alternates render as <xhtml:link rel="alternate" hreflang=".." href=".."/> children so a multilingual site declares its language variants (hreflang). The XML declaration is prepended so the document starts with <?xml ...?>.
func TruncateText ¶
TruncateText truncates text to a maximum length, adding ellipsis if needed
Types ¶
type ArticleStructuredData ¶
type ArticleStructuredData struct {
Context JSONLDContext `json:"@context"`
Type JSONLDType `json:"@type"`
Headline string `json:"headline"`
Description string `json:"description"`
Image string `json:"image,omitempty"`
DatePublished string `json:"datePublished"`
DateModified string `json:"dateModified"`
Author *Person `json:"author"`
Keywords string `json:"keywords,omitempty"`
}
ArticleStructuredData represents Schema.org Article structured data
func DefaultArticleStructuredData ¶
func DefaultArticleStructuredData(title, description, authorName string) ArticleStructuredData
DefaultArticleStructuredData generates Article structured data with defaults
func GenerateArticleStructuredData ¶
func GenerateArticleStructuredData(title, description, image, datePublished, dateModified, authorName string, tags []string) ArticleStructuredData
GenerateArticleStructuredData generates Article structured data from content metadata
func (ArticleStructuredData) ToJSON ¶
func (a ArticleStructuredData) ToJSON() (string, error)
ToJSON converts the structured data to JSON string
func (ArticleStructuredData) ToJSONLDScript ¶
func (a ArticleStructuredData) ToJSONLDScript() (string, error)
ToJSONLDScript renders the structured data as a JSON-LD script tag
type ContentItem ¶
type JSONLDContext ¶
type JSONLDContext string
JSONLDContext represents the JSON-LD context
const ( // JSONLDContextSchemaOrg is the Schema.org context JSONLDContextSchemaOrg JSONLDContext = "https://schema.org" )
type JSONLDType ¶
type JSONLDType string
JSONLDType represents the JSON-LD type
const ( // JSONLDTypeArticle is the Article type JSONLDTypeArticle JSONLDType = "Article" // JSONLDTypeBlogPosting is the BlogPosting type JSONLDTypeBlogPosting JSONLDType = "BlogPosting" // JSONLDTypeNewsArticle is the NewsArticle type JSONLDTypeNewsArticle JSONLDType = "NewsArticle" )
type MetaTag ¶
type MetaTag struct {
Name string
Property string
Content string
// contains filtered or unexported fields
}
MetaTag represents an HTML meta tag
func NewMetaTag ¶
NewMetaTag creates a new meta tag with name attribute
func NewPropertyMetaTag ¶
NewPropertyMetaTag creates a new meta tag with property attribute
func RenderAllSEOMetaTags ¶
func RenderAllSEOMetaTags(metaDescription string, og OpenGraphTags, tc TwitterCardTags) []MetaTag
RenderAllSEOMetaTags renders all SEO meta tags (description, Open Graph, Twitter Card)
type OpenGraphTags ¶
type OpenGraphTags struct {
Title string
Description string
Image string
URL string
Type string
SiteName string
}
OpenGraphTags represents Open Graph meta tags
func DefaultOpenGraphTags ¶
func DefaultOpenGraphTags() OpenGraphTags
DefaultOpenGraphTags returns default Open Graph tags
func (OpenGraphTags) ToMetaTags ¶
func (og OpenGraphTags) ToMetaTags() []MetaTag
ToMetaTags converts Open Graph tags to meta tags
type Person ¶
type Person struct {
Type string `json:"@type"`
Name string `json:"name"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
}
Person represents a person in Schema.org
type SitemapAlternate ¶ added in v0.2.0
SitemapAlternate declares one language variant of a page: a language code (hreflang, e.g. "en", "id") and the absolute URL of that variant (href).
type SitemapEntry ¶
type SitemapEntry struct {
Loc string
LastMod string
ChangeFreq string
Priority string
// Alternates lists the page's other published language variants (and the page
// itself) for hreflang. Empty for pages with no translations.
Alternates []SitemapAlternate
}
func ContentToSitemapEntry ¶
func ContentToSitemapEntry(baseURL string, content ContentItem, postType string) SitemapEntry
ContentToSitemapEntry builds a single sitemap entry. Every public content item is served at the site root by its slug (/<slug>) — see ContentPageHandler.ServeHTTP's default case — so the loc is always baseURL/<slug> regardless of post type. postType is still used to pick the changefreq/priority (posts update more often than pages).
func NewHomepageEntry ¶
func NewHomepageEntry(baseURL string) SitemapEntry
type TipTapDocument ¶
type TipTapDocument struct {
Type string `json:"type"`
Content []TipTapNode `json:"content"`
}
TipTapDocument represents a TipTap JSON document
type TipTapNode ¶
type TipTapNode struct {
Type string `json:"type"`
Attrs map[string]any `json:"attrs,omitempty"`
Content []TipTapNode `json:"content,omitempty"`
Text string `json:"text,omitempty"`
}
TipTapNode represents a node in TipTap JSON
type TwitterCardTags ¶
type TwitterCardTags struct {
Card TwitterCardType
Title string
Description string
Image string
}
TwitterCardTags represents Twitter Card meta tags
func DefaultTwitterCardTags ¶
func DefaultTwitterCardTags() TwitterCardTags
DefaultTwitterCardTags returns default Twitter Card tags
func (TwitterCardTags) ToMetaTags ¶
func (tc TwitterCardTags) ToMetaTags() []MetaTag
ToMetaTags converts Twitter Card tags to meta tags
type TwitterCardType ¶
type TwitterCardType string
TwitterCardType represents Twitter card types
const ( // TwitterCardSummary is the summary card type TwitterCardSummary TwitterCardType = "summary" // TwitterCardSummaryLargeImage is the summary card with large image type TwitterCardSummaryLargeImage TwitterCardType = "summary_large_image" )