Add support for custom footer
This commit is contained in:
parent
9f3e7a7b86
commit
a292c25f84
7 changed files with 60 additions and 3 deletions
|
|
@ -72,6 +72,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
||||||
dis.Instances().Path(),
|
dis.Instances().Path(),
|
||||||
dis.Exporter().StagingPath(),
|
dis.Exporter().StagingPath(),
|
||||||
dis.Exporter().ArchivePath(),
|
dis.Exporter().ArchivePath(),
|
||||||
|
dis.Custom().CustomAssetsPath(),
|
||||||
} {
|
} {
|
||||||
context.Println(d)
|
context.Println(d)
|
||||||
if err := dis.Still.Environment.MkdirAll(d, environment.DefaultDirPerm); err != nil {
|
if err := dis.Still.Environment.MkdirAll(d, environment.DefaultDirPerm); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,5 @@ SELF_RESOLVER_BLOCK_FILE=${SELF_RESOLVER_BLOCK_FILE}
|
||||||
|
|
||||||
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
||||||
HTTPS_ENABLED=${HTTPS_ENABLED}
|
HTTPS_ENABLED=${HTTPS_ENABLED}
|
||||||
|
|
||||||
|
CUSTOM_ASSETS_PATH=${CUSTOM_ASSETS_PATH}
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
|
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||||
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static/custom"
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -18,6 +19,8 @@ type Control struct {
|
||||||
Dependencies struct {
|
Dependencies struct {
|
||||||
Routeables []component.Routeable
|
Routeables []component.Routeable
|
||||||
Cronables []component.Cronable
|
Cronables []component.Cronable
|
||||||
|
|
||||||
|
Custom *custom.Custom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,6 +52,8 @@ func (control *Control) Stack(env environment.Environment) component.StackWithRe
|
||||||
"GLOBAL_AUTHORIZED_KEYS_FILE": control.Config.GlobalAuthorizedKeysFile,
|
"GLOBAL_AUTHORIZED_KEYS_FILE": control.Config.GlobalAuthorizedKeysFile,
|
||||||
"SELF_OVERRIDES_FILE": control.Config.SelfOverridesFile,
|
"SELF_OVERRIDES_FILE": control.Config.SelfOverridesFile,
|
||||||
"SELF_RESOLVER_BLOCK_FILE": control.Config.SelfResolverBlockFile,
|
"SELF_RESOLVER_BLOCK_FILE": control.Config.SelfResolverBlockFile,
|
||||||
|
|
||||||
|
"CUSTOM_ASSETS_PATH": control.Dependencies.Custom.CustomAssetsPath(),
|
||||||
},
|
},
|
||||||
|
|
||||||
CopyContextFiles: []string{bootstrap.Executable},
|
CopyContextFiles: []string{bootstrap.Executable},
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ services:
|
||||||
- "${GLOBAL_AUTHORIZED_KEYS_FILE}:${GLOBAL_AUTHORIZED_KEYS_FILE}:ro"
|
- "${GLOBAL_AUTHORIZED_KEYS_FILE}:${GLOBAL_AUTHORIZED_KEYS_FILE}:ro"
|
||||||
- "${SELF_OVERRIDES_FILE}:${SELF_OVERRIDES_FILE}:ro"
|
- "${SELF_OVERRIDES_FILE}:${SELF_OVERRIDES_FILE}:ro"
|
||||||
- "${SELF_RESOLVER_BLOCK_FILE}:${SELF_RESOLVER_BLOCK_FILE}:ro"
|
- "${SELF_RESOLVER_BLOCK_FILE}:${SELF_RESOLVER_BLOCK_FILE}:ro"
|
||||||
|
- "${CUSTOM_ASSETS_PATH}:${CUSTOM_ASSETS_PATH}:ro"
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
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
|
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.
|
// Custom implements theme and page customization.
|
||||||
type Custom struct {
|
type Custom struct {
|
||||||
|
|
@ -9,3 +11,7 @@ type Custom struct {
|
||||||
// nothing yet
|
// nothing yet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ component.Backupable = (*Custom)(nil)
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ package custom
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"text/template/parse"
|
||||||
|
|
||||||
|
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||||
)
|
)
|
||||||
|
|
||||||
const footerName = "footer"
|
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.
|
// 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.
|
// Any template using this should use one of the template contexts in this package.
|
||||||
func (custom *Custom) Template(tpl *template.Template) *template.Template {
|
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
|
clone := template.Must(tpl.Clone()) // create a clone of the template
|
||||||
template.Must(clone.AddParseTree(footerName, tree)) // add the parse tree to it
|
template.Must(clone.AddParseTree(footerName, tree)) // add the parse tree to it
|
||||||
return clone // and return the tree
|
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