1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 08:39:01 +01:00
gojekyll/commands/commands.go
2017-08-11 13:25:51 -04:00

32 lines
747 B
Go

package commands
import (
"strings"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/gojekyll/site"
"github.com/osteele/gojekyll/utils"
)
// If path starts with /, it's a URL path. Else it's a file path relative
// to the site source directory.
func pageFromPathOrRoute(s *site.Site, path string) (pages.Document, error) {
if path == "" {
path = "/"
}
switch {
case strings.HasPrefix(path, "/"):
page, found := s.URLPage(path)
if !found {
return nil, utils.NewPathError("render", path, "the site does not include a file with this URL path")
}
return page, nil
default:
page, found := s.FilePathPage(path)
if !found {
return nil, utils.NewPathError("render", path, "no such file")
}
return page, nil
}
}