/
util.go
44 lines (37 loc) · 1.18 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package helpers
import (
"strings"
hugo "github.com/gohugoio/hugo/commands"
"github.com/sirupsen/logrus"
)
// FileIsListed returns true if the filename is in the list based on its suffix
func FileIsListed(filename string, list []string) bool {
for _, listed := range list {
if strings.HasSuffix(strings.ToLower(filename), strings.ToLower(listed)) {
return true
}
}
return false
}
// IsMarkdown returns true if a file is a Markdown file
func IsMarkdown(filename string) bool {
return strings.HasSuffix(strings.ToLower(filename), strings.ToLower(".md"))
}
// IsAsciidoc returns true if a file is a Asciidoc file
func IsAsciidoc(filename string) bool {
return strings.HasSuffix(strings.ToLower(filename), strings.ToLower(".adoc")) ||
strings.HasSuffix(strings.ToLower(filename), strings.ToLower(".asciidoc")) ||
strings.HasSuffix(strings.ToLower(filename), strings.ToLower(".asc"))
}
// HugoRun runs Hugo like the command line interface
func HugoRun(args []string) error {
response := hugo.Execute(args)
return response.Err
}
// Trace sets trace mode
func Trace() {
logrus.SetLevel(logrus.DebugLevel)
// Add line and filename to log
// This is slow
logrus.SetReportCaller(true)
}