mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
Create a TargetPath() method that provides OutFile
Moved the generation of the target path to the page breaking all dependecies on Site.
This commit is contained in:
@@ -52,7 +52,7 @@ type Page struct {
|
||||
}
|
||||
|
||||
type File struct {
|
||||
FileName, OutFile, Extension, Dir string
|
||||
FileName, Extension, Dir string
|
||||
}
|
||||
|
||||
type PageMeta struct {
|
||||
@@ -432,3 +432,27 @@ func (page *Page) convertRestructuredText(lines io.Reader) {
|
||||
page.Summary = template.HTML(getRstContent(summary))
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Page) TargetPath() (outfile string) {
|
||||
|
||||
// Always use Url if it's specified
|
||||
if len(strings.TrimSpace(p.Url)) > 2 {
|
||||
outfile = strings.TrimSpace(p.Url)
|
||||
|
||||
if strings.HasSuffix(outfile, "/") {
|
||||
outfile = outfile + "index.html"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if len(strings.TrimSpace(p.Slug)) > 0 {
|
||||
outfile = strings.TrimSpace(p.Slug) + "." + p.Extension
|
||||
} else {
|
||||
// Fall back to filename
|
||||
_, t := path.Split(p.FileName)
|
||||
outfile = replaceExtension(strings.TrimSpace(t), p.Extension)
|
||||
}
|
||||
|
||||
return path.Join(p.Dir, strings.TrimSpace(outfile))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user