Add support for custom footer
This commit is contained in:
parent
9f3e7a7b86
commit
a292c25f84
7 changed files with 60 additions and 3 deletions
22
internal/dis/component/control/static/custom/assets.go
Normal file
22
internal/dis/component/control/static/custom/assets.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package custom
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
)
|
||||
|
||||
// CustomAssetsPath is the path custom assets are stored at
|
||||
func (custom *Custom) CustomAssetsPath() string {
|
||||
return filepath.Join(custom.Config.DeployRoot, "core", "assets")
|
||||
}
|
||||
|
||||
func (custom *Custom) FooterPath() string {
|
||||
return filepath.Join(custom.CustomAssetsPath(), "footer.html")
|
||||
}
|
||||
|
||||
func (custom *Custom) BackupName() string { return "custom" }
|
||||
|
||||
func (custom *Custom) Backup(context component.StagingContext) error {
|
||||
return context.CopyDirectory("", custom.CustomAssetsPath())
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package custom
|
||||
|
||||
import "github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
import (
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
)
|
||||
|
||||
// Custom implements theme and page customization.
|
||||
type Custom struct {
|
||||
|
|
@ -9,3 +11,7 @@ type Custom struct {
|
|||
// nothing yet
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
_ component.Backupable = (*Custom)(nil)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package custom
|
|||
import (
|
||||
_ "embed"
|
||||
"html/template"
|
||||
"text/template/parse"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
const footerName = "footer"
|
||||
|
|
@ -14,9 +17,26 @@ var defaultTemplate = template.Must(template.New("footer.html").Parse(defaultTem
|
|||
// Template creates a copy of template with shared template parts updated accordingly.
|
||||
// Any template using this should use one of the template contexts in this package.
|
||||
func (custom *Custom) Template(tpl *template.Template) *template.Template {
|
||||
tree := defaultTemplate.Tree.Copy()
|
||||
tree := custom.footerTemplate()
|
||||
|
||||
clone := template.Must(tpl.Clone()) // create a clone of the template
|
||||
template.Must(clone.AddParseTree(footerName, tree)) // add the parse tree to it
|
||||
return clone // and return the tree
|
||||
}
|
||||
|
||||
// footerTemplate returns a new copy of the footer template
|
||||
func (custom *Custom) footerTemplate() *parse.Tree {
|
||||
footer, err := (func() (*template.Template, error) {
|
||||
data, err := environment.ReadFile(custom.Environment, custom.FooterPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return template.New("footer.html").Parse(string(data))
|
||||
})()
|
||||
|
||||
if err != nil {
|
||||
return defaultTemplate.Tree.Copy()
|
||||
}
|
||||
|
||||
return footer.Tree
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue