mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 06:59:04 +01:00
Split page.Container and container.Site
This commit is contained in:
parent
1190cc556d
commit
23d5e16786
@ -12,34 +12,41 @@ import (
|
||||
|
||||
// Collection is a Jekyll collection https://jekyllrb.com/docs/collections/.
|
||||
type Collection struct {
|
||||
Name string
|
||||
Metadata map[string]interface{}
|
||||
container pages.Container
|
||||
pages []pages.Page
|
||||
Name string
|
||||
Metadata map[string]interface{}
|
||||
site Site
|
||||
pages []pages.Page
|
||||
}
|
||||
|
||||
// Site is the interface a site provides to collections it contains.
|
||||
type Site interface {
|
||||
AbsDir() string
|
||||
Config() config.Config
|
||||
OutputExt(pathname string) string
|
||||
}
|
||||
|
||||
// NewCollection creates a new Collection
|
||||
func NewCollection(name string, metadata map[string]interface{}, c pages.Container) *Collection {
|
||||
func NewCollection(name string, metadata map[string]interface{}, s Site) *Collection {
|
||||
return &Collection{
|
||||
Name: name,
|
||||
Metadata: metadata,
|
||||
container: c,
|
||||
Name: name,
|
||||
Metadata: metadata,
|
||||
site: s,
|
||||
}
|
||||
}
|
||||
|
||||
// Config is in the page.Container interface.
|
||||
func (c *Collection) Config() config.Config {
|
||||
return c.container.Config()
|
||||
return c.site.Config()
|
||||
}
|
||||
|
||||
// OutputExt is in the page.Container interface.
|
||||
func (c *Collection) OutputExt(pathname string) string {
|
||||
return c.container.OutputExt(pathname)
|
||||
return c.site.OutputExt(pathname)
|
||||
}
|
||||
|
||||
// AbsDir is in the page.Container interface.
|
||||
func (c *Collection) AbsDir() string {
|
||||
return filepath.Join(c.container.AbsDir(), c.PathPrefix())
|
||||
return filepath.Join(c.site.AbsDir(), c.PathPrefix())
|
||||
}
|
||||
|
||||
// PathPrefix is in the page.Container interface.
|
||||
|
@ -3,7 +3,6 @@ package pages
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/osteele/gojekyll/config"
|
||||
"github.com/osteele/gojekyll/pipelines"
|
||||
)
|
||||
|
||||
@ -36,8 +35,6 @@ type RenderingContext interface {
|
||||
// Container is the document container.
|
||||
// It's either the Site or Collection that immediately contains the document.
|
||||
type Container interface {
|
||||
AbsDir() string
|
||||
Config() config.Config
|
||||
OutputExt(pathname string) string
|
||||
PathPrefix() string // PathPrefix is the relative prefix, "" for the site and "_coll/" for a collection
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ type file struct {
|
||||
frontMatter map[string]interface{}
|
||||
}
|
||||
|
||||
func (p *file) String() string {
|
||||
return fmt.Sprintf("%s{Path=%v, Permalink=%v}", reflect.TypeOf(p).Name(), p.relpath, p.permalink)
|
||||
func (f *file) String() string {
|
||||
return fmt.Sprintf("%s{Path=%v, Permalink=%v}", reflect.TypeOf(f).Name(), f.relpath, f.permalink)
|
||||
}
|
||||
|
||||
func (f *file) OutputExt() string { return f.outputExt }
|
||||
@ -72,24 +72,24 @@ func NewFile(filename string, c Container, relpath string, defaults map[string]i
|
||||
|
||||
// Variables returns the attributes of the template page object.
|
||||
// See https://jekyllrb.com/docs/variables/#page-variables
|
||||
func (p *file) PageVariables() map[string]interface{} {
|
||||
func (f *file) PageVariables() map[string]interface{} {
|
||||
var (
|
||||
relpath = "/" + filepath.ToSlash(p.relpath)
|
||||
relpath = "/" + filepath.ToSlash(f.relpath)
|
||||
base = path.Base(relpath)
|
||||
ext = path.Ext(relpath)
|
||||
)
|
||||
|
||||
return templates.MergeVariableMaps(p.frontMatter, map[string]interface{}{
|
||||
return templates.MergeVariableMaps(f.frontMatter, map[string]interface{}{
|
||||
"path": relpath,
|
||||
"modified_time": p.fileModTime,
|
||||
"modified_time": f.fileModTime,
|
||||
"name": base,
|
||||
"basename": helpers.TrimExt(base),
|
||||
"extname": ext,
|
||||
})
|
||||
}
|
||||
|
||||
func (p *file) categories() []string {
|
||||
if v, found := p.frontMatter["categories"]; found {
|
||||
func (f *file) categories() []string {
|
||||
if v, found := f.frontMatter["categories"]; found {
|
||||
switch v := v.(type) {
|
||||
case string:
|
||||
return strings.Fields(v)
|
||||
@ -109,5 +109,5 @@ func (p *file) categories() []string {
|
||||
panic("unimplemented")
|
||||
}
|
||||
}
|
||||
return []string{templates.VariableMap(p.frontMatter).String("category", "")}
|
||||
return []string{templates.VariableMap(f.frontMatter).String("category", "")}
|
||||
}
|
||||
|
@ -10,12 +10,12 @@ import (
|
||||
"github.com/osteele/gojekyll/templates"
|
||||
)
|
||||
|
||||
// Page is a post or collection page.
|
||||
type Page interface {
|
||||
Document
|
||||
Content(rc RenderingContext) ([]byte, error)
|
||||
}
|
||||
|
||||
// Page is a post or collection page.
|
||||
type page struct {
|
||||
file
|
||||
raw []byte
|
||||
|
@ -86,7 +86,7 @@ func (s *Site) readFiles() error {
|
||||
// AddDocument adds a page to the site structures.
|
||||
func (s *Site) AddDocument(p pages.Document, output bool) {
|
||||
if p.Published() || s.config.Unpublished {
|
||||
s.pages = append(s.pages, p)
|
||||
s.docs = append(s.docs, p)
|
||||
if output {
|
||||
s.Routes[p.Permalink()] = p
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ type Site struct {
|
||||
data map[string]interface{}
|
||||
flags config.Flags
|
||||
pipeline *pipelines.Pipeline
|
||||
pages []pages.Document // all pages, output or not
|
||||
docs []pages.Document // all documents, whether or not they are output
|
||||
preparedToRender bool
|
||||
siteVariables map[string]interface{}
|
||||
}
|
||||
@ -51,7 +51,7 @@ func (s *Site) OutputPages() []pages.Document {
|
||||
}
|
||||
|
||||
// Pages returns all the pages, output or not.
|
||||
func (s *Site) Pages() []pages.Document { return s.pages }
|
||||
func (s *Site) Pages() []pages.Document { return s.docs }
|
||||
|
||||
// AbsDir is in the page.Container interface.
|
||||
func (s *Site) AbsDir() string {
|
||||
|
Loading…
Reference in New Issue
Block a user