mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-26 22:04:32 +02:00
More initialism corrections (golint)
Thanks to @bep's new, brilliant helpers.Deprecated() function, the following functions or variables are transitioned to their new names, preserving backward compatibility for v0.14 and warning the user of upcoming obsolescence in v0.15: * .Url → .URL (for node, menu and paginator) * .Site.BaseUrl → .Site.BaseURL * .Site.Indexes → .Site.Taxonomies * .Site.Recent → .Site.Pages * getJson → getJSON * getCsv → getCSV * safeHtml → safeHTML * safeCss → safeCSS * safeUrl → safeURL Also fix related initialisms in strings and comments. Continued effort in fixing #959.
This commit is contained in:
@@ -938,7 +938,7 @@ func SafeHTML(text string) template.HTML {
|
||||
return template.HTML(text)
|
||||
}
|
||||
|
||||
// "safeHtmlAttr" is currently disabled, pending further discussion
|
||||
// "safeHTMLAttr" is currently disabled, pending further discussion
|
||||
// on its use case. 2015-01-19
|
||||
func SafeHTMLAttr(text string) template.HTMLAttr {
|
||||
return template.HTMLAttr(text)
|
||||
@@ -1308,11 +1308,8 @@ func init() {
|
||||
"isset": IsSet,
|
||||
"echoParam": ReturnWhenSet,
|
||||
"safeHTML": SafeHTML,
|
||||
"safeHtml": SafeHTML,
|
||||
"safeCSS": SafeCSS,
|
||||
"safeCss": SafeCSS,
|
||||
"safeURL": SafeURL,
|
||||
"safeUrl": SafeURL,
|
||||
"markdownify": Markdownify,
|
||||
"first": First,
|
||||
"where": Where,
|
||||
@@ -1337,11 +1334,35 @@ func init() {
|
||||
"trim": Trim,
|
||||
"dateFormat": DateFormat,
|
||||
"getJSON": GetJSON,
|
||||
"getJson": GetJSON,
|
||||
"getCSV": GetCSV,
|
||||
"getCsv": GetCSV,
|
||||
"seq": helpers.Seq,
|
||||
"getenv": func(varName string) string { return os.Getenv(varName) },
|
||||
|
||||
// "getJson" is deprecated. Will be removed in 0.15.
|
||||
"getJson": func(urlParts ...string) interface{} {
|
||||
helpers.Deprecated("Template", "getJson", "getJSON")
|
||||
return GetJSON(urlParts...)
|
||||
},
|
||||
// "getJson" is deprecated. Will be removed in 0.15.
|
||||
"getCsv": func(sep string, urlParts ...string) [][]string {
|
||||
helpers.Deprecated("Template", "getCsv", "getCSV")
|
||||
return GetCSV(sep, urlParts...)
|
||||
},
|
||||
// "safeHtml" is deprecated. Will be removed in 0.15.
|
||||
"safeHtml": func(text string) template.HTML {
|
||||
helpers.Deprecated("Template", "safeHtml", "safeHTML")
|
||||
return SafeHTML(text)
|
||||
},
|
||||
// "safeCss" is deprecated. Will be removed in 0.15.
|
||||
"safeCss": func(text string) template.CSS {
|
||||
helpers.Deprecated("Template", "safeCss", "safeCSS")
|
||||
return SafeCSS(text)
|
||||
},
|
||||
// "safeUrl" is deprecated. Will be removed in 0.15.
|
||||
"safeUrl": func(text string) template.URL {
|
||||
helpers.Deprecated("Template", "safeUrl", "safeURL")
|
||||
return SafeURL(text)
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -55,13 +55,13 @@ func (t *GoHTMLTemplate) EmbedTemplates() {
|
||||
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
|
||||
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
|
||||
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
|
||||
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHtml }}</lastBuildDate>{{ end }}
|
||||
<atom:link href="{{.Url}}" rel="self" type="application/rss+xml" />
|
||||
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
|
||||
<atom:link href="{{.URL}}" rel="self" type="application/rss+xml" />
|
||||
{{ range first 15 .Data.Pages }}
|
||||
<item>
|
||||
<title>{{ .Title }}</title>
|
||||
<link>{{ .Permalink }}</link>
|
||||
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHtml }}</pubDate>
|
||||
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
|
||||
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
|
||||
<guid>{{ .Permalink }}</guid>
|
||||
<description>{{ .Content | html }}</description>
|
||||
@@ -74,7 +74,7 @@ func (t *GoHTMLTemplate) EmbedTemplates() {
|
||||
{{ range .Data.Pages }}
|
||||
<url>
|
||||
<loc>{{ .Permalink }}</loc>{{ if not .Date.IsZero }}
|
||||
<lastmod>{{ safeHtml ( .Date.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
|
||||
<lastmod>{{ safeHTML ( .Date.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
|
||||
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
|
||||
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}
|
||||
</url>
|
||||
@@ -86,24 +86,24 @@ func (t *GoHTMLTemplate) EmbedTemplates() {
|
||||
<ul class="pagination">
|
||||
{{ with $pag.First }}
|
||||
<li>
|
||||
<a href="{{ .Url }}" aria-label="First"><span aria-hidden="true">««</span></a>
|
||||
<a href="{{ .URL }}" aria-label="First"><span aria-hidden="true">««</span></a>
|
||||
</li>
|
||||
{{ end }}
|
||||
<li
|
||||
{{ if not $pag.HasPrev }}class="disabled"{{ end }}>
|
||||
<a href="{{ if $pag.HasPrev }}{{ $pag.Prev.Url }}{{ end }}" aria-label="Previous"><span aria-hidden="true">«</span></a>
|
||||
<a href="{{ if $pag.HasPrev }}{{ $pag.Prev.URL }}{{ end }}" aria-label="Previous"><span aria-hidden="true">«</span></a>
|
||||
</li>
|
||||
{{ range $pag.Pagers }}
|
||||
<li
|
||||
{{ if eq . $pag }}class="active"{{ end }}><a href="{{ .Url }}">{{ .PageNumber }}</a></li>
|
||||
{{ if eq . $pag }}class="active"{{ end }}><a href="{{ .URL }}">{{ .PageNumber }}</a></li>
|
||||
{{ end }}
|
||||
<li
|
||||
{{ if not $pag.HasNext }}class="disabled"{{ end }}>
|
||||
<a href="{{ if $pag.HasNext }}{{ $pag.Next.Url }}{{ end }}" aria-label="Next"><span aria-hidden="true">»</span></a>
|
||||
<a href="{{ if $pag.HasNext }}{{ $pag.Next.URL }}{{ end }}" aria-label="Next"><span aria-hidden="true">»</span></a>
|
||||
</li>
|
||||
{{ with $pag.Last }}
|
||||
<li>
|
||||
<a href="{{ .Url }}" aria-label="Last"><span aria-hidden="true">»»</span></a>
|
||||
<a href="{{ .URL }}" aria-label="Last"><span aria-hidden="true">»»</span></a>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
@@ -134,7 +134,7 @@ func (t *GoHTMLTemplate) EmbedTemplates() {
|
||||
<meta property="og:image" content="{{ . }}" />
|
||||
{{ end }}{{ end }}
|
||||
|
||||
{{ if not .Date.IsZero }}<meta property="og:updated_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHtml }}"/>{{ end }}{{ with .Params.audio }}
|
||||
{{ if not .Date.IsZero }}<meta property="og:updated_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}"/>{{ end }}{{ with .Params.audio }}
|
||||
<meta property="og:audio" content="{{ . }}" />{{ end }}{{ with .Params.locale }}
|
||||
<meta property="og:locale" content="{{ . }}" />{{ end }}{{ with .Site.Params.title }}
|
||||
<meta property="og:site_name" content="{{ . }}" />{{ end }}{{ with .Params.videos }}
|
||||
@@ -193,8 +193,8 @@ func (t *GoHTMLTemplate) EmbedTemplates() {
|
||||
<meta itemprop="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
|
||||
|
||||
{{if .IsPage}}{{ $ISO8601 := "2006-01-02T15:04:05-07:00" }}{{ if not .PublishDate.IsZero }}
|
||||
<meta itemprop="datePublished" content="{{ .PublishDate.Format $ISO8601 | safeHtml }}" />{{ end }}
|
||||
{{ if not .Date.IsZero }}<meta itemprop="dateModified" content="{{ .Date.Format $ISO8601 | safeHtml }}" />{{ end }}
|
||||
<meta itemprop="datePublished" content="{{ .PublishDate.Format $ISO8601 | safeHTML }}" />{{ end }}
|
||||
{{ if not .Date.IsZero }}<meta itemprop="dateModified" content="{{ .Date.Format $ISO8601 | safeHTML }}" />{{ end }}
|
||||
<meta itemprop="wordCount" content="{{ .WordCount }}">
|
||||
{{ with .Params.images }}{{ range first 6 . }}
|
||||
<meta itemprop="image" content="{{ . }}">
|
||||
|
@@ -38,7 +38,7 @@ type remoteLock struct {
|
||||
m map[string]*sync.Mutex
|
||||
}
|
||||
|
||||
// resLock locks an URL during download
|
||||
// URLLock locks an URL during download
|
||||
func (l *remoteLock) URLLock(url string) {
|
||||
l.Lock()
|
||||
if _, ok := l.m[url]; !ok {
|
||||
@@ -48,7 +48,7 @@ func (l *remoteLock) URLLock(url string) {
|
||||
l.m[url].Lock()
|
||||
}
|
||||
|
||||
// resUnlock unlocks an URL when the download has been finished. Use only in defer calls.
|
||||
// URLUnlock unlocks an URL when the download has been finished. Use only in defer calls.
|
||||
func (l *remoteLock) URLUnlock(url string) {
|
||||
l.RLock()
|
||||
defer l.RUnlock()
|
||||
@@ -57,7 +57,7 @@ func (l *remoteLock) URLUnlock(url string) {
|
||||
}
|
||||
}
|
||||
|
||||
// getFileID returns the cache ID for a string
|
||||
// getCacheFileID returns the cache ID for a string
|
||||
func getCacheFileID(id string) string {
|
||||
return viper.GetString("CacheDir") + url.QueryEscape(id)
|
||||
}
|
||||
@@ -173,9 +173,9 @@ func resGetResource(url string) ([]byte, error) {
|
||||
return resGetLocal(url, hugofs.SourceFs)
|
||||
}
|
||||
|
||||
// GetJson expects one or n-parts of a URL to a resource which can either be a local or a remote one.
|
||||
// GetJSON expects one or n-parts of a URL to a resource which can either be a local or a remote one.
|
||||
// If you provide multiple parts they will be joined together to the final URL.
|
||||
// GetJson returns nil or parsed JSON to use in a short code.
|
||||
// GetJSON returns nil or parsed JSON to use in a short code.
|
||||
func GetJSON(urlParts ...string) interface{} {
|
||||
url := strings.Join(urlParts, "")
|
||||
c, err := resGetResource(url)
|
||||
@@ -193,7 +193,7 @@ func GetJSON(urlParts ...string) interface{} {
|
||||
return v
|
||||
}
|
||||
|
||||
// parseCsv parses bytes of csv data into a slice slice string or an error
|
||||
// parseCSV parses bytes of CSV data into a slice slice string or an error
|
||||
func parseCSV(c []byte, sep string) ([][]string, error) {
|
||||
if len(sep) != 1 {
|
||||
return nil, errors.New("Incorrect length of csv separator: " + sep)
|
||||
@@ -206,11 +206,11 @@ func parseCSV(c []byte, sep string) ([][]string, error) {
|
||||
return r.ReadAll()
|
||||
}
|
||||
|
||||
// GetCsv expects a data separator and one or n-parts of a URL to a resource which
|
||||
// GetCSV expects a data separator and one or n-parts of a URL to a resource which
|
||||
// can either be a local or a remote one.
|
||||
// The data separator can be a comma, semi-colon, pipe, etc, but only one character.
|
||||
// If you provide multiple parts for the URL they will be joined together to the final URL.
|
||||
// GetCsv returns nil or a slice slice to use in a short code.
|
||||
// GetCSV returns nil or a slice slice to use in a short code.
|
||||
func GetCSV(sep string, urlParts ...string) [][]string {
|
||||
url := strings.Join(urlParts, "")
|
||||
c, err := resGetResource(url)
|
||||
|
@@ -999,10 +999,10 @@ func TestSafeHTML(t *testing.T) {
|
||||
buf.Reset()
|
||||
err = tmpl.Execute(buf, SafeHTML(this.str))
|
||||
if err != nil {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHtml returns unexpected error: %s", i, err)
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHTML returns unexpected error: %s", i, err)
|
||||
}
|
||||
if buf.String() != this.expectWithEscape {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHtml, got %v but expected %v", i, buf.String(), this.expectWithEscape)
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHTML, got %v but expected %v", i, buf.String(), this.expectWithEscape)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1034,10 +1034,10 @@ func TestSafeHTMLAttr(t *testing.T) {
|
||||
buf.Reset()
|
||||
err = tmpl.Execute(buf, SafeHTMLAttr(this.str))
|
||||
if err != nil {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHtmlAttr returns unexpected error: %s", i, err)
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHTMLAttr returns unexpected error: %s", i, err)
|
||||
}
|
||||
if buf.String() != this.expectWithEscape {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHtmlAttr, got %v but expected %v", i, buf.String(), this.expectWithEscape)
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHTMLAttr, got %v but expected %v", i, buf.String(), this.expectWithEscape)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1069,10 +1069,10 @@ func TestSafeCSS(t *testing.T) {
|
||||
buf.Reset()
|
||||
err = tmpl.Execute(buf, SafeCSS(this.str))
|
||||
if err != nil {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeCss returns unexpected error: %s", i, err)
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeCSS returns unexpected error: %s", i, err)
|
||||
}
|
||||
if buf.String() != this.expectWithEscape {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeCss, got %v but expected %v", i, buf.String(), this.expectWithEscape)
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeCSS, got %v but expected %v", i, buf.String(), this.expectWithEscape)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1104,10 +1104,10 @@ func TestSafeURL(t *testing.T) {
|
||||
buf.Reset()
|
||||
err = tmpl.Execute(buf, SafeURL(this.str))
|
||||
if err != nil {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeUrl returns unexpected error: %s", i, err)
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeURL returns unexpected error: %s", i, err)
|
||||
}
|
||||
if buf.String() != this.expectWithEscape {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeUrl, got %v but expected %v", i, buf.String(), this.expectWithEscape)
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeURL, got %v but expected %v", i, buf.String(), this.expectWithEscape)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user