1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 15:37:52 +01:00
gojekyll/config/pathnames.go

49 lines
1.4 KiB
Go
Raw Normal View History

2017-06-24 19:30:01 +02:00
package config
import (
"path/filepath"
"strings"
2017-07-09 22:17:20 +02:00
"github.com/osteele/gojekyll/utils"
2017-06-24 19:30:01 +02:00
)
// 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, ".")]
}
2017-07-09 15:37:23 +02:00
// IsSASSPath returns a boolean indicating whether the file is a Sass (".sass" or ".scss") file.
func (c *Config) IsSASSPath(name string) bool {
2017-06-24 19:30:01 +02:00
return strings.HasSuffix(name, ".sass") || strings.HasSuffix(name, ".scss")
}
2017-07-01 23:46:18 +02:00
// markdownExtensions returns a set of markdown extensions, without the initial dots.
2017-06-24 19:30:01 +02:00
func (c *Config) markdownExtensions() map[string]bool {
2017-07-01 23:46:18 +02:00
exts := strings.SplitN(c.MarkdownExt, `,`, -1)
2017-07-09 22:17:20 +02:00
return utils.StringArrayToMap(exts)
2017-07-01 23:46:18 +02:00
}
// MarkdownExtensions returns a list of markdown extensions, with dotsa.
func (c *Config) MarkdownExtensions() []string {
exts := strings.SplitN(c.MarkdownExt, `,`, -1)
2017-07-02 02:49:15 +02:00
for i, k := range exts {
2017-07-01 23:46:18 +02:00
exts[i] = "." + k
}
return exts
2017-06-24 19:30:01 +02:00
}
// OutputExt returns the pathname's output extension.
// This is generally the pathname extension;
// exceptions are *.md -> *.html, and *.{sass,scss} -> *.css.
2017-06-24 19:30:01 +02:00
func (c *Config) OutputExt(pathname string) string {
switch {
case c.IsMarkdown(pathname):
return ".html"
2017-07-09 15:37:23 +02:00
case c.IsSASSPath(pathname):
2017-06-24 19:30:01 +02:00
return ".css"
default:
return filepath.Ext(pathname)
}
}