2017-07-04 15:09:36 +02:00
|
|
|
package pages
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2017-07-05 18:44:38 +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{}{
|
2017-08-27 20:33:28 +02:00
|
|
|
"name": path.Base(d.relPath),
|
|
|
|
"basename": utils.TrimExt(path.Base(d.relPath)),
|
2017-09-02 19:53:50 +02:00
|
|
|
"path": d.URL(),
|
2017-08-27 20:33:28 +02:00
|
|
|
"modified_time": d.modTime,
|
2017-07-05 18:44:38 +02:00
|
|
|
"extname": d.OutputExt(),
|
2017-08-20 18:54:24 +02:00
|
|
|
// de facto:
|
|
|
|
"collection": nil,
|
2017-08-16 00:55:18 +02:00
|
|
|
})
|
2017-07-05 18:44:38 +02:00
|
|
|
}
|
|
|
|
|
2017-07-04 15:09:36 +02:00
|
|
|
func (f *file) ToLiquid() interface{} {
|
|
|
|
var (
|
2017-08-27 20:33:28 +02:00
|
|
|
relpath = "/" + filepath.ToSlash(f.relPath)
|
2017-07-04 15:09:36 +02:00
|
|
|
base = path.Base(relpath)
|
|
|
|
ext = path.Ext(relpath)
|
|
|
|
)
|
2017-09-03 18:21:55 +02:00
|
|
|
return liquid.IterationKeyedMap(f.fm.Merged(FrontMatter{
|
2017-07-04 15:09:36 +02:00
|
|
|
"path": relpath,
|
2017-08-27 20:33:28 +02:00
|
|
|
"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 (
|
2017-08-27 20:33:28 +02:00
|
|
|
fm = p.fm
|
|
|
|
relpath = p.relPath
|
2017-08-20 22:54:33 +02:00
|
|
|
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(),
|
2017-08-27 20:33:28 +02:00
|
|
|
"date": fm.Get("date", p.modTime),
|
2017-08-20 22:51:51 +02:00
|
|
|
"excerpt": p.Excerpt(),
|
2017-09-02 19:53:50 +02:00
|
|
|
"id": utils.TrimExt(p.URL()),
|
2017-08-20 22:54:33 +02:00
|
|
|
"path": siteRelPath,
|
|
|
|
"relative_path": siteRelPath,
|
2017-08-27 20:33:28 +02:00
|
|
|
"slug": fm.String("slug", utils.Slugify(utils.TrimExt(filepath.Base(p.relPath)))),
|
2017-08-20 22:51:51 +02:00
|
|
|
"tags": p.Tags(),
|
2017-09-02 19:53:50 +02:00
|
|
|
"url": p.URL(),
|
2017-07-04 15:09:36 +02:00
|
|
|
|
2017-08-20 18:54:24 +02:00
|
|
|
// de facto
|
2017-07-04 15:09:36 +02:00
|
|
|
"ext": ext,
|
|
|
|
}
|
2017-08-27 20:33:28 +02:00
|
|
|
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
|
|
|
}
|