1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 15:47:47 +01:00
gojekyll/commands/commands.go

32 lines
747 B
Go
Raw Permalink Normal View History

2017-07-19 22:06:43 +02:00
package commands
2017-06-18 22:54:58 +02:00
import (
"strings"
2017-06-22 17:02:32 +02:00
"github.com/osteele/gojekyll/pages"
2017-07-04 15:09:36 +02:00
"github.com/osteele/gojekyll/site"
2017-07-09 22:17:20 +02:00
"github.com/osteele/gojekyll/utils"
2017-06-18 22:54:58 +02:00
)
// If path starts with /, it's a URL path. Else it's a file path relative
// to the site source directory.
2017-07-04 15:09:36 +02:00
func pageFromPathOrRoute(s *site.Site, path string) (pages.Document, error) {
2017-06-22 16:37:31 +02:00
if path == "" {
path = "/"
2017-06-18 22:54:58 +02:00
}
2017-06-22 16:37:31 +02:00
switch {
case strings.HasPrefix(path, "/"):
page, found := s.URLPage(path)
if !found {
2017-07-09 22:17:20 +02:00
return nil, utils.NewPathError("render", path, "the site does not include a file with this URL path")
}
return page, nil
2017-06-22 16:37:31 +02:00
default:
2017-07-01 23:46:18 +02:00
page, found := s.FilePathPage(path)
2017-06-22 16:37:31 +02:00
if !found {
2017-07-09 22:17:20 +02:00
return nil, utils.NewPathError("render", path, "no such file")
2017-06-18 22:54:58 +02:00
}
2017-06-22 16:37:31 +02:00
return page, nil
2017-06-18 22:54:58 +02:00
}
}