Skip to content

Commit

Permalink
Re-export FrontMatter from pages
Browse files Browse the repository at this point in the history
  • Loading branch information
osteele committed Jun 16, 2021
1 parent 9240857 commit 1b6ef60
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 24 deletions.
3 changes: 1 addition & 2 deletions collection/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"
"sort"

"github.com/osteele/gojekyll/frontmatter"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/gojekyll/utils"
)
Expand Down Expand Up @@ -77,7 +76,7 @@ func (c *Collection) readPost(path string, rel string) error {
case strategy.isFuture(rel) && !c.cfg.Future:
return nil
}
fm := frontmatter.FrontMatter{
fm := pages.FrontMatter{
"collection": c.Name,
"permalink": c.PermalinkPattern(),
}.Merged(c.cfg.GetFrontMatterDefaults(c.Name, siteRel))
Expand Down
3 changes: 1 addition & 2 deletions pages/drops.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"path"
"path/filepath"

"github.com/osteele/gojekyll/frontmatter"
"github.com/osteele/gojekyll/utils"
"github.com/osteele/liquid"
)
Expand All @@ -28,7 +27,7 @@ func (f *file) ToLiquid() interface{} {
base = path.Base(relpath)
ext = path.Ext(relpath)
)
return liquid.IterationKeyedMap(f.fm.Merged(frontmatter.FrontMatter{
return liquid.IterationKeyedMap(f.fm.Merged(FrontMatter{
"path": relpath,
"modified_time": f.modTime,
"name": base,
Expand Down
6 changes: 3 additions & 3 deletions pages/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ type file struct {
outputExt string
permalink string // cached permalink
modTime time.Time
dfm frontmatter.FrontMatter // default frontMatter
fm frontmatter.FrontMatter
dfm FrontMatter // default frontMatter
fm FrontMatter
}

// NewFile creates a Page or StaticFile.
//
// filename is the absolute filename. relpath is the path relative to the site or collection directory.
func NewFile(s Site, filename string, relpath string, fm frontmatter.FrontMatter) (Document, error) {
func NewFile(s Site, filename string, relpath string, fm FrontMatter) (Document, error) {
hasFM, err := frontmatter.FileHasFrontMatter(filename)
if err != nil {
return nil, err
Expand Down
7 changes: 5 additions & 2 deletions pages/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Page interface {
// This has the side effect of causing the content to subsequently appear in the drop.
Render() error
SetContent(string)
FrontMatter() frontmatter.FrontMatter
FrontMatter() FrontMatter
// 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?
Expand All @@ -40,6 +40,9 @@ type PageEmbed struct {
Path string
}

// FrontMatter is from the frontmatter package.
type FrontMatter = frontmatter.FrontMatter

// URL is in the pages.Page interface.
func (p *PageEmbed) URL() string { return p.Path }

Expand Down Expand Up @@ -125,7 +128,7 @@ func readFrontMatter(f *file) (b []byte, lineNo int, err error) {
return
}

func (p *page) FrontMatter() frontmatter.FrontMatter {
func (p *page) FrontMatter() FrontMatter {
return p.fm
}

Expand Down
5 changes: 2 additions & 3 deletions pages/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/frontmatter"
"github.com/osteele/gojekyll/utils"
"github.com/stretchr/testify/require"
)
Expand All @@ -31,7 +30,7 @@ func TestPage_TemplateContext(t *testing.T) {

func TestPage_Categories(t *testing.T) {
s := siteFake{t, config.Default()}
fm := frontmatter.FrontMatter{"categories": "b a"}
fm := FrontMatter{"categories": "b a"}
f := file{site: s, fm: fm}
p := page{file: f}
require.Equal(t, []string{"a", "b"}, p.Categories())
Expand Down Expand Up @@ -61,7 +60,7 @@ func fakePageFromFile(t *testing.T, file string) (Document, error) {
siteFake{t, config.Default()},
filepath.Join("testdata", file),
file,
frontmatter.FrontMatter{},
FrontMatter{},
)
}

Expand Down
2 changes: 1 addition & 1 deletion pages/permalinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestExpandPermalinkPattern(t *testing.T) {
)

testPermalinkPattern := func(pattern, path string, data map[string]interface{}) (string, error) {
fm := frontmatter.Merge(data, frontmatter.FrontMatter{"permalink": pattern})
fm := frontmatter.Merge(data, FrontMatter{"permalink": pattern})
ext := filepath.Ext(path)
switch ext {
case ".md", ".markdown":
Expand Down
14 changes: 7 additions & 7 deletions plugins/avatar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/frontmatter"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/liquid"
"github.com/stretchr/testify/require"
)
Expand All @@ -15,12 +15,12 @@ type siteFake struct {
e *liquid.Engine
}

func (s siteFake) AddHTMLPage(string, string, frontmatter.FrontMatter) {}
func (s siteFake) Config() *config.Config { return &s.c }
func (s siteFake) HasLayout(string) bool { return true }
func (s siteFake) Pages() []Page { return nil }
func (s siteFake) Posts() []Page { return nil }
func (s siteFake) TemplateEngine() *liquid.Engine { return s.e }
func (s siteFake) AddHTMLPage(string, string, pages.FrontMatter) {}
func (s siteFake) Config() *config.Config { return &s.c }
func (s siteFake) HasLayout(string) bool { return true }
func (s siteFake) Pages() []Page { return nil }
func (s siteFake) Posts() []Page { return nil }
func (s siteFake) TemplateEngine() *liquid.Engine { return s.e }

func TestAvatarTag(t *testing.T) {
engine := liquid.NewEngine()
Expand Down
3 changes: 1 addition & 2 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/kyokomi/emoji"
"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/frontmatter"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/gojekyll/utils"
"github.com/osteele/liquid"
Expand All @@ -31,7 +30,7 @@ type Plugin interface {

// Site is the site interface that is available to plugins.
type Site interface {
AddHTMLPage(url string, tpl string, fm frontmatter.FrontMatter)
AddHTMLPage(url string, tpl string, fm pages.FrontMatter)
Config() *config.Config
TemplateEngine() *liquid.Engine
Pages() []Page
Expand Down
3 changes: 1 addition & 2 deletions site/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"io"

"github.com/osteele/gojekyll/frontmatter"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/gojekyll/plugins"
"github.com/osteele/gojekyll/utils"
Expand All @@ -14,7 +13,7 @@ import (
)

// AddHTMLPage is in the plugins.Site interface.
func (s *Site) AddHTMLPage(url string, src string, fm frontmatter.FrontMatter) {
func (s *Site) AddHTMLPage(url string, src string, fm pages.FrontMatter) {
tpl, err := s.TemplateEngine().ParseTemplate([]byte(src))
if err != nil {
panic(err)
Expand Down

0 comments on commit 1b6ef60

Please sign in to comment.