Skip to content

Commit

Permalink
formattable ctx page methods
Browse files Browse the repository at this point in the history
  • Loading branch information
maxence-charriere committed May 23, 2024
1 parent 96d424e commit 6c4a48c
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions pkg/app/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Page interface {
Title() string

// Sets the page title.
SetTitle(v string)
SetTitle(format string, v ...any)

// Returns the page language.
Lang() string
Expand All @@ -23,13 +23,13 @@ type Page interface {
Description() string

// Sets the page description.
SetDescription(v string)
SetDescription(format string, v ...any)

// Returns the page author.
Author() string

// Sets the page author.
SetAuthor(v string)
SetAuthor(format string, v ...any)

// Returns the page keywords.
Keywords() string
Expand All @@ -44,7 +44,7 @@ type Page interface {
SetPreloads(v ...Preload)

// Set the page loading label.
SetLoadingLabel(v string)
SetLoadingLabel(format string, v ...any)

// Returns the image used by social networks when linking the page.
Image() string
Expand Down Expand Up @@ -95,8 +95,8 @@ func (p *requestPage) Title() string {
return p.title
}

func (p *requestPage) SetTitle(v string) {
p.title = v
func (p *requestPage) SetTitle(format string, v ...any) {
p.title = FormatString(format, v...)
}

func (p *requestPage) Lang() string {
Expand All @@ -111,16 +111,16 @@ func (p *requestPage) Description() string {
return p.description
}

func (p *requestPage) SetDescription(v string) {
p.description = v
func (p *requestPage) SetDescription(format string, v ...any) {
p.description = FormatString(format, v...)
}

func (p *requestPage) Author() string {
return p.author
}

func (p *requestPage) SetAuthor(v string) {
p.author = v
func (p *requestPage) SetAuthor(format string, v ...any) {
p.author = FormatString(format, v...)
}

func (p *requestPage) Keywords() string {
Expand All @@ -142,8 +142,8 @@ func (p *requestPage) SetPreloads(v ...Preload) {
p.preloads = v
}

func (p *requestPage) SetLoadingLabel(v string) {
p.loadingLabel = v
func (p *requestPage) SetLoadingLabel(format string, v ...any) {
p.loadingLabel = FormatString(format, v...)
}

func (p *requestPage) Image() string {
Expand Down Expand Up @@ -188,9 +188,10 @@ func (p browserPage) Title() string {
String()
}

func (p browserPage) SetTitle(v string) {
Window().Get("document").Set("title", v)
p.metaByProperty("og:title").setAttr("content", v)
func (p browserPage) SetTitle(format string, v ...any) {
title := FormatString(format, v...)
Window().Get("document").Set("title", title)
p.metaByProperty("og:title").setAttr("content", title)
}

func (p browserPage) Lang() string {
Expand All @@ -212,17 +213,18 @@ func (p browserPage) Description() string {
return p.metaByName("description").getAttr("content")
}

func (p browserPage) SetDescription(v string) {
p.metaByName("description").setAttr("content", v)
p.metaByProperty("og:description").setAttr("content", v)
func (p browserPage) SetDescription(format string, v ...any) {
description := FormatString(format, v...)
p.metaByName("description").setAttr("content", description)
p.metaByProperty("og:description").setAttr("content", description)
}

func (p browserPage) Author() string {
return p.metaByName("author").getAttr("content")
}

func (p browserPage) SetAuthor(v string) {
p.metaByName("author").setAttr("content", v)
func (p browserPage) SetAuthor(format string, v ...any) {
p.metaByName("author").setAttr("content", FormatString(format, v...))
}

func (p browserPage) Keywords() string {
Expand All @@ -233,7 +235,7 @@ func (p browserPage) SetKeywords(v ...string) {
p.metaByName("keywords").setAttr("content", strings.Join(v, ", "))
}

func (p browserPage) SetLoadingLabel(v string) {
func (p browserPage) SetLoadingLabel(format string, v ...any) {
}

func (p browserPage) Preloads() []Preload {
Expand Down

0 comments on commit 6c4a48c

Please sign in to comment.