1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 18:37:50 +01:00
gojekyll/pages/drops.go

84 lines
2.1 KiB
Go
Raw Normal View History

2017-07-04 15:09:36 +02:00
package pages
import (
"path"
"path/filepath"
"github.com/osteele/gojekyll/frontmatter"
2017-07-09 22:17:20 +02:00
"github.com/osteele/gojekyll/utils"
2017-08-16 00:55:18 +02:00
"github.com/osteele/liquid"
2017-07-04 15:09:36 +02:00
)
// ToLiquid is part of the liquid.Drop interface.
func (d *StaticFile) ToLiquid() interface{} {
2017-08-16 00:55:18 +02:00
return liquid.IterationKeyedMap(map[string]interface{}{
"name": path.Base(d.relPath),
"basename": utils.TrimExt(path.Base(d.relPath)),
"path": d.Permalink(),
"modified_time": d.modTime,
"extname": d.OutputExt(),
// de facto:
"collection": nil,
2017-08-16 00:55:18 +02:00
})
}
2017-07-04 15:09:36 +02:00
func (f *file) ToLiquid() interface{} {
var (
relpath = "/" + filepath.ToSlash(f.relPath)
2017-07-04 15:09:36 +02:00
base = path.Base(relpath)
ext = path.Ext(relpath)
)
return liquid.IterationKeyedMap(f.fm.Merged(frontmatter.FrontMatter{
2017-07-04 15:09:36 +02:00
"path": relpath,
"modified_time": f.modTime,
2017-07-04 15:09:36 +02:00
"name": base,
2017-07-09 22:17:20 +02:00
"basename": utils.TrimExt(base),
2017-07-04 15:09:36 +02:00
"extname": ext,
2017-08-16 00:55:18 +02:00
}))
2017-07-04 15:09:36 +02:00
}
// ToLiquid is in the liquid.Drop interface.
func (p *page) ToLiquid() interface{} {
var (
fm = p.fm
relpath = p.relPath
siteRelPath = filepath.ToSlash(p.site.RelativePath(p.filename))
ext = filepath.Ext(relpath)
2017-07-04 15:09:36 +02:00
)
data := map[string]interface{}{
2017-08-20 22:51:51 +02:00
"categories": p.Categories(),
"content": p.maybeContent(),
"date": fm.Get("date", p.modTime),
2017-08-20 22:51:51 +02:00
"excerpt": p.Excerpt(),
"id": utils.TrimExt(p.Permalink()),
"path": siteRelPath,
"relative_path": siteRelPath,
"slug": fm.String("slug", utils.Slugify(utils.TrimExt(filepath.Base(p.relPath)))),
2017-08-20 22:51:51 +02:00
"tags": p.Tags(),
"url": p.Permalink(),
2017-07-04 15:09:36 +02:00
// de facto
2017-07-04 15:09:36 +02:00
"ext": ext,
}
for k, v := range p.fm {
2017-07-04 15:09:36 +02:00
switch k {
// doc implies these aren't present, but they appear to be present in a collection page:
// case "layout", "published":
case "permalink":
// omit this, in order to use the value above
default:
data[k] = v
}
}
2017-08-16 00:55:18 +02:00
return liquid.IterationKeyedMap(data)
2017-07-04 15:09:36 +02:00
}
2017-08-10 16:44:04 +02:00
func (p *page) maybeContent() interface{} {
2017-08-10 15:06:53 +02:00
p.RLock()
defer p.RUnlock()
2017-08-10 16:44:04 +02:00
if p.rendered {
return p.content
2017-07-10 19:23:51 +02:00
}
2017-08-10 16:44:04 +02:00
return p.raw
2017-07-10 19:23:51 +02:00
}