From 6c4a48cd32a828440777b0b513004a5c3f5bb3a4 Mon Sep 17 00:00:00 2001 From: Maxence Charriere Date: Thu, 23 May 2024 15:46:08 +0800 Subject: [PATCH] formattable ctx page methods --- pkg/app/page.go | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/pkg/app/page.go b/pkg/app/page.go index 901b5fe7..a322598f 100644 --- a/pkg/app/page.go +++ b/pkg/app/page.go @@ -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 @@ -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 @@ -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 @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 {