mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 07:18:59 +01:00
Remove some uses of templates.VariableMap
This commit is contained in:
parent
899875e6f5
commit
f86956b5c8
@ -15,7 +15,6 @@ import (
|
||||
"github.com/osteele/gojekyll/pages"
|
||||
"github.com/osteele/gojekyll/server"
|
||||
"github.com/osteele/gojekyll/sites"
|
||||
"github.com/osteele/gojekyll/templates"
|
||||
)
|
||||
|
||||
// main sets this
|
||||
@ -78,16 +77,16 @@ func varsCommand(site *sites.Site) error {
|
||||
// (Actually it's circular, which the yaml package can't handle.)
|
||||
// Neuter it. This destroys it as Liquid data, but that's okay in this context.
|
||||
for _, c := range site.Collections {
|
||||
siteData[c.Name] = fmt.Sprintf("<elided page data for %d items>", len(siteData[c.Name].([]templates.VariableMap)))
|
||||
siteData[c.Name] = fmt.Sprintf("<elided page data for %d items>", len(siteData[c.Name].([]interface{})))
|
||||
}
|
||||
var data templates.VariableMap
|
||||
var data map[string]interface{}
|
||||
switch {
|
||||
case *siteVariable:
|
||||
data = siteData
|
||||
case *dataVariable:
|
||||
data = siteData["data"].(templates.VariableMap)
|
||||
data = siteData["data"].(map[string]interface{})
|
||||
if *variablePath != "" {
|
||||
data = data[*variablePath].(templates.VariableMap)
|
||||
data = data[*variablePath].(map[string]interface{})
|
||||
}
|
||||
default:
|
||||
page, err := pageFromPathOrRoute(site, *variablePath)
|
||||
|
@ -30,7 +30,7 @@ type Document interface {
|
||||
type RenderingContext interface {
|
||||
RenderingPipeline() pipelines.PipelineInterface
|
||||
// SiteVariables is the value of the "site" template variable.
|
||||
SiteVariables() templates.VariableMap // value of the "site" template variable
|
||||
SiteVariables() map[string]interface{} // value of the "site" template variable
|
||||
}
|
||||
|
||||
// Container is the document container.
|
||||
|
@ -91,7 +91,7 @@ func avatarTag(_ string) (func(io.Writer, chunks.RenderContext) error, error) {
|
||||
if user == "" {
|
||||
return fmt.Errorf("parse error in avatar tag parameters %s", args)
|
||||
}
|
||||
s := strings.Replace(avatarTemplate, "40", fmt.Sprint(size), -1)
|
||||
s := strings.Replace(avatarTemplate, "40", size, -1)
|
||||
s = strings.Replace(s, "{user}", user, -1)
|
||||
_, err = w.Write([]byte(s))
|
||||
return err
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"github.com/osteele/gojekyll/pages"
|
||||
"github.com/osteele/gojekyll/pipelines"
|
||||
"github.com/osteele/gojekyll/plugins"
|
||||
"github.com/osteele/gojekyll/templates"
|
||||
"github.com/osteele/liquid"
|
||||
)
|
||||
|
||||
@ -27,7 +26,7 @@ type Site struct {
|
||||
pipeline *pipelines.Pipeline
|
||||
pages []pages.Document // all pages, output or not
|
||||
preparedToRender bool
|
||||
siteVariables templates.VariableMap
|
||||
siteVariables map[string]interface{}
|
||||
}
|
||||
|
||||
func (s *Site) SourceDir() string { return s.config.Source }
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// SiteVariables returns the site variable for template evaluation.
|
||||
func (s *Site) SiteVariables() templates.VariableMap {
|
||||
func (s *Site) SiteVariables() map[string]interface{} {
|
||||
if len(s.siteVariables) == 0 {
|
||||
if err := s.initializeSiteVariables(); err != nil {
|
||||
panic(err)
|
||||
@ -21,15 +21,11 @@ func (s *Site) initializeSiteVariables() error {
|
||||
"data": s.data,
|
||||
// TODO read time from _config, if it's available
|
||||
"time": time.Now(),
|
||||
// TODO pages, posts, related_posts, static_files, html_pages, html_files, collections, data, documents, categories.CATEGORY, tags.TAG
|
||||
// TODO pages, static_files, html_pages, html_files, documents, categories.CATEGORY, tags.TAG
|
||||
})
|
||||
return s.setCollectionVariables(false)
|
||||
}
|
||||
|
||||
func normalizeMaps(value interface{}) interface{} {
|
||||
return value
|
||||
}
|
||||
|
||||
func (s *Site) setCollectionVariables(includeContent bool) error {
|
||||
for _, c := range s.Collections {
|
||||
pages, err := c.TemplateVariable(s, includeContent)
|
||||
@ -45,6 +41,9 @@ func (s *Site) setCollectionVariables(includeContent bool) error {
|
||||
s.siteVariables["related_posts"] = related
|
||||
}
|
||||
}
|
||||
// Set these here instead of initializeSiteVariables so that they're
|
||||
// re-generated once page.content has been rendered. Obviously
|
||||
// this method has the wrong name.
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user