diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-02-22 09:05:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-22 09:05:26 +0800 |
commit | 648d9e253c1924b832248f26fee42b2fb64dc3bc (patch) | |
tree | 51649fad974cd7284a47d30e412c90e7ab72cd2c /internal/markup | |
parent | 5b14cc6f0b7b661beb2640a94bd15660cdb48587 (diff) |
conf: overhaul server settings (#5928)
* conf: rename package
* Requires Go 1.12
* Fix lint
* Fix lint
* Overhaul
* db: fix tests
* Save my work
* Fix tests
* Server.UnixSocketPermission
* Server.LocalRootURL
* SSH settings
* Server.OfflineMode
* Save my work
* App.Version
* Remove [server] STATIC_ROOT_PATH
* Server.LandingURL
Diffstat (limited to 'internal/markup')
-rw-r--r-- | internal/markup/markdown.go | 22 | ||||
-rw-r--r-- | internal/markup/markdown_test.go | 8 | ||||
-rw-r--r-- | internal/markup/markup.go | 8 | ||||
-rw-r--r-- | internal/markup/markup_test.go | 4 | ||||
-rw-r--r-- | internal/markup/sanitizer.go | 4 |
5 files changed, 23 insertions, 23 deletions
diff --git a/internal/markup/markdown.go b/internal/markup/markdown.go index 6606d2b5..0d4cdd2a 100644 --- a/internal/markup/markdown.go +++ b/internal/markup/markdown.go @@ -13,15 +13,15 @@ import ( "github.com/russross/blackfriday" + "gogs.io/gogs/internal/conf" "gogs.io/gogs/internal/lazyregexp" - "gogs.io/gogs/internal/setting" "gogs.io/gogs/internal/tool" ) // IsMarkdownFile reports whether name looks like a Markdown file based on its extension. func IsMarkdownFile(name string) bool { extension := strings.ToLower(filepath.Ext(name)) - for _, ext := range setting.Markdown.FileExtensions { + for _, ext := range conf.Markdown.FileExtensions { if strings.ToLower(ext) == extension { return true } @@ -63,7 +63,7 @@ func (r *MarkdownRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) { // Since this method could only possibly serve one link at a time, // we do not need to find all. - if bytes.HasPrefix(link, []byte(setting.AppURL)) { + if bytes.HasPrefix(link, []byte(conf.Server.ExternalURL)) { m := CommitPattern.Find(link) if m != nil { m = bytes.TrimSpace(m) @@ -86,14 +86,14 @@ func (r *MarkdownRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) { } index := string(m[i+7 : j]) - fullRepoURL := setting.AppURL + strings.TrimPrefix(r.urlPrefix, "/") + fullRepoURL := conf.Server.ExternalURL + strings.TrimPrefix(r.urlPrefix, "/") var link string if strings.HasPrefix(string(m), fullRepoURL) { // Use a short issue reference if the URL refers to this repository link = fmt.Sprintf(`<a href="%s">#%s</a>`, m, index) } else { // Use a cross-repository issue reference if the URL refers to a different repository - repo := string(m[len(setting.AppURL) : i-1]) + repo := string(m[len(conf.Server.ExternalURL) : i-1]) link = fmt.Sprintf(`<a href="%s">%s#%s</a>`, m, repo, index) } out.WriteString(link) @@ -122,18 +122,18 @@ func RawMarkdown(body []byte, urlPrefix string) []byte { htmlFlags |= blackfriday.HTML_SKIP_STYLE htmlFlags |= blackfriday.HTML_OMIT_CONTENTS - if setting.Smartypants.Enabled { + if conf.Smartypants.Enabled { htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS - if setting.Smartypants.Fractions { + if conf.Smartypants.Fractions { htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS } - if setting.Smartypants.Dashes { + if conf.Smartypants.Dashes { htmlFlags |= blackfriday.HTML_SMARTYPANTS_DASHES } - if setting.Smartypants.LatexDashes { + if conf.Smartypants.LatexDashes { htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES } - if setting.Smartypants.AngledQuotes { + if conf.Smartypants.AngledQuotes { htmlFlags |= blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES } } @@ -153,7 +153,7 @@ func RawMarkdown(body []byte, urlPrefix string) []byte { extensions |= blackfriday.EXTENSION_SPACE_HEADERS extensions |= blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK - if setting.Markdown.EnableHardLineBreak { + if conf.Markdown.EnableHardLineBreak { extensions |= blackfriday.EXTENSION_HARD_LINE_BREAK } diff --git a/internal/markup/markdown_test.go b/internal/markup/markdown_test.go index e748adc7..2715a322 100644 --- a/internal/markup/markdown_test.go +++ b/internal/markup/markdown_test.go @@ -12,12 +12,12 @@ import ( "github.com/russross/blackfriday" . "github.com/smartystreets/goconvey/convey" + "gogs.io/gogs/internal/conf" . "gogs.io/gogs/internal/markup" - "gogs.io/gogs/internal/setting" ) func Test_IsMarkdownFile(t *testing.T) { - setting.Markdown.FileExtensions = strings.Split(".md,.markdown,.mdown,.mkd", ",") + conf.Markdown.FileExtensions = strings.Split(".md,.markdown,.mdown,.mkd", ",") Convey("Detect Markdown file extension", t, func() { testCases := []struct { ext string @@ -40,7 +40,7 @@ func Test_IsMarkdownFile(t *testing.T) { func Test_Markdown(t *testing.T) { Convey("Rendering an issue URL", t, func() { - setting.AppURL = "http://localhost:3000/" + conf.Server.ExternalURL = "http://localhost:3000/" htmlFlags := 0 htmlFlags |= blackfriday.HTML_SKIP_STYLE htmlFlags |= blackfriday.HTML_OMIT_CONTENTS @@ -82,7 +82,7 @@ func Test_Markdown(t *testing.T) { }) Convey("Rendering a commit URL", t, func() { - setting.AppURL = "http://localhost:3000/" + conf.Server.ExternalURL = "http://localhost:3000/" htmlFlags := 0 htmlFlags |= blackfriday.HTML_SKIP_STYLE htmlFlags |= blackfriday.HTML_OMIT_CONTENTS diff --git a/internal/markup/markup.go b/internal/markup/markup.go index 2bb56603..65b14865 100644 --- a/internal/markup/markup.go +++ b/internal/markup/markup.go @@ -13,8 +13,8 @@ import ( "github.com/unknwon/com" "golang.org/x/net/html" + "gogs.io/gogs/internal/conf" "gogs.io/gogs/internal/lazyregexp" - "gogs.io/gogs/internal/setting" "gogs.io/gogs/internal/tool" ) @@ -78,7 +78,7 @@ func cutoutVerbosePrefix(prefix string) string { if prefix[i] == '/' { count++ } - if count >= 3+setting.AppSubURLDepth { + if count >= 3+conf.Server.SubpathDepth { return prefix[:i] } } @@ -133,7 +133,7 @@ func RenderCrossReferenceIssueIndexPattern(rawBytes []byte, urlPrefix string, me repo := string(m[:delimIdx]) index := string(m[delimIdx+1:]) - link := fmt.Sprintf(`<a href="%s%s/issues/%s">%s</a>`, setting.AppURL, repo, index, m) + link := fmt.Sprintf(`<a href="%s%s/issues/%s">%s</a>`, conf.Server.ExternalURL, repo, index, m) rawBytes = bytes.Replace(rawBytes, m, []byte(link), 1) } return rawBytes @@ -155,7 +155,7 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]strin for _, m := range ms { m = m[bytes.Index(m, []byte("@")):] rawBytes = bytes.Replace(rawBytes, m, - []byte(fmt.Sprintf(`<a href="%s/%s">%s</a>`, setting.AppSubURL, m[1:], m)), -1) + []byte(fmt.Sprintf(`<a href="%s/%s">%s</a>`, conf.Server.Subpath, m[1:], m)), -1) } rawBytes = RenderIssueIndexPattern(rawBytes, urlPrefix, metas) diff --git a/internal/markup/markup_test.go b/internal/markup/markup_test.go index 0e3beb76..be19047b 100644 --- a/internal/markup/markup_test.go +++ b/internal/markup/markup_test.go @@ -10,8 +10,8 @@ import ( . "github.com/smartystreets/goconvey/convey" + "gogs.io/gogs/internal/conf" . "gogs.io/gogs/internal/markup" - "gogs.io/gogs/internal/setting" ) func Test_IsReadmeFile(t *testing.T) { @@ -62,7 +62,7 @@ func Test_RenderIssueIndexPattern(t *testing.T) { urlPrefix = "/prefix" metas map[string]string = nil ) - setting.AppSubURLDepth = 0 + conf.Server.SubpathDepth = 0 Convey("To the internal issue tracker", func() { Convey("It should not render anything when there are no mentions", func() { diff --git a/internal/markup/sanitizer.go b/internal/markup/sanitizer.go index 981e1c73..4a8f6c28 100644 --- a/internal/markup/sanitizer.go +++ b/internal/markup/sanitizer.go @@ -10,7 +10,7 @@ import ( "github.com/microcosm-cc/bluemonday" "gogs.io/gogs/internal/lazyregexp" - "gogs.io/gogs/internal/setting" + "gogs.io/gogs/internal/conf" ) // Sanitizer is a protection wrapper of *bluemonday.Policy which does not allow @@ -40,7 +40,7 @@ func NewSanitizer() { sanitizer.policy.AllowURLSchemes("data") // Custom URL-Schemes - sanitizer.policy.AllowURLSchemes(setting.Markdown.CustomURLSchemes...) + sanitizer.policy.AllowURLSchemes(conf.Markdown.CustomURLSchemes...) }) } |