1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-22 12:41:13 +01:00

Implement site.html_pages

This commit is contained in:
Oliver Steele 2017-07-07 12:24:00 -04:00
parent e43569d14f
commit 3fb43c65ab
4 changed files with 31 additions and 18 deletions

View File

@ -2,7 +2,6 @@ package pages
import (
"io"
"time"
"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pipelines"
@ -32,18 +31,6 @@ type Document interface {
setPermalink() error
}
// Page is a document with frontmatter.
type Page interface {
Document
// Content asks a page to compute its content.
// This has the side effect of causing the content to subsequently appear in the drop.
Content(rc RenderingContext) ([]byte, error)
// PostDate returns the date computed from the filename or frontmatter.
// It is an uncaught error to call this on a page that is not a Post.
// TODO Should posts have their own interface?
PostDate() time.Time
}
// RenderingContext provides context information for rendering.
type RenderingContext interface {
RenderingPipeline() pipelines.PipelineInterface

View File

@ -11,6 +11,18 @@ import (
"github.com/osteele/liquid/evaluator"
)
// Page is a document with frontmatter.
type Page interface {
Document
// Content asks a page to compute its content.
// This has the side effect of causing the content to subsequently appear in the drop.
Content(rc RenderingContext) ([]byte, error)
// PostDate returns the date computed from the filename or frontmatter.
// It is an uncaught error to call this on a page that is not a Post.
// TODO Should posts have their own interface?
PostDate() time.Time
}
type page struct {
file
raw []byte

View File

@ -3,6 +3,7 @@ package site
import (
"time"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/gojekyll/templates"
"github.com/osteele/liquid/evaluator"
)
@ -31,12 +32,12 @@ func (s *Site) initializeDrop() {
vars := templates.MergeVariableMaps(s.config.Variables, map[string]interface{}{
"data": s.data,
"documents": s.docs,
// "collections": s.computeCollections(), // generics.MustConvert(s.config.Collections, reflect.TypeOf([]interface{}{})),
// TODO read time from _config, if it's available
"time": time.Now(),
"html_pages": s.htmlPages(),
"pages": s.Pages(),
"static_files": s.StaticFiles(),
// TODO pages, static_files, html_pages, html_files, documents, tags.TAG
"time": time.Now(),
// TODO static_files, html_files, tags.TAG
})
collections := []interface{}{}
for _, c := range s.Collections {
@ -57,3 +58,12 @@ func (s *Site) setPageContent() error {
}
return nil
}
func (s *Site) htmlPages() (out []pages.Page) {
for _, p := range s.Pages() {
if p.OutputExt() == ".html" {
out = append(out, p)
}
}
return
}

View File

@ -36,9 +36,13 @@ func TestSite_ToLiquid_time(t *testing.T) {
func TestSite_ToLiquid_pages(t *testing.T) {
drop := readTestSiteDrop(t)
pages, ok := drop["pages"].([]pages.Page)
ps, ok := drop["pages"].([]pages.Page)
require.True(t, ok, fmt.Sprintf("pages has type %T", drop["pages"]))
require.Len(t, pages, 3)
require.Len(t, ps, 3)
ps, ok = drop["html_pages"].([]pages.Page)
require.True(t, ok, fmt.Sprintf("pages has type %T", drop["pages"]))
require.Len(t, ps, 3)
}
func TestSite_ToLiquid_posts(t *testing.T) {