mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-13 12:27:30 -06:00
[feature] Allow user to choose "gallery" style web layout
This commit is contained in:
parent
d3c3d34aae
commit
7e689edbe3
82 changed files with 2840 additions and 1154 deletions
|
|
@ -76,6 +76,10 @@ func LoadTemplates(engine *gin.Engine) error {
|
|||
|
||||
// Set additional "include" functions to render
|
||||
// provided template name using the base template.
|
||||
|
||||
// Include renders the given template with the given data.
|
||||
// Unlike `template`, `include` can be chained with `indent`
|
||||
// to produce nicely-indented HTML.
|
||||
funcMap["include"] = func(name string, data any) (template.HTML, error) {
|
||||
var buf strings.Builder
|
||||
err := tmpl.ExecuteTemplate(&buf, name, data)
|
||||
|
|
@ -85,6 +89,25 @@ func LoadTemplates(engine *gin.Engine) error {
|
|||
return noescape(buf.String()), err
|
||||
}
|
||||
|
||||
// includeIndex is like `include` but an index can be specified at
|
||||
// `.Index` and data will be nested at `.Item`. Useful when ranging.
|
||||
funcMap["includeIndex"] = func(name string, data any, index int) (template.HTML, error) {
|
||||
var buf strings.Builder
|
||||
withIndex := struct {
|
||||
Item any
|
||||
Index int
|
||||
}{
|
||||
Item: data,
|
||||
Index: index,
|
||||
}
|
||||
err := tmpl.ExecuteTemplate(&buf, name, withIndex)
|
||||
|
||||
// Template was already escaped by
|
||||
// ExecuteTemplate so we can trust it.
|
||||
return noescape(buf.String()), err
|
||||
}
|
||||
|
||||
// includeAttr is like `include` but for element attributes.
|
||||
funcMap["includeAttr"] = func(name string, data any) (template.HTMLAttr, error) {
|
||||
var buf strings.Builder
|
||||
err := tmpl.ExecuteTemplate(&buf, name, data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue