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 {
|
2017-06-22 16:42:57 +02:00
|
|
|
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")
|
2017-06-22 16:42:57 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|