// RenderSectionLists renders a page for each section func (s *Site) RenderSectionLists() error { for section, data := range s.Sections { // section keys can be lower case (depending on site.pathifyTaxonomyKeys) // extract the original casing from the first page to get sensible titles. sectionName := section if !s.Info.preserveTaxonomyNames && len(data) > 0 { sectionName = data[0].Page.Section() } layouts := s.appendThemeTemplates( []string{"section/" + section + ".html", "_default/section.html", "_default/list.html", "indexes/" + section + ".html", "_default/indexes.html"}) if s.Info.preserveTaxonomyNames { section = helpers.MakePathSanitized(section) } n := s.newSectionListNode(sectionName, section, data) if err := s.renderAndWritePage(fmt.Sprintf("section %s", section), section, n, s.appendThemeTemplates(layouts)...); err != nil { return err } if n.paginator != nil { paginatePath := viper.GetString("paginatePath") // write alias for page 1 s.WriteDestAlias(helpers.PaginateAliasPath(section, 1), s.permalink(section)) pagers := n.paginator.Pagers() for i, pager := range pagers { if i == 0 { // already created continue } sectionPagerNode := s.newSectionListNode(sectionName, section, data) sectionPagerNode.paginator = pager if pager.TotalPages() > 0 { first, _ := pager.page(0) sectionPagerNode.Date = first.Date sectionPagerNode.Lastmod = first.Lastmod } pageNumber := i + 1 htmlBase := fmt.Sprintf("/%s/%s/%d", section, paginatePath, pageNumber) if err := s.renderAndWritePage(fmt.Sprintf("section %s", section), filepath.FromSlash(htmlBase), sectionPagerNode, layouts...); err != nil { return err } } } if !viper.GetBool("DisableRSS") && section != "" { // XML Feed rssuri := viper.GetString("RSSUri") n.URL = s.permalinkStr(section + "/" + rssuri) n.Permalink = s.permalink(section) rssLayouts := []string{"section/" + section + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"} if err := s.renderAndWriteXML("section "+section+" rss", section+"/"+rssuri, n, s.appendThemeTemplates(rssLayouts)...); err != nil { return err } } } return nil }
func (s *Site) RenderHomePage() error { n := s.newHomeNode() layouts := s.appendThemeTemplates([]string{"index.html", "_default/list.html"}) if err := s.renderAndWritePage("homepage", helpers.FilePathSeparator, n, layouts...); err != nil { return err } if n.paginator != nil { paginatePath := viper.GetString("paginatePath") // write alias for page 1 s.WriteDestAlias(helpers.PaginateAliasPath("", 1), s.permalink("/")) pagers := n.paginator.Pagers() for i, pager := range pagers { if i == 0 { // already created continue } homePagerNode := s.newHomeNode() homePagerNode.paginator = pager if pager.TotalPages() > 0 { first, _ := pager.page(0) homePagerNode.Date = first.Date homePagerNode.Lastmod = first.Lastmod } pageNumber := i + 1 htmlBase := fmt.Sprintf("/%s/%d", paginatePath, pageNumber) if err := s.renderAndWritePage(fmt.Sprintf("homepage"), filepath.FromSlash(htmlBase), homePagerNode, layouts...); err != nil { return err } } } if !viper.GetBool("DisableRSS") { // XML Feed n.URL = s.permalinkStr(viper.GetString("RSSUri")) n.Title = "" high := 50 if len(s.Pages) < high { high = len(s.Pages) } n.Data["Pages"] = s.Pages[:high] if len(s.Pages) > 0 { n.Date = s.Pages[0].Date n.Lastmod = s.Pages[0].Lastmod } rssLayouts := []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"} if err := s.renderAndWriteXML("homepage rss", viper.GetString("RSSUri"), n, s.appendThemeTemplates(rssLayouts)...); err != nil { return err } } // TODO(bep) reusing the Home Node smells trouble n.URL = helpers.URLize("404.html") n.IsHome = false n.Title = "404 Page not found" n.Permalink = s.permalink("404.html") n.scratch = newScratch() nfLayouts := []string{"404.html"} if nfErr := s.renderAndWritePage("404 page", "404.html", n, s.appendThemeTemplates(nfLayouts)...); nfErr != nil { return nfErr } return nil }
func taxonomyRenderer(s *Site, taxes <-chan taxRenderInfo, results chan<- error, wg *sync.WaitGroup) { defer wg.Done() var n *Node for t := range taxes { var base string layouts := s.appendThemeTemplates( []string{"taxonomy/" + t.singular + ".html", "indexes/" + t.singular + ".html", "_default/taxonomy.html", "_default/list.html"}) n, base = s.newTaxonomyNode(t) dest := base if viper.GetBool("UglyURLs") { dest = helpers.Uglify(base + ".html") } else { dest = helpers.PrettifyPath(base + "/index.html") } if err := s.renderAndWritePage("taxonomy "+t.singular, dest, n, layouts...); err != nil { results <- err continue } if n.paginator != nil { paginatePath := viper.GetString("paginatePath") // write alias for page 1 s.WriteDestAlias(helpers.PaginateAliasPath(base, 1), s.permalink(base)) pagers := n.paginator.Pagers() for i, pager := range pagers { if i == 0 { // already created continue } taxonomyPagerNode, _ := s.newTaxonomyNode(t) taxonomyPagerNode.paginator = pager if pager.TotalPages() > 0 { first, _ := pager.page(0) taxonomyPagerNode.Date = first.Date taxonomyPagerNode.Lastmod = first.Lastmod } pageNumber := i + 1 htmlBase := fmt.Sprintf("/%s/%s/%d", base, paginatePath, pageNumber) if err := s.renderAndWritePage(fmt.Sprintf("taxonomy %s", t.singular), htmlBase, taxonomyPagerNode, layouts...); err != nil { results <- err continue } } } if !viper.GetBool("DisableRSS") { // XML Feed rssuri := viper.GetString("RSSUri") n.URL = s.permalinkStr(base + "/" + rssuri) n.Permalink = s.permalink(base) rssLayouts := []string{"taxonomy/" + t.singular + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"} if err := s.renderAndWriteXML("taxonomy "+t.singular+" rss", base+"/"+rssuri, n, s.appendThemeTemplates(rssLayouts)...); err != nil { results <- err continue } } } }