Skip to content

Commit

Permalink
Custom Branding (TUM-Dev#665)
Browse files Browse the repository at this point in the history
* Update Dockerfile

Add copy of opptional branding folder for
- manifest.json
- favicon.ico
- logo.svg

* Update README.md & Add /branding-example

Add Customization to README.md
Add branding-example folder

* Add branding.go

Custom branding for titles, etc.
Add branding.yaml to /branding-example
Update templates

* Add additional branding.yaml locations

Copied from config.go for config.yaml

* Update README.md

Add branding.yaml information

* Update docker-compose.yml

Add branding to volumes

* Add custom description to branding.yaml

* Add comments to functions

* Remove copying of branding

* Rename branding-example to branding

* Update static router

Make static files more "dynamic"
Use embedded FS for favicon.ico
Include branding

* go mod tidy

* Update README.md

* Add missing bg-white
  • Loading branch information
MatthiasReumann authored Oct 17, 2022
1 parent ac3363f commit 3199521
Show file tree
Hide file tree
Showing 27 changed files with 256 additions and 138 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ To create database models and their corresponding daos there is a helper script
go run cmd/modelGen/modelGen.go <NameOfYourModel(UpperCamelCase)>
```

### Customization

An exemplary configuration can be found in `/branding`.

#### logo, favicon, manifest.json

For customization mount a directory containing the files in the docker container. Make sure to
specify the location of the directory in the container in the configuration file as `paths > branding`.
See `/config.yaml` for an exemplary configuration.

#### title, description
If intended, put a `branding.yaml` file at the same location as `config.yaml`.

## Credit & Licenses

- [Check out our dependencies](https://github.com/joschahenningsen/TUM-Live/network/dependencies)
2 changes: 2 additions & 0 deletions branding/branding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: MUT-Live
description: MUT-Live, non-existing live streaming, and VoD service
Binary file added branding/favicon.ico
Binary file not shown.
7 changes: 7 additions & 0 deletions branding/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions branding/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "MUT-Live",
"short_name": "MUT-Live",
"icons": [
{
"src": "/static/assets/img/icons-192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/static/assets/img/icons-512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": "/?source=pwa",
"background_color": "#161c22",
"display_override": ["window-control-overlay", "minimal-ui"],
"display": "standalone",
"scope": "/",
"theme_color": "#161c22",
"description": "MUT-Live, non-existing live streaming, and VoD service",
"screenshots": []
}
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ mail:
paths:
mass: /srv/ceph/live
static: /var/www/static
branding: /srv/ceph/branding
weburl: https://live.rbg.tum.de
workertoken: 2657575f-40e4-4278-9ca1-f3a5ed667cff
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
backend-network:
volumes:
- ./config.yaml:/etc/TUM-Live/config.yaml
- ./branding/branding.yaml:/etc/TUM-Live/branding.yaml
- type: volume
source: recordings
target: /recordings
Expand Down
48 changes: 48 additions & 0 deletions tools/branding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tools

import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

var BrandingCfg Branding

type Branding struct {
Title string `yaml:"title"`
Description string `yaml:"description"`
}

// getDefaultBranding returns the struct branding with default values
func getDefaultBranding() Branding {
return Branding{
Title: "TUM-Live",
Description: "TUM-Live, the livestreaming and VoD service of the " +
"Rechnerbetriebsgruppe at the department of informatics and " +
"mathematics at the Technical University of Munich",
}
}

// init initializes the global branding configuration variable `BrandingCfg`. If the config file doesn't exist
// it will be set to the result of `getDefaultBranding()`.
func init() {
v := viper.New()
v.SetConfigName("branding")
v.SetConfigType("yaml")
v.AddConfigPath("/etc/TUM-Live/")
v.AddConfigPath("$HOME/.TUM-Live")
v.AddConfigPath(".")

branding := getDefaultBranding()

err := v.ReadInConfig()
if err == nil {
err = v.Unmarshal(&branding)
log.Info("Using branding.yaml.")
if err != nil {
panic(fmt.Errorf("fatal error branding file: %v", err))
}
}

BrandingCfg = branding
}
7 changes: 4 additions & 3 deletions tools/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type Config struct {
Password string `yaml:"password"`
Database string `yaml:"database"`
Host string `yaml:"host"`
Port uint `yaml:"port"`
Port uint `yaml:"port"`
} `yaml:"db"`
Campus struct {
Base string `yaml:"base"`
Expand All @@ -128,8 +128,9 @@ type Config struct {
IdpColor string `yaml:"idpColor"`
} `yaml:"saml"`
Paths struct {
Static string `yaml:"static"`
Mass string `yaml:"mass"`
Static string `yaml:"static"`
Mass string `yaml:"mass"`
Branding string `yaml:"branding"`
} `yaml:"paths"`
Auths struct {
SmpUser string `yaml:"smpUser"`
Expand Down
10 changes: 6 additions & 4 deletions tools/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ func LoggedIn(c *gin.Context) {
// the gin context is always aborted after this function is called.
func RenderErrorPage(c *gin.Context, status int, message string) {
err := templateExecutor.ExecuteTemplate(c.Writer, "error.gohtml", ErrorPageData{
Status: status,
Message: message,
Status: status,
Message: message,
Branding: BrandingCfg,
})
if err != nil {
log.Error(err)
Expand All @@ -96,8 +97,9 @@ func RenderErrorPage(c *gin.Context, status int, message string) {

// ErrorPageData is the required data for the error page
type ErrorPageData struct {
Status int
Message string
Status int
Message string
Branding Branding
}

const (
Expand Down
136 changes: 57 additions & 79 deletions web/assets/img/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions web/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (r mainRoutes) InfoPage(id uint) gin.HandlerFunc {
c.AbortWithStatus(http.StatusInternalServerError)
return
}
indexData.VersionTag = VersionTag

indexData = NewIndexData()

text, err := r.InfoPageDao.GetById(id)
if err != nil {
Expand Down Expand Up @@ -91,18 +92,18 @@ type IndexData struct {
CurrentTerm string
UserName string
ServerNotifications []model.ServerNotification
Branding tools.Branding
}

func NewIndexData() IndexData {
return IndexData{
VersionTag: VersionTag,
Branding: tools.BrandingCfg,
}
}

func NewIndexDataWithContext(c *gin.Context) IndexData {
indexData := IndexData{
VersionTag: VersionTag,
}
indexData := NewIndexData()

var tumLiveContext tools.TUMLiveContext
tumLiveContextQueried, found := c.Get("TUMLiveContext")
Expand Down
Loading

0 comments on commit 3199521

Please sign in to comment.