mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 11:09:01 +01:00
page.Variables -> PageVariables
This commit is contained in:
parent
3297748f9e
commit
adf910d649
@ -79,21 +79,22 @@ func varsCommand(site *gojekyll.Site) error {
|
||||
for _, c := range site.Collections {
|
||||
siteData[c.Name] = fmt.Sprintf("<elided page data for %d items>", len(siteData[c.Name].([]templates.VariableMap)))
|
||||
}
|
||||
var data interface{} //templates.VariableMap
|
||||
var data templates.VariableMap
|
||||
// var data interface{} //templates.VariableMap
|
||||
switch {
|
||||
case *siteVariable:
|
||||
data = siteData
|
||||
case *dataVariable:
|
||||
data = siteData["data"].(templates.VariableMap)
|
||||
if *variablePath != "" {
|
||||
data = data.(templates.VariableMap)[*variablePath]
|
||||
data = data[*variablePath].(templates.VariableMap)
|
||||
}
|
||||
default:
|
||||
page, err := cliPage(site, *variablePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data = page.Variables()
|
||||
data = page.PageVariables()
|
||||
}
|
||||
b, err := yaml.Marshal(data)
|
||||
if err != nil {
|
||||
|
@ -43,7 +43,7 @@ func (c *Collection) Source() string { return filepath.Join(c.Site.Source, "_"+c
|
||||
// value of the collection.
|
||||
func (c *Collection) TemplateVariable() (d []templates.VariableMap) {
|
||||
for _, page := range c.Pages() {
|
||||
d = append(d, page.Variables())
|
||||
d = append(d, page.PageVariables())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ func newDynamicPageFromFile(filename string, f pageFields) (*DynamicPage, error)
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Variables returns the attributes of the template page object.
|
||||
func (p *DynamicPage) Variables() templates.VariableMap {
|
||||
// PageVariables returns the attributes of the template page object.
|
||||
func (p *DynamicPage) PageVariables() templates.VariableMap {
|
||||
var (
|
||||
relpath = p.relpath
|
||||
ext = filepath.Ext(relpath)
|
||||
@ -98,7 +98,7 @@ func (p *DynamicPage) Variables() templates.VariableMap {
|
||||
// TemplateContext returns the local variables for template evaluation
|
||||
func (p *DynamicPage) TemplateContext(ctx Context) templates.VariableMap {
|
||||
return templates.VariableMap{
|
||||
"page": p.Variables(),
|
||||
"page": p.PageVariables(),
|
||||
"site": ctx.SiteVariables(),
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ type Page interface {
|
||||
Write(Context, io.Writer) error
|
||||
|
||||
// Variables
|
||||
Variables() templates.VariableMap
|
||||
PageVariables() templates.VariableMap
|
||||
|
||||
// internal
|
||||
initPermalink() error
|
||||
@ -60,25 +60,25 @@ type Container interface {
|
||||
|
||||
// pageFields is embedded in StaticPage and DynamicPage
|
||||
type pageFields struct {
|
||||
container Container
|
||||
filename string
|
||||
relpath string // relative to site source directory
|
||||
outputExt string
|
||||
permalink string // cached permalink
|
||||
modTime time.Time
|
||||
frontMatter templates.VariableMap // page front matter, merged with defaults
|
||||
isMarkdown bool
|
||||
container Container
|
||||
filename string
|
||||
relpath string // relative to site source directory
|
||||
outputExt string
|
||||
permalink string // cached permalink
|
||||
modTime time.Time
|
||||
frontMatter templates.VariableMap
|
||||
isMarkdown bool
|
||||
}
|
||||
|
||||
func (p *pageFields) String() string {
|
||||
return fmt.Sprintf("%s{Path=%v, Permalink=%v}", reflect.TypeOf(p).Name(), p.relpath, p.permalink)
|
||||
}
|
||||
|
||||
func (p *pageFields) Path() string { return p.relpath }
|
||||
func (p *pageFields) Output() bool { return p.Published() }
|
||||
func (p *pageFields) OutputExt() string { return p.outputExt }
|
||||
func (p *pageFields) Path() string { return p.relpath }
|
||||
func (p *pageFields) Permalink() string { return p.permalink }
|
||||
func (p *pageFields) Published() bool { return p.frontMatter.Bool("published", true) }
|
||||
func (p *pageFields) OutputExt() string { return p.outputExt }
|
||||
func (p *pageFields) SiteRelPath() string { return p.relpath }
|
||||
|
||||
// NewPageFromFile reads a Page from a file, using defaults as the default front matter.
|
||||
@ -93,11 +93,11 @@ func NewPageFromFile(ctx Context, c Container, filename string, relpath string,
|
||||
}
|
||||
|
||||
fields := pageFields{
|
||||
container: c,
|
||||
filename: filename,
|
||||
container: c,
|
||||
filename: filename,
|
||||
frontMatter: defaults,
|
||||
modTime: info.ModTime(),
|
||||
relpath: relpath,
|
||||
modTime: info.ModTime(),
|
||||
relpath: relpath,
|
||||
}
|
||||
switch {
|
||||
case ctx.IsMarkdown(relpath):
|
||||
@ -127,18 +127,18 @@ func NewPageFromFile(ctx Context, c Container, filename string, relpath string,
|
||||
|
||||
// Variables returns the attributes of the template page object.
|
||||
// See https://jekyllrb.com/docs/variables/#page-variables
|
||||
func (p *pageFields) Variables() templates.VariableMap {
|
||||
func (p *pageFields) PageVariables() templates.VariableMap {
|
||||
var (
|
||||
relpath = "/" + filepath.ToSlash(p.relpath)
|
||||
base = path.Base(relpath)
|
||||
ext = path.Ext(relpath)
|
||||
)
|
||||
|
||||
return templates.VariableMap{
|
||||
return templates.MergeVariableMaps(p.frontMatter, templates.VariableMap{
|
||||
"path": relpath,
|
||||
"modified_time": p.modTime,
|
||||
"name": base,
|
||||
"basename": helpers.TrimExt(base),
|
||||
"extname": ext,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ package pages
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/osteele/gojekyll/templates"
|
||||
)
|
||||
|
||||
// StaticPage is a static page.
|
||||
@ -15,11 +13,6 @@ type StaticPage struct {
|
||||
// Static returns a bool indicating that the page is a static page.
|
||||
func (p *StaticPage) Static() bool { return true }
|
||||
|
||||
// Variables returns metadata for use in the representation of the page as a collection item
|
||||
func (p *StaticPage) Variables() templates.VariableMap {
|
||||
return templates.MergeVariableMaps(p.frontMatter, p.pageFields.Variables())
|
||||
}
|
||||
|
||||
func (p *StaticPage) Write(_ Context, w io.Writer) error {
|
||||
b, err := ioutil.ReadFile(p.filename)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user