mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Correct initialisms as suggested by golint
First step to use initialisms that golint suggests, for example: Line 116: func GetHtmlRenderer should be GetHTMLRenderer as see on http://goreportcard.com/report/spf13/hugo Thanks to @bep for the idea! Note that command-line flags (cobra and pflag) as well as struct fields like .BaseUrl and .Url that are used in Go HTML templates need more work to maintain backward-compatibility, and thus are NOT yet dealt with in this commit. First step in fixing #959.
This commit is contained in:
@@ -41,7 +41,7 @@ var SummaryDivider = []byte("<!--more-->")
|
||||
type Blackfriday struct {
|
||||
AngledQuotes bool
|
||||
Fractions bool
|
||||
PlainIdAnchors bool
|
||||
PlainIDAnchors bool
|
||||
Extensions []string
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func NewBlackfriday() *Blackfriday {
|
||||
return &Blackfriday{
|
||||
AngledQuotes: false,
|
||||
Fractions: true,
|
||||
PlainIdAnchors: false,
|
||||
PlainIDAnchors: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,17 +113,17 @@ func BytesToHTML(b []byte) template.HTML {
|
||||
}
|
||||
|
||||
// GetHtmlRenderer creates a new Renderer with the given configuration.
|
||||
func GetHtmlRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Renderer {
|
||||
func GetHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Renderer {
|
||||
renderParameters := blackfriday.HtmlRendererParameters{
|
||||
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
||||
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
|
||||
}
|
||||
|
||||
b := len(ctx.DocumentId) != 0
|
||||
b := len(ctx.DocumentID) != 0
|
||||
|
||||
if b && !ctx.getConfig().PlainIdAnchors {
|
||||
renderParameters.FootnoteAnchorPrefix = ctx.DocumentId + ":" + renderParameters.FootnoteAnchorPrefix
|
||||
renderParameters.HeaderIDSuffix = ":" + ctx.DocumentId
|
||||
if b && !ctx.getConfig().PlainIDAnchors {
|
||||
renderParameters.FootnoteAnchorPrefix = ctx.DocumentID + ":" + renderParameters.FootnoteAnchorPrefix
|
||||
renderParameters.HeaderIDSuffix = ":" + ctx.DocumentID
|
||||
}
|
||||
|
||||
htmlFlags := defaultFlags
|
||||
@@ -158,13 +158,13 @@ func getMarkdownExtensions(ctx *RenderingContext) int {
|
||||
}
|
||||
|
||||
func markdownRender(ctx *RenderingContext) []byte {
|
||||
return blackfriday.Markdown(ctx.Content, GetHtmlRenderer(0, ctx),
|
||||
return blackfriday.Markdown(ctx.Content, GetHTMLRenderer(0, ctx),
|
||||
getMarkdownExtensions(ctx))
|
||||
}
|
||||
|
||||
func markdownRenderWithTOC(ctx *RenderingContext) []byte {
|
||||
return blackfriday.Markdown(ctx.Content,
|
||||
GetHtmlRenderer(blackfriday.HTML_TOC, ctx),
|
||||
GetHTMLRenderer(blackfriday.HTML_TOC, ctx),
|
||||
getMarkdownExtensions(ctx))
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
|
||||
type RenderingContext struct {
|
||||
Content []byte
|
||||
PageFmt string
|
||||
DocumentId string
|
||||
DocumentID string
|
||||
Config *Blackfriday
|
||||
configInit sync.Once
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
const tstHtmlContent = "<!DOCTYPE html><html><head><script src=\"http://two/foobar.js\"></script></head><body><nav><ul><li hugo-nav=\"section_0\"></li><li hugo-nav=\"section_1\"></li></ul></nav><article>content <a href=\"http://two/foobar\">foobar</a>. Follow up</article><p>This is some text.<br>And some more.</p></body></html>"
|
||||
const tstHTMLContent = "<!DOCTYPE html><html><head><script src=\"http://two/foobar.js\"></script></head><body><nav><ul><li hugo-nav=\"section_0\"></li><li hugo-nav=\"section_1\"></li></ul></nav><article>content <a href=\"http://two/foobar\">foobar</a>. Follow up</article><p>This is some text.<br>And some more.</p></body></html>"
|
||||
|
||||
func TestStripHTML(t *testing.T) {
|
||||
type test struct {
|
||||
@@ -31,7 +31,7 @@ func TestStripHTML(t *testing.T) {
|
||||
func BenchmarkStripHTML(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
StripHTML(tstHtmlContent)
|
||||
StripHTML(tstHTMLContent)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -52,7 +52,7 @@ func (PathBridge) Separator() string {
|
||||
|
||||
var pathBridge PathBridge
|
||||
|
||||
func sanitizeUrlWithFlags(in string, f purell.NormalizationFlags) string {
|
||||
func sanitizeURLWithFlags(in string, f purell.NormalizationFlags) string {
|
||||
s, err := purell.NormalizeURLString(in, f)
|
||||
if err != nil {
|
||||
return in
|
||||
@@ -88,20 +88,20 @@ func sanitizeUrlWithFlags(in string, f purell.NormalizationFlags) string {
|
||||
}
|
||||
|
||||
// SanitizeUrl sanitizes the input URL string.
|
||||
func SanitizeUrl(in string) string {
|
||||
return sanitizeUrlWithFlags(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
|
||||
func SanitizeURL(in string) string {
|
||||
return sanitizeURLWithFlags(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
|
||||
}
|
||||
|
||||
// SanitizeUrlKeepTrailingSlash is the same as SanitizeUrl, but will keep any trailing slash.
|
||||
func SanitizeUrlKeepTrailingSlash(in string) string {
|
||||
return sanitizeUrlWithFlags(in, purell.FlagsSafe|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
|
||||
func SanitizeURLKeepTrailingSlash(in string) string {
|
||||
return sanitizeURLWithFlags(in, purell.FlagsSafe|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
|
||||
}
|
||||
|
||||
// Similar to MakePath, but with Unicode handling
|
||||
// Example:
|
||||
// uri: Vim (text editor)
|
||||
// urlize: vim-text-editor
|
||||
func Urlize(uri string) string {
|
||||
func URLize(uri string) string {
|
||||
sanitized := MakePathToLower(uri)
|
||||
|
||||
// escape unicode letters
|
||||
@@ -148,9 +148,9 @@ func MakePermalink(host, plink string) *url.URL {
|
||||
// AddContextRoot adds the context root to an URL if it's not already set.
|
||||
// For relative URL entries on sites with a base url with a context root set (i.e. http://example.com/mysite),
|
||||
// relative URLs must not include the context root if canonifyUrls is enabled. But if it's disabled, it must be set.
|
||||
func AddContextRoot(baseUrl, relativePath string) string {
|
||||
func AddContextRoot(baseURL, relativePath string) string {
|
||||
|
||||
url, err := url.Parse(baseUrl)
|
||||
url, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -164,16 +164,16 @@ func AddContextRoot(baseUrl, relativePath string) string {
|
||||
return newPath
|
||||
}
|
||||
|
||||
func UrlizeAndPrep(in string) string {
|
||||
return UrlPrep(viper.GetBool("UglyUrls"), Urlize(in))
|
||||
func URLizeAndPrep(in string) string {
|
||||
return URLPrep(viper.GetBool("UglyURLs"), URLize(in))
|
||||
}
|
||||
|
||||
func UrlPrep(ugly bool, in string) string {
|
||||
func URLPrep(ugly bool, in string) string {
|
||||
if ugly {
|
||||
x := Uglify(SanitizeUrl(in))
|
||||
x := Uglify(SanitizeURL(in))
|
||||
return x
|
||||
}
|
||||
x := PrettifyUrl(SanitizeUrl(in))
|
||||
x := PrettifyURL(SanitizeURL(in))
|
||||
if path.Ext(x) == ".xml" {
|
||||
return x
|
||||
}
|
||||
@@ -186,8 +186,8 @@ func UrlPrep(ugly bool, in string) string {
|
||||
}
|
||||
|
||||
// PrettifyUrl takes a URL string and returns a semantic, clean URL.
|
||||
func PrettifyUrl(in string) string {
|
||||
x := PrettifyUrlPath(in)
|
||||
func PrettifyURL(in string) string {
|
||||
x := PrettifyURLPath(in)
|
||||
|
||||
if path.Base(x) == "index.html" {
|
||||
return path.Dir(x)
|
||||
@@ -205,7 +205,7 @@ func PrettifyUrl(in string) string {
|
||||
// /section/name.html becomes /section/name/index.html
|
||||
// /section/name/ becomes /section/name/index.html
|
||||
// /section/name/index.html becomes /section/name/index.html
|
||||
func PrettifyUrlPath(in string) string {
|
||||
func PrettifyURLPath(in string) string {
|
||||
return PrettiyPath(in, pathBridge)
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ func TestUrlize(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
output := Urlize(test.input)
|
||||
output := URLize(test.input)
|
||||
if output != test.expected {
|
||||
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
|
||||
}
|
||||
@@ -36,8 +36,8 @@ func TestSanitizeUrl(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
o1 := SanitizeUrl(test.input)
|
||||
o2 := SanitizeUrlKeepTrailingSlash(test.input)
|
||||
o1 := SanitizeURL(test.input)
|
||||
o2 := SanitizeURLKeepTrailingSlash(test.input)
|
||||
|
||||
expected2 := test.expected
|
||||
|
||||
@@ -88,7 +88,7 @@ func TestUrlPrep(t *testing.T) {
|
||||
{true, "/section/name/index.html", "/section/name.html"},
|
||||
}
|
||||
for i, d := range data {
|
||||
output := UrlPrep(d.ugly, d.input)
|
||||
output := URLPrep(d.ugly, d.input)
|
||||
if d.output != output {
|
||||
t.Errorf("Test #%d failed. Expected %q got %q", i, d.output, output)
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func TestUrlPrep(t *testing.T) {
|
||||
|
||||
func TestAddContextRoot(t *testing.T) {
|
||||
tests := []struct {
|
||||
baseUrl string
|
||||
baseURL string
|
||||
url string
|
||||
expected string
|
||||
}{
|
||||
@@ -114,7 +114,7 @@ func TestAddContextRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
output := AddContextRoot(test.baseUrl, test.url)
|
||||
output := AddContextRoot(test.baseURL, test.url)
|
||||
if output != test.expected {
|
||||
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
|
||||
}
|
||||
@@ -122,22 +122,22 @@ func TestAddContextRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPretty(t *testing.T) {
|
||||
assert.Equal(t, PrettifyUrlPath("/section/name.html"), "/section/name/index.html")
|
||||
assert.Equal(t, PrettifyUrlPath("/section/sub/name.html"), "/section/sub/name/index.html")
|
||||
assert.Equal(t, PrettifyUrlPath("/section/name/"), "/section/name/index.html")
|
||||
assert.Equal(t, PrettifyUrlPath("/section/name/index.html"), "/section/name/index.html")
|
||||
assert.Equal(t, PrettifyUrlPath("/index.html"), "/index.html")
|
||||
assert.Equal(t, PrettifyUrlPath("/name.xml"), "/name/index.xml")
|
||||
assert.Equal(t, PrettifyUrlPath("/"), "/")
|
||||
assert.Equal(t, PrettifyUrlPath(""), "/")
|
||||
assert.Equal(t, PrettifyUrl("/section/name.html"), "/section/name")
|
||||
assert.Equal(t, PrettifyUrl("/section/sub/name.html"), "/section/sub/name")
|
||||
assert.Equal(t, PrettifyUrl("/section/name/"), "/section/name")
|
||||
assert.Equal(t, PrettifyUrl("/section/name/index.html"), "/section/name")
|
||||
assert.Equal(t, PrettifyUrl("/index.html"), "/")
|
||||
assert.Equal(t, PrettifyUrl("/name.xml"), "/name/index.xml")
|
||||
assert.Equal(t, PrettifyUrl("/"), "/")
|
||||
assert.Equal(t, PrettifyUrl(""), "/")
|
||||
assert.Equal(t, PrettifyURLPath("/section/name.html"), "/section/name/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/section/sub/name.html"), "/section/sub/name/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/section/name/"), "/section/name/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/section/name/index.html"), "/section/name/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/index.html"), "/index.html")
|
||||
assert.Equal(t, PrettifyURLPath("/name.xml"), "/name/index.xml")
|
||||
assert.Equal(t, PrettifyURLPath("/"), "/")
|
||||
assert.Equal(t, PrettifyURLPath(""), "/")
|
||||
assert.Equal(t, PrettifyURL("/section/name.html"), "/section/name")
|
||||
assert.Equal(t, PrettifyURL("/section/sub/name.html"), "/section/sub/name")
|
||||
assert.Equal(t, PrettifyURL("/section/name/"), "/section/name")
|
||||
assert.Equal(t, PrettifyURL("/section/name/index.html"), "/section/name")
|
||||
assert.Equal(t, PrettifyURL("/index.html"), "/")
|
||||
assert.Equal(t, PrettifyURL("/name.xml"), "/name/index.xml")
|
||||
assert.Equal(t, PrettifyURL("/"), "/")
|
||||
assert.Equal(t, PrettifyURL(""), "/")
|
||||
}
|
||||
|
||||
func TestUgly(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user