From c559a9f824abc060bebf4855c4e833a749a48749 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 14 Mar 2019 10:20:40 +0800 Subject: [PATCH] static url --- custom/conf/app.ini.sample | 2 ++ modules/setting/setting.go | 4 ++- modules/templates/helper.go | 15 ++++++---- templates/base/footer.tmpl | 42 +++++++++++++-------------- templates/base/footer_content.tmpl | 2 +- templates/base/head.tmpl | 46 +++++++++++++++--------------- templates/base/head_navbar.tmpl | 2 +- templates/home.tmpl | 2 +- 8 files changed, 61 insertions(+), 54 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 0212964750..832e6cf2e8 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -151,6 +151,8 @@ FILE_EXTENSIONS = .md,.markdown,.mdown,.mkd PROTOCOL = http DOMAIN = localhost ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/ +; when STATIC_URL_PREFIX is empty it will follow APP_URL +STATIC_URL_PREFIX = ; The address to listen on. Either a IPv4/IPv6 address or the path to a unix socket. HTTP_ADDR = 0.0.0.0 HTTP_PORT = 3000 diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 6a5c5a36d7..005f756b32 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -104,6 +104,7 @@ var ( LetsEncryptTOS bool LetsEncryptDirectory string LetsEncryptEmail string + StaticURLPrefix string SSH = struct { Disabled bool `ini:"DISABLE_SSH"` @@ -582,7 +583,7 @@ func NewContext() { defaultAppURL += ":" + HTTPPort } AppURL = sec.Key("ROOT_URL").MustString(defaultAppURL) - AppURL = strings.TrimRight(AppURL, "/") + "/" + AppURL = strings.TrimSuffix(AppURL, "/") + "/" // Check if has app suburl. appURL, err := url.Parse(AppURL) @@ -592,6 +593,7 @@ func NewContext() { // Suburl should start with '/' and end without '/', such as '/{subpath}'. // This value is empty if site does not have sub-url. AppSubURL = strings.TrimSuffix(appURL.Path, "/") + StaticURLPrefix = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL), "/") AppSubURLDepth = strings.Count(AppSubURL, "/") // Check if Domain differs from AppURL domain than update it to AppURL's domain // TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8 diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 5a3969c098..dc2865254c 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -48,6 +48,9 @@ func NewFuncMap() []template.FuncMap { "AppSubUrl": func() string { return setting.AppSubURL }, + "StaticUrlPrefix": func() string { + return setting.StaticURLPrefix + }, "AppUrl": func() string { return setting.AppURL }, @@ -110,12 +113,12 @@ func NewFuncMap() []template.FuncMap { } return str[start:end] }, - "EllipsisString": base.EllipsisString, - "DiffTypeToStr": DiffTypeToStr, - "DiffLineTypeToStr": DiffLineTypeToStr, - "Sha1": Sha1, - "ShortSha": base.ShortSha, - "MD5": base.EncodeMD5, + "EllipsisString": base.EllipsisString, + "DiffTypeToStr": DiffTypeToStr, + "DiffLineTypeToStr": DiffLineTypeToStr, + "Sha1": Sha1, + "ShortSha": base.ShortSha, + "MD5": base.EncodeMD5, "ActionContent2Commits": ActionContent2Commits, "PathEscape": url.PathEscape, "EscapePound": func(str string) string { diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl index 13718620da..802175ce7e 100644 --- a/templates/base/footer.tmpl +++ b/templates/base/footer.tmpl @@ -12,38 +12,38 @@ {{template "base/footer_content" .}} - - - + + + {{if .RequireSimpleMDE}} - - - + + + {{end}} {{if .RequireGitGraph}} - + {{end}} {{if .RequireHighlightJS}} - + {{end}} {{if .RequireMinicolors}} - + {{end}} {{if .RequireDatetimepicker}} - + {{end}} {{if .RequireDropzone}} - + {{end}} {{if .RequireU2F}} - + {{end}} {{if .EnableCaptcha}} {{if eq .CaptchaType "recaptcha"}} @@ -51,7 +51,7 @@ {{end}} {{end}} {{if .RequireTribute}} - + {{end}} - - - + + + - + {{if .EnableHeatmap}} - - + + diff --git a/templates/base/footer_content.tmpl b/templates/base/footer_content.tmpl index 6f680d4cb8..364e58a3d0 100644 --- a/templates/base/footer_content.tmpl +++ b/templates/base/footer_content.tmpl @@ -16,7 +16,7 @@ {{end}} - JavaScript licenses + JavaScript licenses {{if .EnableSwagger}}API{{end}} {{.i18n.Tr "website"}} {{if (or .ShowFooterVersion .PageIsAdmin)}}{{GoVer}}{{end}} diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 7cdfdd34be..658fb33a78 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -5,7 +5,7 @@ {{if .Title}}{{.Title}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} - + - - - - - + + + + + {{if .RequireSimpleMDE}} - + {{end}} {{if .RequireGitGraph}} - + {{end}} {{if .RequireTribute}} - + {{end}} - - + +