1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-26 23:34:47 +01:00

Rename Page methods

This commit is contained in:
Oliver Steele 2017-09-02 13:53:50 -04:00
parent 0344353d4d
commit c64c4fe7cc
15 changed files with 40 additions and 40 deletions

View File

@ -86,7 +86,7 @@ func (c *Collection) readPost(path string, rel string) error {
switch { switch {
case err != nil: case err != nil:
return err return err
case f.Static(): case f.IsStatic():
return nil return nil
case f.Published() || c.cfg.Unpublished: case f.Published() || c.cfg.Unpublished:
p := f.(pages.Page) // f.Static() guarantees this p := f.(pages.Page) // f.Static() guarantees this

View File

@ -15,8 +15,8 @@ func renderCommand(site *site.Site) error {
if err != nil { if err != nil {
return err return err
} }
logger.path("Render:", filepath.Join(site.SourceDir(), p.SourcePath())) logger.path("Render:", filepath.Join(site.SourceDir(), p.Source()))
logger.label("URL:", p.Permalink()) logger.label("URL:", p.URL())
logger.label("Content:", "") logger.label("Content:", "")
return site.WriteDocument(os.Stdout, p) return site.WriteDocument(os.Stdout, p)
} }

View File

@ -14,13 +14,13 @@ func routesCommand(site *site.Site) error {
logger.label("Routes:", "") logger.label("Routes:", "")
urls := []string{} urls := []string{}
for u, p := range site.Routes { for u, p := range site.Routes {
if !(*dynamicRoutes && p.Static()) { if !(*dynamicRoutes && p.IsStatic()) {
urls = append(urls, u) urls = append(urls, u)
} }
} }
sort.Strings(urls) sort.Strings(urls)
for _, u := range urls { for _, u := range urls {
filename := site.Routes[u].SourcePath() filename := site.Routes[u].Source()
fmt.Printf(" %s -> %s\n", u, filename) fmt.Printf(" %s -> %s\n", u, filename)
} }
return nil return nil

View File

@ -10,13 +10,13 @@ import (
// A Document is a Jekyll post, page, or file. // A Document is a Jekyll post, page, or file.
type Document interface { type Document interface {
// Paths // Paths
Permalink() string // relative URL path URL() string // relative to site base
SourcePath() string Source() string
OutputExt() string OutputExt() string
// Output // Output
Published() bool Published() bool
Static() bool IsStatic() bool
Write(io.Writer) error Write(io.Writer) error
Reload() error Reload() error

View File

@ -14,7 +14,7 @@ func (d *StaticFile) ToLiquid() interface{} {
return liquid.IterationKeyedMap(map[string]interface{}{ return liquid.IterationKeyedMap(map[string]interface{}{
"name": path.Base(d.relPath), "name": path.Base(d.relPath),
"basename": utils.TrimExt(path.Base(d.relPath)), "basename": utils.TrimExt(path.Base(d.relPath)),
"path": d.Permalink(), "path": d.URL(),
"modified_time": d.modTime, "modified_time": d.modTime,
"extname": d.OutputExt(), "extname": d.OutputExt(),
// de facto: // de facto:
@ -50,12 +50,12 @@ func (p *page) ToLiquid() interface{} {
"content": p.maybeContent(), "content": p.maybeContent(),
"date": fm.Get("date", p.modTime), "date": fm.Get("date", p.modTime),
"excerpt": p.Excerpt(), "excerpt": p.Excerpt(),
"id": utils.TrimExt(p.Permalink()), "id": utils.TrimExt(p.URL()),
"path": siteRelPath, "path": siteRelPath,
"relative_path": siteRelPath, "relative_path": siteRelPath,
"slug": fm.String("slug", utils.Slugify(utils.TrimExt(filepath.Base(p.relPath)))), "slug": fm.String("slug", utils.Slugify(utils.TrimExt(filepath.Base(p.relPath)))),
"tags": p.Tags(), "tags": p.Tags(),
"url": p.Permalink(), "url": p.URL(),
// de facto // de facto
"ext": ext, "ext": ext,

View File

@ -54,9 +54,9 @@ func (f *file) String() string {
} }
func (f *file) OutputExt() string { return f.outputExt } func (f *file) OutputExt() string { return f.outputExt }
func (f *file) Permalink() string { return f.permalink } func (f *file) URL() string { return f.permalink }
func (f *file) Published() bool { return f.fm.Bool("published", true) } func (f *file) Published() bool { return f.fm.Bool("published", true) }
func (f *file) SourcePath() string { return f.filename } func (f *file) Source() string { return f.filename }
// const requiresReloadError = error.Error("requires reload") // const requiresReloadError = error.Error("requires reload")

View File

@ -40,20 +40,20 @@ type PageEmbed struct {
Path string Path string
} }
// Permalink is in the pages.Page interface. // URL is in the pages.Page interface.
func (p *PageEmbed) Permalink() string { return p.Path } func (p *PageEmbed) URL() string { return p.Path }
// OutputExt is in the pages.Page interface. // OutputExt is in the pages.Page interface.
func (p *PageEmbed) OutputExt() string { return path.Ext(p.Path) } func (p *PageEmbed) OutputExt() string { return path.Ext(p.Path) }
// SourcePath is in the pages.Page interface. // Source is in the pages.Page interface.
func (p *PageEmbed) SourcePath() string { return "" } func (p *PageEmbed) Source() string { return "" }
// Published is in the pages.Page interface. // Published is in the pages.Page interface.
func (p *PageEmbed) Published() bool { return true } func (p *PageEmbed) Published() bool { return true }
// Static is in the pages.Page interface. // IsStatic is in the pages.Page interface.
func (p *PageEmbed) Static() bool { return false } // FIXME means different things to different callers func (p *PageEmbed) IsStatic() bool { return false } // FIXME means different things to different callers
// Reload is in the pages.Page interface. // Reload is in the pages.Page interface.
func (p *PageEmbed) Reload() error { return nil } func (p *PageEmbed) Reload() error { return nil }
@ -72,8 +72,8 @@ type page struct {
rendered bool rendered bool
} }
// Static is in the File interface. // IsStatic is in the File interface.
func (p *page) Static() bool { return false } func (p *page) IsStatic() bool { return false }
func makePage(filename string, f file) (*page, error) { func makePage(filename string, f file) (*page, error) {
raw, lineNo, err := readFrontMatter(&f) raw, lineNo, err := readFrontMatter(&f)

View File

@ -10,8 +10,8 @@ type StaticFile struct {
file file
} }
// Static is in the File interface. // IsStatic is in the File interface.
func (p *StaticFile) Static() bool { return true } func (p *StaticFile) IsStatic() bool { return true }
func (p *StaticFile) Write(w io.Writer) error { func (p *StaticFile) Write(w io.Writer) error {
in, err := os.Open(p.filename) in, err := os.Open(p.filename)

View File

@ -38,7 +38,7 @@ func (p jekyllDefaultLayout) PostInitPage(s Site, pg Page) error {
switch { switch {
case pg.IsPost(): case pg.IsPost():
ln = layoutNames[postLayout] ln = layoutNames[postLayout]
case pg.Permalink() == "/": case pg.URL() == "/":
ln = layoutNames[homeLayout] ln = layoutNames[homeLayout]
} }
if ln != "" { if ln != "" {

View File

@ -43,7 +43,7 @@ type Site interface {
type Page interface { type Page interface {
FrontMatter() frontmatter.FrontMatter FrontMatter() frontmatter.FrontMatter
IsPost() bool IsPost() bool
Permalink() string URL() string
} }
// Lookup returns a plugin if it has been registered. // Lookup returns a plugin if it has been registered.

View File

@ -46,7 +46,7 @@ func (p jekyllRedirectFromPlugin) processRedirectFrom(site Site, ps []pages.Page
redirections = []pages.Document{} redirections = []pages.Document{}
) )
addRedirectFrom := func(from string, to pages.Page) { addRedirectFrom := func(from string, to pages.Page) {
r := redirectionDoc{pages.PageEmbed{Path: from}, prefix + to.Permalink()} r := redirectionDoc{pages.PageEmbed{Path: from}, prefix + to.URL()}
redirections = append(redirections, &r) redirections = append(redirections, &r)
} }
for _, p := range ps { for _, p := range ps {
@ -68,7 +68,7 @@ func (p jekyllRedirectFromPlugin) processRedirectTo(site Site, ps []pages.Page)
return err return err
} }
if len(sources) > 0 { if len(sources) > 0 {
r := redirectionDoc{pages.PageEmbed{Path: p.Permalink()}, sources[0]} r := redirectionDoc{pages.PageEmbed{Path: p.URL()}, sources[0]}
p.SetContent(r.Content()) p.SetContent(r.Content())
} }
} }

View File

@ -108,6 +108,6 @@ func (s *Site) fileAffectsBuild(rel string) bool {
// returns true if changes to the site-relative paths invalidate doc // returns true if changes to the site-relative paths invalidate doc
func (s *Site) invalidatesDoc(paths map[string]bool, d pages.Document) bool { func (s *Site) invalidatesDoc(paths map[string]bool, d pages.Document) bool {
rel := utils.MustRel(s.SourceDir(), d.SourcePath()) rel := utils.MustRel(s.SourceDir(), d.Source())
return paths[rel] return paths[rel]
} }

View File

@ -94,7 +94,7 @@ func (s *Site) AddDocument(d pages.Document, output bool) {
if d.Published() || s.cfg.Unpublished { if d.Published() || s.cfg.Unpublished {
s.docs = append(s.docs, d) s.docs = append(s.docs, d)
if output { if output {
s.Routes[d.Permalink()] = d s.Routes[d.URL()] = d
} }
} }
} }

View File

@ -118,7 +118,7 @@ func (s *Site) SetAbsoluteURL(url string) {
func (s *Site) FilenameURLs() map[string]string { func (s *Site) FilenameURLs() map[string]string {
urls := map[string]string{} urls := map[string]string{}
for _, page := range s.Pages() { for _, page := range s.Pages() {
urls[utils.MustRel(s.SourceDir(), page.SourcePath())] = page.Permalink() urls[utils.MustRel(s.SourceDir(), page.Source())] = page.URL()
} }
return urls return urls
} }
@ -132,8 +132,8 @@ func (s *Site) KeepFile(filename string) bool {
func (s *Site) FilePathPage(rel string) (pages.Document, bool) { func (s *Site) FilePathPage(rel string) (pages.Document, bool) {
// This looks wasteful. If it shows up as a hotspot, you know what to do. // This looks wasteful. If it shows up as a hotspot, you know what to do.
for _, p := range s.Routes { for _, p := range s.Routes {
if p.SourcePath() != "" { if p.Source() != "" {
if r, err := filepath.Rel(s.SourceDir(), p.SourcePath()); err == nil { if r, err := filepath.Rel(s.SourceDir(), p.Source()); err == nil {
if r == rel { if r == rel {
return p, true return p, true
} }
@ -146,7 +146,7 @@ func (s *Site) FilePathPage(rel string) (pages.Document, bool) {
// FilenameURLPath returns a page's URL path, give a relative file path relative to the site source directory. // FilenameURLPath returns a page's URL path, give a relative file path relative to the site source directory.
func (s *Site) FilenameURLPath(relpath string) (string, bool) { func (s *Site) FilenameURLPath(relpath string) (string, bool) {
if p, found := s.FilePathPage(relpath); found { if p, found := s.FilePathPage(relpath); found {
return p.Permalink(), true return p.URL(), true
} }
return "", false return "", false
} }

View File

@ -54,14 +54,14 @@ func (s *Site) WriteFiles() (count int, err error) {
// WriteDoc writes a document to the destination directory. // WriteDoc writes a document to the destination directory.
func (s *Site) WriteDoc(d pages.Document) error { func (s *Site) WriteDoc(d pages.Document) error {
from := d.SourcePath() from := d.Source()
rel := d.Permalink() rel := d.URL()
if !d.Static() && filepath.Ext(rel) == "" { if !d.IsStatic() && filepath.Ext(rel) == "" {
rel = filepath.Join(rel, "index.html") rel = filepath.Join(rel, "index.html")
} }
to := filepath.Join(s.DestDir(), rel) to := filepath.Join(s.DestDir(), rel)
if s.cfg.Verbose { if s.cfg.Verbose {
fmt.Println("create", to, "from", d.SourcePath()) fmt.Println("create", to, "from", d.Source())
} }
if s.cfg.DryRun { if s.cfg.DryRun {
// FIXME render the page, just don't write it // FIXME render the page, just don't write it
@ -72,7 +72,7 @@ func (s *Site) WriteDoc(d pages.Document) error {
return err return err
} }
switch { switch {
case d.Static(): case d.IsStatic():
return utils.CopyFileContents(to, from, 0644) return utils.CopyFileContents(to, from, 0644)
default: default:
return utils.VisitCreatedFile(to, func(w io.Writer) error { return utils.VisitCreatedFile(to, func(w io.Writer) error {