-
Notifications
You must be signed in to change notification settings - Fork 13
/
pathnames.go
47 lines (40 loc) · 1.36 KB
/
pathnames.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
45
46
47
package config
import (
"path/filepath"
"strings"
"github.com/osteele/gojekyll/utils"
)
// IsMarkdown returns a boolean indicating whether the file is a Markdown file, according to the current project.
func (c *Config) IsMarkdown(name string) bool {
ext := filepath.Ext(name)
return c.markdownExtensions()[strings.TrimLeft(ext, ".")]
}
// IsSASSPath returns a boolean indicating whether the file is a Sass (".sass" or ".scss") file.
func (c *Config) IsSASSPath(name string) bool {
return strings.HasSuffix(name, ".sass") || strings.HasSuffix(name, ".scss")
}
// markdownExtensions returns a set of markdown extensions, without the initial dots.
func (c *Config) markdownExtensions() map[string]bool {
exts := strings.SplitN(c.MarkdownExt, `,`, -1)
return utils.StringArrayToMap(exts)
}
// MarkdownExtensions returns a list of markdown extensions, with dotsa.
func (c *Config) MarkdownExtensions() []string {
exts := strings.SplitN(c.MarkdownExt, `,`, -1)
for i, k := range exts {
exts[i] = "." + k
}
return exts
}
// OutputExt returns the pathname's output extension. This is generally the pathname extension;
// exception are *.md -> *.html, and *.{sass,scss} -> *.css.
func (c *Config) OutputExt(pathname string) string {
switch {
case c.IsMarkdown(pathname):
return ".html"
case c.IsSASSPath(pathname):
return ".css"
default:
return filepath.Ext(pathname)
}
}