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

95 lines
2.3 KiB
Go
Raw Normal View History

2017-07-04 15:09:36 +02:00
package pages
import (
2017-07-07 01:31:36 +02:00
"fmt"
2017-07-04 15:09:36 +02:00
"path"
"path/filepath"
"github.com/osteele/gojekyll/templates"
2017-07-09 22:17:20 +02:00
"github.com/osteele/gojekyll/utils"
2017-07-04 15:09:36 +02:00
)
// ToLiquid is part of the liquid.Drop interface.
func (d *StaticFile) ToLiquid() interface{} {
return map[string]interface{}{
"name": d.relpath,
"basename": utils.TrimExt(d.relpath),
"path": d.Permalink(),
"modified_time": d.fileModTime,
"extname": d.OutputExt(),
}
}
2017-07-04 15:09:36 +02:00
func (f *file) ToLiquid() interface{} {
var (
relpath = "/" + filepath.ToSlash(f.relpath)
base = path.Base(relpath)
ext = path.Ext(relpath)
)
return templates.MergeVariableMaps(f.frontMatter, map[string]interface{}{
"path": relpath,
"modified_time": f.fileModTime,
"name": base,
2017-07-09 22:17:20 +02:00
"basename": utils.TrimExt(base),
2017-07-04 15:09:36 +02:00
"extname": ext,
})
}
// ToLiquid is in the liquid.Drop interface.
func (p *page) ToLiquid() interface{} {
var (
relpath = p.relpath
ext = filepath.Ext(relpath)
2017-07-09 22:17:20 +02:00
root = utils.TrimExt(p.relpath)
2017-07-04 15:09:36 +02:00
base = filepath.Base(root)
)
data := map[string]interface{}{
2017-08-10 16:44:04 +02:00
"content": p.maybeContent(),
"excerpt": p.Excerpt(),
2017-07-07 01:31:36 +02:00
"path": relpath,
"url": p.Permalink(),
2017-08-10 16:44:04 +02:00
// "output": // TODO; includes layouts
2017-07-04 15:09:36 +02:00
// not documented, but present in both collection and non-collection pages
"permalink": p.Permalink(),
// TODO only in non-collection pages:
2017-08-10 16:44:04 +02:00
"dir": fmt.Sprintf("%c%s", filepath.Separator, path.Dir(relpath)),
2017-07-24 18:39:16 +02:00
"name": path.Base(relpath),
2017-07-04 15:09:36 +02:00
2017-08-10 16:44:04 +02:00
// TODO documented as present in all pages, but de facto only defined for collection pages
"id": base,
2017-07-04 15:09:36 +02:00
"categories": p.Categories(),
"tags": p.Tags(),
2017-08-10 16:44:04 +02:00
// "title": base,
2017-07-04 15:09:36 +02:00
// TODO Only present in collection pages https://jekyllrb.com/docs/collections/#documents
2017-07-24 15:32:57 +02:00
"relative_path": filepath.ToSlash(p.site.RelativePath(p.filename)),
2017-07-04 15:09:36 +02:00
// TODO collection(name)
// TODO undocumented; only present in collection pages:
"ext": ext,
}
for k, v := range p.frontMatter {
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
}
}
return data
}
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
}