summaryrefslogtreecommitdiffstats
path: root/hugolib/page_output.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-22 00:25:55 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-27 15:43:56 +0200
commit1b2be5e878c0bd8c68731389e46bf1c6d3664635 (patch)
tree1174452aab6221fc940db4cd31821275a00c162f /hugolib/page_output.go
parentbaa29f6534fcd324dbade7dd6c32c90547e3fa4f (diff)
hugolib: Add OutputFormats with permalinks to Page
Diffstat (limited to 'hugolib/page_output.go')
-rw-r--r--hugolib/page_output.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/hugolib/page_output.go b/hugolib/page_output.go
index fa9a45190..cdc4a53d8 100644
--- a/hugolib/page_output.go
+++ b/hugolib/page_output.go
@@ -15,6 +15,7 @@ package hugolib
import (
"html/template"
+ "strings"
"sync"
"github.com/spf13/hugo/output"
@@ -109,3 +110,46 @@ func (p *PageOutput) Render(layout ...string) template.HTML {
func (p *Page) Render(layout ...string) template.HTML {
return p.mainPageOutput.Render(layout...)
}
+
+// OutputFormats holds a list of the relevant output formats for a given resource.
+type OutputFormats []*OutputFormat
+
+// And OutputFormat links to a representation of a resource.
+type OutputFormat struct {
+ f output.Format
+ p *Page
+}
+
+// TODO(bep) outputs consider just save this wrapper on Page.
+// OutputFormats gives the output formats for this Page.
+func (p *Page) OutputFormats() OutputFormats {
+ var o OutputFormats
+ for _, f := range p.outputFormats {
+ o = append(o, &OutputFormat{f: f, p: p})
+ }
+ return o
+}
+
+// Get gets a OutputFormat given its name, i.e. json, html etc.
+// It returns nil if not found.
+func (o OutputFormats) Get(name string) *OutputFormat {
+ name = strings.ToLower(name)
+ for _, f := range o {
+ if strings.ToLower(f.f.Name) == name {
+ return f
+ }
+ }
+ return nil
+}
+
+// Permalink returns the absolute permalink to this output format.
+func (o *OutputFormat) Permalink() string {
+ rel := o.p.createRelativePermalinkForOutputFormat(o.f)
+ return o.p.s.permalink(rel)
+}
+
+// Permalink returns the relative permalink to this output format.
+func (o *OutputFormat) RelPermalink() string {
+ rel := o.p.createRelativePermalinkForOutputFormat(o.f)
+ return o.p.s.PathSpec.PrependBasePath(rel)
+}