add function permalink

This commit is contained in:
Fabrizio (Misto) Milo 2013-09-01 17:58:03 -07:00
parent 4237785263
commit 59a9e7eda5

View file

@ -428,8 +428,8 @@ func (s *Site) RenderIndexes() error {
} else {
n.Url = url + "/index.html"
}
n.Permalink = HTML(MakePermalink(string(n.Site.BaseUrl), string(plink)))
n.RSSlink = HTML(MakePermalink(string(n.Site.BaseUrl), string(url+".xml")))
n.Permalink = permalink(s, plink)
n.RSSlink = permalink(s, url+".xml")
n.Date = o[0].Date
n.Data[singular] = o
n.Data["Pages"] = o
@ -459,7 +459,7 @@ func (s *Site) RenderIndexes() error {
} else {
n.Url = Urlize(plural + "/" + k + "/" + "index.xml")
}
n.Permalink = HTML(string(n.Site.BaseUrl) + n.Url)
n.Permalink = permalink(s, n.Url)
s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
err = s.WritePublic(base+".xml", y.Bytes())
if err != nil {
@ -479,7 +479,7 @@ func (s *Site) RenderIndexesIndexes() (err error) {
n.Title = strings.Title(plural)
url := Urlize(plural)
n.Url = url + "/index.html"
n.Permalink = HTML(MakePermalink(string(n.Site.BaseUrl), string(n.Url)))
n.Permalink = permalink(s, n.Url)
n.Data["Singular"] = singular
n.Data["Plural"] = plural
n.Data["Index"] = s.Indexes[plural]
@ -504,8 +504,8 @@ func (s *Site) RenderLists() error {
n := s.NewNode()
n.Title = strings.Title(inflect.Pluralize(section))
n.Url = Urlize(section + "/" + "index.html")
n.Permalink = HTML(MakePermalink(string(n.Site.BaseUrl), string(n.Url)))
n.RSSlink = HTML(MakePermalink(string(n.Site.BaseUrl), string(section+".xml")))
n.Permalink = permalink(s, n.Url)
n.RSSlink = permalink(s, section+".xml")
n.Date = data[0].Date
n.Data["Pages"] = data
layout := "indexes/" + section + ".html"
@ -540,8 +540,8 @@ func (s *Site) RenderHomePage() error {
n := s.NewNode()
n.Title = n.Site.Title
n.Url = Urlize(string(n.Site.BaseUrl))
n.RSSlink = HTML(MakePermalink(string(n.Site.BaseUrl), string("index.xml")))
n.Permalink = HTML(string(n.Site.BaseUrl))
n.RSSlink = permalink(s, "index.xml")
n.Permalink = permalink(s, "")
if len(s.Pages) > 0 {
n.Date = s.Pages[0].Date
if len(s.Pages) < 9 {
@ -563,7 +563,7 @@ func (s *Site) RenderHomePage() error {
// XML Feed
n.Url = Urlize("index.xml")
n.Title = "Recent Content"
n.Permalink = HTML(string(n.Site.BaseUrl) + "index.xml")
n.Permalink = permalink(s, "index.xml")
y := s.NewXMLBuffer()
s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
err = s.WritePublic("index.xml", y.Bytes())
@ -573,7 +573,7 @@ func (s *Site) RenderHomePage() error {
if a := s.Tmpl.Lookup("404.html"); a != nil {
n.Url = Urlize("404.html")
n.Title = "404 Page not found"
n.Permalink = HTML(string(n.Site.BaseUrl) + "404.html")
n.Permalink = permalink(s, "404.html")
x, err := s.RenderThing(n, "404.html")
if err != nil {
return err
@ -592,6 +592,10 @@ func (s *Site) Stats() {
}
}
func permalink(s *Site, plink string) HTML {
return HTML(MakePermalink(string(s.Info.BaseUrl), plink))
}
func (s *Site) NewNode() *Node {
return &Node{
Data: make(map[string]interface{}),