mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-26 19:24:45 +01:00
Rename Page methods
This commit is contained in:
parent
0344353d4d
commit
c64c4fe7cc
@ -86,7 +86,7 @@ func (c *Collection) readPost(path string, rel string) error {
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case f.Static():
|
||||
case f.IsStatic():
|
||||
return nil
|
||||
case f.Published() || c.cfg.Unpublished:
|
||||
p := f.(pages.Page) // f.Static() guarantees this
|
||||
|
@ -15,8 +15,8 @@ func renderCommand(site *site.Site) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.path("Render:", filepath.Join(site.SourceDir(), p.SourcePath()))
|
||||
logger.label("URL:", p.Permalink())
|
||||
logger.path("Render:", filepath.Join(site.SourceDir(), p.Source()))
|
||||
logger.label("URL:", p.URL())
|
||||
logger.label("Content:", "")
|
||||
return site.WriteDocument(os.Stdout, p)
|
||||
}
|
||||
|
@ -14,13 +14,13 @@ func routesCommand(site *site.Site) error {
|
||||
logger.label("Routes:", "")
|
||||
urls := []string{}
|
||||
for u, p := range site.Routes {
|
||||
if !(*dynamicRoutes && p.Static()) {
|
||||
if !(*dynamicRoutes && p.IsStatic()) {
|
||||
urls = append(urls, u)
|
||||
}
|
||||
}
|
||||
sort.Strings(urls)
|
||||
for _, u := range urls {
|
||||
filename := site.Routes[u].SourcePath()
|
||||
filename := site.Routes[u].Source()
|
||||
fmt.Printf(" %s -> %s\n", u, filename)
|
||||
}
|
||||
return nil
|
||||
|
@ -10,13 +10,13 @@ import (
|
||||
// A Document is a Jekyll post, page, or file.
|
||||
type Document interface {
|
||||
// Paths
|
||||
Permalink() string // relative URL path
|
||||
SourcePath() string
|
||||
URL() string // relative to site base
|
||||
Source() string
|
||||
OutputExt() string
|
||||
|
||||
// Output
|
||||
Published() bool
|
||||
Static() bool
|
||||
IsStatic() bool
|
||||
Write(io.Writer) error
|
||||
|
||||
Reload() error
|
||||
|
@ -14,7 +14,7 @@ func (d *StaticFile) ToLiquid() interface{} {
|
||||
return liquid.IterationKeyedMap(map[string]interface{}{
|
||||
"name": path.Base(d.relPath),
|
||||
"basename": utils.TrimExt(path.Base(d.relPath)),
|
||||
"path": d.Permalink(),
|
||||
"path": d.URL(),
|
||||
"modified_time": d.modTime,
|
||||
"extname": d.OutputExt(),
|
||||
// de facto:
|
||||
@ -50,12 +50,12 @@ func (p *page) ToLiquid() interface{} {
|
||||
"content": p.maybeContent(),
|
||||
"date": fm.Get("date", p.modTime),
|
||||
"excerpt": p.Excerpt(),
|
||||
"id": utils.TrimExt(p.Permalink()),
|
||||
"id": utils.TrimExt(p.URL()),
|
||||
"path": siteRelPath,
|
||||
"relative_path": siteRelPath,
|
||||
"slug": fm.String("slug", utils.Slugify(utils.TrimExt(filepath.Base(p.relPath)))),
|
||||
"tags": p.Tags(),
|
||||
"url": p.Permalink(),
|
||||
"url": p.URL(),
|
||||
|
||||
// de facto
|
||||
"ext": ext,
|
||||
|
@ -53,10 +53,10 @@ func (f *file) String() string {
|
||||
return fmt.Sprintf("%T{Path=%v, Permalink=%v}", f, f.relPath, f.permalink)
|
||||
}
|
||||
|
||||
func (f *file) OutputExt() string { return f.outputExt }
|
||||
func (f *file) Permalink() string { return f.permalink }
|
||||
func (f *file) Published() bool { return f.fm.Bool("published", true) }
|
||||
func (f *file) SourcePath() string { return f.filename }
|
||||
func (f *file) OutputExt() string { return f.outputExt }
|
||||
func (f *file) URL() string { return f.permalink }
|
||||
func (f *file) Published() bool { return f.fm.Bool("published", true) }
|
||||
func (f *file) Source() string { return f.filename }
|
||||
|
||||
// const requiresReloadError = error.Error("requires reload")
|
||||
|
||||
|
@ -40,20 +40,20 @@ type PageEmbed struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
// Permalink is in the pages.Page interface.
|
||||
func (p *PageEmbed) Permalink() string { return p.Path }
|
||||
// URL is in the pages.Page interface.
|
||||
func (p *PageEmbed) URL() string { return p.Path }
|
||||
|
||||
// OutputExt is in the pages.Page interface.
|
||||
func (p *PageEmbed) OutputExt() string { return path.Ext(p.Path) }
|
||||
|
||||
// SourcePath is in the pages.Page interface.
|
||||
func (p *PageEmbed) SourcePath() string { return "" }
|
||||
// Source is in the pages.Page interface.
|
||||
func (p *PageEmbed) Source() string { return "" }
|
||||
|
||||
// Published is in the pages.Page interface.
|
||||
func (p *PageEmbed) Published() bool { return true }
|
||||
|
||||
// Static is in the pages.Page interface.
|
||||
func (p *PageEmbed) Static() bool { return false } // FIXME means different things to different callers
|
||||
// IsStatic is in the pages.Page interface.
|
||||
func (p *PageEmbed) IsStatic() bool { return false } // FIXME means different things to different callers
|
||||
|
||||
// Reload is in the pages.Page interface.
|
||||
func (p *PageEmbed) Reload() error { return nil }
|
||||
@ -72,8 +72,8 @@ type page struct {
|
||||
rendered bool
|
||||
}
|
||||
|
||||
// Static is in the File interface.
|
||||
func (p *page) Static() bool { return false }
|
||||
// IsStatic is in the File interface.
|
||||
func (p *page) IsStatic() bool { return false }
|
||||
|
||||
func makePage(filename string, f file) (*page, error) {
|
||||
raw, lineNo, err := readFrontMatter(&f)
|
||||
|
@ -10,8 +10,8 @@ type StaticFile struct {
|
||||
file
|
||||
}
|
||||
|
||||
// Static is in the File interface.
|
||||
func (p *StaticFile) Static() bool { return true }
|
||||
// IsStatic is in the File interface.
|
||||
func (p *StaticFile) IsStatic() bool { return true }
|
||||
|
||||
func (p *StaticFile) Write(w io.Writer) error {
|
||||
in, err := os.Open(p.filename)
|
||||
|
@ -38,7 +38,7 @@ func (p jekyllDefaultLayout) PostInitPage(s Site, pg Page) error {
|
||||
switch {
|
||||
case pg.IsPost():
|
||||
ln = layoutNames[postLayout]
|
||||
case pg.Permalink() == "/":
|
||||
case pg.URL() == "/":
|
||||
ln = layoutNames[homeLayout]
|
||||
}
|
||||
if ln != "" {
|
||||
|
@ -43,7 +43,7 @@ type Site interface {
|
||||
type Page interface {
|
||||
FrontMatter() frontmatter.FrontMatter
|
||||
IsPost() bool
|
||||
Permalink() string
|
||||
URL() string
|
||||
}
|
||||
|
||||
// Lookup returns a plugin if it has been registered.
|
||||
|
@ -46,7 +46,7 @@ func (p jekyllRedirectFromPlugin) processRedirectFrom(site Site, ps []pages.Page
|
||||
redirections = []pages.Document{}
|
||||
)
|
||||
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)
|
||||
}
|
||||
for _, p := range ps {
|
||||
@ -68,7 +68,7 @@ func (p jekyllRedirectFromPlugin) processRedirectTo(site Site, ps []pages.Page)
|
||||
return err
|
||||
}
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
@ -108,6 +108,6 @@ func (s *Site) fileAffectsBuild(rel string) bool {
|
||||
|
||||
// returns true if changes to the site-relative paths invalidate doc
|
||||
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]
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func (s *Site) AddDocument(d pages.Document, output bool) {
|
||||
if d.Published() || s.cfg.Unpublished {
|
||||
s.docs = append(s.docs, d)
|
||||
if output {
|
||||
s.Routes[d.Permalink()] = d
|
||||
s.Routes[d.URL()] = d
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func (s *Site) SetAbsoluteURL(url string) {
|
||||
func (s *Site) FilenameURLs() map[string]string {
|
||||
urls := map[string]string{}
|
||||
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
|
||||
}
|
||||
@ -132,8 +132,8 @@ func (s *Site) KeepFile(filename string) 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.
|
||||
for _, p := range s.Routes {
|
||||
if p.SourcePath() != "" {
|
||||
if r, err := filepath.Rel(s.SourceDir(), p.SourcePath()); err == nil {
|
||||
if p.Source() != "" {
|
||||
if r, err := filepath.Rel(s.SourceDir(), p.Source()); err == nil {
|
||||
if r == rel {
|
||||
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.
|
||||
func (s *Site) FilenameURLPath(relpath string) (string, bool) {
|
||||
if p, found := s.FilePathPage(relpath); found {
|
||||
return p.Permalink(), true
|
||||
return p.URL(), true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
@ -54,14 +54,14 @@ func (s *Site) WriteFiles() (count int, err error) {
|
||||
|
||||
// WriteDoc writes a document to the destination directory.
|
||||
func (s *Site) WriteDoc(d pages.Document) error {
|
||||
from := d.SourcePath()
|
||||
rel := d.Permalink()
|
||||
if !d.Static() && filepath.Ext(rel) == "" {
|
||||
from := d.Source()
|
||||
rel := d.URL()
|
||||
if !d.IsStatic() && filepath.Ext(rel) == "" {
|
||||
rel = filepath.Join(rel, "index.html")
|
||||
}
|
||||
to := filepath.Join(s.DestDir(), rel)
|
||||
if s.cfg.Verbose {
|
||||
fmt.Println("create", to, "from", d.SourcePath())
|
||||
fmt.Println("create", to, "from", d.Source())
|
||||
}
|
||||
if s.cfg.DryRun {
|
||||
// FIXME render the page, just don't write it
|
||||
@ -72,7 +72,7 @@ func (s *Site) WriteDoc(d pages.Document) error {
|
||||
return err
|
||||
}
|
||||
switch {
|
||||
case d.Static():
|
||||
case d.IsStatic():
|
||||
return utils.CopyFileContents(to, from, 0644)
|
||||
default:
|
||||
return utils.VisitCreatedFile(to, func(w io.Writer) error {
|
||||
|
Loading…
Reference in New Issue
Block a user