twittercard

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 5 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WriteMetaTag = teseo.WriteMetaTag

Functions

This section is empty.

Types

type TwitterCard

type TwitterCard struct {
	Card        TwitterCardType // Card type, e.g., "summary", "summary_large_image", "app", "player"
	Title       string          // Title of the content
	Description string          // Description of the content
	Image       string          // URL to a thumbnail image to be used in the card
	Site        string          // Twitter username of the website or the content creator
	Creator     string          // Twitter username of the content creator
	AppID       string          // App ID (used in app cards)
	PlayerURL   string          // URL of the player (used in player cards)
}

TwitterCard contains information for generating Twitter Card meta tags. For more details about the meaning of the properties see: https://developer.x.com/en/docs/x-for-websites/cards/overview/markup

Example usage:

Pure struct usage:

twitterCard := &twittercard.TwitterCard{
	Card:        twittercard.CardSummary,
	Title:       "Example Title",
	Description: "This is an example Twitter Card description.",
	Image:       "https://www.example.com/image.jpg",
	Site:        "@example_site",
	Creator:     "@example_creator",
}

Factory method usage:

twitterCard := twittercard.NewCard(
	twittercard.CardSummary,
	"Example Title",
	"This is an example Twitter Card description.",
	"https://www.example.com/image.jpg",
	"@example_site",
	"@example_creator",
)

// Generate the HTML meta tags
templ Page() {
	@twitterCard.ToJsonLd()
})

Expected output:

<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Example Title">
<meta name="twitter:description" content="This is an example Twitter Card description.">
<meta name="twitter:image" content="https://www.example.com/image.jpg">
<meta name="twitter:site" content="@example_site">
<meta name="twitter:creator" content="@example_creator">

func NewAppCard

func NewAppCard(title string, description string, image string, site string, appID string) *TwitterCard

AppCard represents a Twitter App Card.

Example usage:

Pure struct usage:

appCard := &twittercard.TwitterCard{
	Card:        twittercard.CardApp,
	Title:       "Example App",
	Description: "This is an example app card.",
	Image:       "https://www.example.com/app.jpg",
	Site:        "@example_site",
	AppID:       "1234567890",
}

Factory method usage:

appCard := twittercard.NewAppCard(
	"Example App",
	"This is an example app card.",
	"https://www.example.com/app.jpg",
	"@example_site",
	"1234567890",
)

// Generate the HTML meta tags
templ Page() {
	@appCard.ToJsonLd()
})

Expected output:

<meta name="twitter:card" content="app">
<meta name="twitter:title" content="Example App">
<meta name="twitter:description" content="This is an example app card.">
<meta name="twitter:image" content="https://www.example.com/app.jpg">
<meta name="twitter:site" content="@example_site">
<meta name="twitter:app:id:iphone" content="1234567890">

func NewCard

func NewCard(cardType TwitterCardType, title string, description string, image string, site string, creator string) *TwitterCard

NewCard initializes a TwitterCard based on the provided type.

func NewPlayerCard

func NewPlayerCard(title string, description string, image string, site string, playerURL string) *TwitterCard

PlayerCard represents a Twitter Player Card.

Example usage:

Pure struct usage:

playerCard := &twittercard.TwitterCard{
	Card:        twittercard.CardPlayer,
	Title:       "Example Player",
	Description: "This is an example player card.",
	Image:       "https://www.example.com/player.jpg",
	Site:        "@example_site",
	PlayerURL:   "https://www.example.com/player",
}

Factory method usage:

playerCard := twittercard.NewPlayerCard(
	"Example Player",
	"This is an example player card.",
	"https://www.example.com/player.jpg",
	"@example_site",
	"https://www.example.com/player",
)

// Generate the HTML meta tags
templ Page() {
	@playerCard.ToMetaTags()
})

Expected output:

<meta name="twitter:card" content="player">
<meta name="twitter:title" content="Example Player">
<meta name="twitter:description" content="This is an example player card.">
<meta name="twitter:image" content="https://www.example.com/player.jpg">
<meta name="twitter:site" content="@example_site">
<meta name="twitter:player" content="https://www.example.com/player">

func NewSummaryCard

func NewSummaryCard(title string, description string, image string, site string, creator string) *TwitterCard

SummaryCard represents a Twitter Card of type summary.

Example usage:

Pure struct usage:

summaryCard := &twittercard.TwitterCard{
	Card:        twittercard.CardSummary,
	Title:       "Example Summary",
	Description: "This is an example summary card.",
	Image:       "https://www.example.com/summary.jpg",
	Site:        "@example_site",
	Creator:     "@example_creator",
}

Factory method usage:

summaryCard := twittercard.NewSummaryCard(
	"Example Summary",
	"This is an example summary card.",
	"https://www.example.com/summary.jpg",
	"@example_site",
	"@example_creator",
)

// Generate the HTML meta tags
templ Page() {
	@twitterCard.ToJsonLd()
})

Expected output:

<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Example Summary">
<meta name="twitter:description" content="This is an example summary card.">
<meta name="twitter:image" content="https://www.example.com/summary.jpg">
<meta name="twitter:site" content="@example_site">
<meta name="twitter:creator" content="@example_creator">

func NewSummaryLargeImageCard

func NewSummaryLargeImageCard(title string, description string, image string, site string, creator string) *TwitterCard

SummaryLargeImageCard represents a Twitter Card of type summary_large_image.

Example usage:

Pure struct usage:

summaryLargeImageCard := &twittercard.TwitterCard{
	Card:        twittercard.CardSummaryLargeImage,
	Title:       "Example Summary Large Image",
	Description: "This is an example large image summary card.",
	Image:       "https://www.example.com/large_image.jpg",
	Site:        "@example_site",
	Creator:     "@example_creator",
}

Factory method usage:

summaryLargeImageCard := twittercard.NewSummaryLargeImageCard(
	"Example Summary Large Image",
	"This is an example large image summary card.",
	"https://www.example.com/large_image.jpg",
	"@example_site",
	"@example_creator",
)

// Generate the HTML meta tags
templ Page() {
	@summaryLargeImageCard.ToJsonLd()
})

Expected output:

<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Example Summary Large Image">
<meta name="twitter:description" content="This is an example large image summary card.">
<meta name="twitter:image" content="https://www.example.com/large_image.jpg">
<meta name="twitter:site" content="@example_site">
<meta name="twitter:creator" content="@example_creator">

func (*TwitterCard) ToGoHTMLMetaTags

func (tc *TwitterCard) ToGoHTMLMetaTags() (template.HTML, error)

ToGoHTMLMetaTags generates the HTML meta tags for the Twitter Card as `template.HTML` value for Go's html/template

func (*TwitterCard) ToMetaTags

func (tc *TwitterCard) ToMetaTags() templ.Component

ToMetaTags generates the HTML meta tags for the Twitter Card using templ.Component

type TwitterCardType

type TwitterCardType string

TwitterCardType represents the type of Twitter Card.

const (
	CardSummary           TwitterCardType = "summary"
	CardSummaryLargeImage TwitterCardType = "summary_large_image"
	CardApp               TwitterCardType = "app"
	CardPlayer            TwitterCardType = "player"
)

func (TwitterCardType) String

func (tc TwitterCardType) String() string

Jump to

Keyboard shortcuts

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