Add slogan config (#3752)
This is a PR for #3616 Currently added a new optional config `SLOGAN` in ini file. When this config is set title page is modified in APP_NAME [ - SLOGAN] Example in image below  Add the new config value in the admin settings page (readonly)  ## TODO * [x] Add the possibility to add the `SLOGAN` config from the installation form * [ ] Update https://forgejo.org/docs/next/admin/config-cheat-sheet Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3752 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: mirko <mirko.perillo@gmail.com> Co-committed-by: mirko <mirko.perillo@gmail.com>
This commit is contained in:
parent
dedcd6c647
commit
f015846c11
19 changed files with 138 additions and 13 deletions
|
@ -45,6 +45,14 @@ var (
|
|||
// AppName is the Application name, used in the page title.
|
||||
// It maps to ini:"APP_NAME"
|
||||
AppName string
|
||||
// AppSlogan is the Application slogan.
|
||||
// It maps to ini:"APP_SLOGAN"
|
||||
AppSlogan string
|
||||
// AppDisplayNameFormat defines how the AppDisplayName should be presented
|
||||
// It maps to ini:"APP_DISPLAY_NAME_FORMAT"
|
||||
AppDisplayNameFormat string
|
||||
// AppDisplayName is the display name for the application, defined following AppDisplayNameFormat
|
||||
AppDisplayName string
|
||||
// AppURL is the Application ROOT_URL. It always has a '/' suffix
|
||||
// It maps to ini:"ROOT_URL"
|
||||
AppURL string
|
||||
|
@ -164,10 +172,21 @@ func MakeAbsoluteAssetURL(appURL, staticURLPrefix string) string {
|
|||
return strings.TrimSuffix(staticURLPrefix, "/")
|
||||
}
|
||||
|
||||
func generateDisplayName() string {
|
||||
appDisplayName := AppName
|
||||
if AppSlogan != "" {
|
||||
appDisplayName = strings.Replace(AppDisplayNameFormat, "{APP_NAME}", AppName, 1)
|
||||
appDisplayName = strings.Replace(appDisplayName, "{APP_SLOGAN}", AppSlogan, 1)
|
||||
}
|
||||
return appDisplayName
|
||||
}
|
||||
|
||||
func loadServerFrom(rootCfg ConfigProvider) {
|
||||
sec := rootCfg.Section("server")
|
||||
AppName = rootCfg.Section("").Key("APP_NAME").MustString("Forgejo: Beyond coding. We Forge.")
|
||||
|
||||
AppSlogan = rootCfg.Section("").Key("APP_SLOGAN").MustString("")
|
||||
AppDisplayNameFormat = rootCfg.Section("").Key("APP_DISPLAY_NAME_FORMAT").MustString("{APP_NAME}: {APP_SLOGAN}")
|
||||
AppDisplayName = generateDisplayName()
|
||||
Domain = sec.Key("DOMAIN").MustString("localhost")
|
||||
HTTPAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
|
||||
HTTPPort = sec.Key("HTTP_PORT").MustString("3000")
|
||||
|
|
36
modules/setting/server_test.go
Normal file
36
modules/setting/server_test.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package setting
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDisplayNameDefault(t *testing.T) {
|
||||
defer test.MockVariableValue(&AppName, "Forgejo")()
|
||||
defer test.MockVariableValue(&AppSlogan, "Beyond coding. We Forge.")()
|
||||
defer test.MockVariableValue(&AppDisplayNameFormat, "{APP_NAME}: {APP_SLOGAN}")()
|
||||
displayName := generateDisplayName()
|
||||
assert.Equal(t, "Forgejo: Beyond coding. We Forge.", displayName)
|
||||
}
|
||||
|
||||
func TestDisplayNameEmptySlogan(t *testing.T) {
|
||||
defer test.MockVariableValue(&AppName, "Forgejo")()
|
||||
defer test.MockVariableValue(&AppSlogan, "")()
|
||||
defer test.MockVariableValue(&AppDisplayNameFormat, "{APP_NAME}: {APP_SLOGAN}")()
|
||||
displayName := generateDisplayName()
|
||||
assert.Equal(t, "Forgejo", displayName)
|
||||
}
|
||||
|
||||
func TestDisplayNameCustomFormat(t *testing.T) {
|
||||
defer test.MockVariableValue(&AppName, "Forgejo")()
|
||||
defer test.MockVariableValue(&AppSlogan, "Beyond coding. We Forge.")()
|
||||
defer test.MockVariableValue(&AppDisplayNameFormat, "{APP_NAME} - {APP_SLOGAN}")()
|
||||
displayName := generateDisplayName()
|
||||
assert.Equal(t, "Forgejo - Beyond coding. We Forge.", displayName)
|
||||
}
|
|
@ -79,6 +79,12 @@ func NewFuncMap() template.FuncMap {
|
|||
"AppName": func() string {
|
||||
return setting.AppName
|
||||
},
|
||||
"AppSlogan": func() string {
|
||||
return setting.AppSlogan
|
||||
},
|
||||
"AppDisplayName": func() string {
|
||||
return setting.AppDisplayName
|
||||
},
|
||||
"AppSubUrl": func() string {
|
||||
return setting.AppSubURL
|
||||
},
|
||||
|
|
|
@ -28,6 +28,12 @@ func mailSubjectTextFuncMap() texttmpl.FuncMap {
|
|||
"AppName": func() string {
|
||||
return setting.AppName
|
||||
},
|
||||
"AppSlogan": func() string {
|
||||
return setting.AppSlogan
|
||||
},
|
||||
"AppDisplayName": func() string {
|
||||
return setting.AppDisplayName
|
||||
},
|
||||
"AppDomain": func() string { // documented in mail-templates.md
|
||||
return setting.Domain
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue