mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-20 19:04:37 +00:00
Apply some more Golint suggestions
This commit is contained in:
parent
224a2ddf3c
commit
e685dfc0c6
2 changed files with 43 additions and 37 deletions
|
@ -379,9 +379,9 @@ func NewWatcher(port int) error {
|
||||||
case evs := <-watcher.Event:
|
case evs := <-watcher.Event:
|
||||||
jww.INFO.Println("File System Event:", evs)
|
jww.INFO.Println("File System Event:", evs)
|
||||||
|
|
||||||
static_changed := false
|
staticChanged := false
|
||||||
dynamic_changed := false
|
dynamicChanged := false
|
||||||
static_files_changed := make(map[string]bool)
|
staticFilesChanged := make(map[string]bool)
|
||||||
|
|
||||||
for _, ev := range evs {
|
for _, ev := range evs {
|
||||||
ext := filepath.Ext(ev.Name)
|
ext := filepath.Ext(ev.Name)
|
||||||
|
@ -395,12 +395,12 @@ func NewWatcher(port int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
isstatic := strings.HasPrefix(ev.Name, helpers.GetStaticDirPath()) || strings.HasPrefix(ev.Name, helpers.GetThemesDirPath())
|
isstatic := strings.HasPrefix(ev.Name, helpers.GetStaticDirPath()) || strings.HasPrefix(ev.Name, helpers.GetThemesDirPath())
|
||||||
static_changed = static_changed || isstatic
|
staticChanged = staticChanged || isstatic
|
||||||
dynamic_changed = dynamic_changed || !isstatic
|
dynamicChanged = dynamicChanged || !isstatic
|
||||||
|
|
||||||
if isstatic {
|
if isstatic {
|
||||||
if staticPath, err := helpers.MakeStaticPathRelative(ev.Name); err == nil {
|
if staticPath, err := helpers.MakeStaticPathRelative(ev.Name); err == nil {
|
||||||
static_files_changed[staticPath] = true
|
staticFilesChanged[staticPath] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ func NewWatcher(port int) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if static_changed {
|
if staticChanged {
|
||||||
jww.FEEDBACK.Println("Static file changed, syncing\n")
|
jww.FEEDBACK.Println("Static file changed, syncing\n")
|
||||||
utils.StopOnErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", helpers.AbsPathify(viper.GetString("PublishDir"))))
|
utils.StopOnErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", helpers.AbsPathify(viper.GetString("PublishDir"))))
|
||||||
|
|
||||||
|
@ -420,8 +420,8 @@ func NewWatcher(port int) error {
|
||||||
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initalized
|
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initalized
|
||||||
|
|
||||||
// force refresh when more than one file
|
// force refresh when more than one file
|
||||||
if len(static_files_changed) == 1 {
|
if len(staticFilesChanged) == 1 {
|
||||||
for path := range static_files_changed {
|
for path := range staticFilesChanged {
|
||||||
livereload.RefreshPath(path)
|
livereload.RefreshPath(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ func NewWatcher(port int) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if dynamic_changed {
|
if dynamicChanged {
|
||||||
fmt.Print("\nChange detected, rebuilding site\n")
|
fmt.Print("\nChange detected, rebuilding site\n")
|
||||||
const layout = "2006-01-02 15:04 -0700"
|
const layout = "2006-01-02 15:04 -0700"
|
||||||
fmt.Println(time.Now().Format(layout))
|
fmt.Println(time.Now().Format(layout))
|
||||||
|
|
|
@ -37,6 +37,7 @@ var SummaryLength = 70
|
||||||
// Custom divider <!--more--> let's user define where summarization ends.
|
// Custom divider <!--more--> let's user define where summarization ends.
|
||||||
var SummaryDivider = []byte("<!--more-->")
|
var SummaryDivider = []byte("<!--more-->")
|
||||||
|
|
||||||
|
// Blackfriday holds configuration values for Blackfriday rendering.
|
||||||
type Blackfriday struct {
|
type Blackfriday struct {
|
||||||
AngledQuotes bool
|
AngledQuotes bool
|
||||||
Fractions bool
|
Fractions bool
|
||||||
|
@ -44,6 +45,7 @@ type Blackfriday struct {
|
||||||
Extensions []string
|
Extensions []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewBlackfriday creates a new Blackfriday with some sane defaults.
|
||||||
func NewBlackfriday() *Blackfriday {
|
func NewBlackfriday() *Blackfriday {
|
||||||
return &Blackfriday{
|
return &Blackfriday{
|
||||||
AngledQuotes: false,
|
AngledQuotes: false,
|
||||||
|
@ -77,28 +79,27 @@ func StripHTML(s string) string {
|
||||||
// Shortcut strings with no tags in them
|
// Shortcut strings with no tags in them
|
||||||
if !strings.ContainsAny(s, "<>") {
|
if !strings.ContainsAny(s, "<>") {
|
||||||
return s
|
return s
|
||||||
} else {
|
}
|
||||||
s = stripHTMLReplacer.Replace(s)
|
s = stripHTMLReplacer.Replace(s)
|
||||||
|
|
||||||
// Walk through the string removing all tags
|
// Walk through the string removing all tags
|
||||||
b := bp.GetBuffer()
|
b := bp.GetBuffer()
|
||||||
defer bp.PutBuffer(b)
|
defer bp.PutBuffer(b)
|
||||||
|
|
||||||
inTag := false
|
inTag := false
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
switch r {
|
switch r {
|
||||||
case '<':
|
case '<':
|
||||||
inTag = true
|
inTag = true
|
||||||
case '>':
|
case '>':
|
||||||
inTag = false
|
inTag = false
|
||||||
default:
|
default:
|
||||||
if !inTag {
|
if !inTag {
|
||||||
b.WriteRune(r)
|
b.WriteRune(r)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return b.String()
|
|
||||||
}
|
}
|
||||||
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// StripEmptyNav strips out empty <nav> tags from content.
|
// StripEmptyNav strips out empty <nav> tags from content.
|
||||||
|
@ -111,6 +112,7 @@ func BytesToHTML(b []byte) template.HTML {
|
||||||
return template.HTML(string(b))
|
return template.HTML(string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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{
|
renderParameters := blackfriday.HtmlRendererParameters{
|
||||||
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
||||||
|
@ -141,7 +143,7 @@ func GetHtmlRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Render
|
||||||
return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
|
return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMarkdownExtensions(ctx *RenderingContext) int {
|
func getMarkdownExtensions(ctx *RenderingContext) int {
|
||||||
flags := 0 | blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
|
flags := 0 | blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
|
||||||
blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE |
|
blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE |
|
||||||
blackfriday.EXTENSION_AUTOLINK | blackfriday.EXTENSION_STRIKETHROUGH |
|
blackfriday.EXTENSION_AUTOLINK | blackfriday.EXTENSION_STRIKETHROUGH |
|
||||||
|
@ -155,15 +157,15 @@ func GetMarkdownExtensions(ctx *RenderingContext) int {
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func MarkdownRender(ctx *RenderingContext) []byte {
|
func markdownRender(ctx *RenderingContext) []byte {
|
||||||
return blackfriday.Markdown(ctx.Content, GetHtmlRenderer(0, ctx),
|
return blackfriday.Markdown(ctx.Content, GetHtmlRenderer(0, ctx),
|
||||||
GetMarkdownExtensions(ctx))
|
getMarkdownExtensions(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func MarkdownRenderWithTOC(ctx *RenderingContext) []byte {
|
func markdownRenderWithTOC(ctx *RenderingContext) []byte {
|
||||||
return blackfriday.Markdown(ctx.Content,
|
return blackfriday.Markdown(ctx.Content,
|
||||||
GetHtmlRenderer(blackfriday.HTML_TOC, ctx),
|
GetHtmlRenderer(blackfriday.HTML_TOC, ctx),
|
||||||
GetMarkdownExtensions(ctx))
|
getMarkdownExtensions(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractTOC extracts Table of Contents from content.
|
// ExtractTOC extracts Table of Contents from content.
|
||||||
|
@ -202,6 +204,8 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RenderingContext holds contextual information, like content and configuration,
|
||||||
|
// for a given content renderin.g
|
||||||
type RenderingContext struct {
|
type RenderingContext struct {
|
||||||
Content []byte
|
Content []byte
|
||||||
PageFmt string
|
PageFmt string
|
||||||
|
@ -219,23 +223,25 @@ func (c *RenderingContext) getConfig() *Blackfriday {
|
||||||
return c.Config
|
return c.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RenderBytesWithTOC renders a []byte with table of contents included.
|
||||||
func RenderBytesWithTOC(ctx *RenderingContext) []byte {
|
func RenderBytesWithTOC(ctx *RenderingContext) []byte {
|
||||||
switch ctx.PageFmt {
|
switch ctx.PageFmt {
|
||||||
default:
|
default:
|
||||||
return MarkdownRenderWithTOC(ctx)
|
return markdownRenderWithTOC(ctx)
|
||||||
case "markdown":
|
case "markdown":
|
||||||
return MarkdownRenderWithTOC(ctx)
|
return markdownRenderWithTOC(ctx)
|
||||||
case "rst":
|
case "rst":
|
||||||
return []byte(GetRstContent(ctx.Content))
|
return []byte(GetRstContent(ctx.Content))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RenderBytes renders a []byte.
|
||||||
func RenderBytes(ctx *RenderingContext) []byte {
|
func RenderBytes(ctx *RenderingContext) []byte {
|
||||||
switch ctx.PageFmt {
|
switch ctx.PageFmt {
|
||||||
default:
|
default:
|
||||||
return MarkdownRender(ctx)
|
return markdownRender(ctx)
|
||||||
case "markdown":
|
case "markdown":
|
||||||
return MarkdownRender(ctx)
|
return markdownRender(ctx)
|
||||||
case "rst":
|
case "rst":
|
||||||
return []byte(GetRstContent(ctx.Content))
|
return []byte(GetRstContent(ctx.Content))
|
||||||
}
|
}
|
||||||
|
@ -250,7 +256,7 @@ func TotalWords(s string) int {
|
||||||
func WordCount(s string) map[string]int {
|
func WordCount(s string) map[string]int {
|
||||||
m := make(map[string]int)
|
m := make(map[string]int)
|
||||||
for _, f := range strings.Fields(s) {
|
for _, f := range strings.Fields(s) {
|
||||||
m[f] += 1
|
m[f]++
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
Loading…
Add table
Reference in a new issue