Example #1
0
File: site.go Project: colyli/hugo
func (s *Site) RenderHomePage() error {
	n := s.NewNode()
	n.Title = n.Site.Title
	n.Url = helpers.Urlize(string(n.Site.BaseUrl))
	n.RSSlink = permalink(s, "index.xml")
	n.Permalink = permalink(s, "")
	n.Data["Pages"] = s.Pages
	err := s.render(n, "/", "index.html")
	if err != nil {
		return err
	}

	if a := s.Tmpl.Lookup("rss.xml"); a != nil {
		// XML Feed
		n.Url = helpers.Urlize("index.xml")
		n.Title = "Recent Content"
		n.Permalink = permalink(s, "index.xml")
		err := s.render(n, ".xml", "rss.xml")
		if err != nil {
			return err
		}
	}

	if a := s.Tmpl.Lookup("404.html"); a != nil {
		n.Url = helpers.Urlize("404.html")
		n.Title = "404 Page not found"
		n.Permalink = permalink(s, "404.html")
		return s.render(n, "404.html", "404.html")
	}

	return nil
}
Example #2
0
File: site.go Project: colyli/hugo
func (s *Site) RenderIndexes() error {
	for singular, plural := range s.Config.Indexes {
		for k, o := range s.Indexes[plural] {
			n := s.NewNode()
			n.Title = strings.Title(k)
			url := helpers.Urlize(plural + "/" + k)
			n.Url = url + ".html"
			plink := n.Url
			n.Permalink = permalink(s, plink)
			n.RSSlink = permalink(s, url+".xml")
			n.Date = o[0].Page.Date
			n.Data[singular] = o
			n.Data["Pages"] = o.Pages()
			layout := "indexes/" + singular + ".html"

			var base string
			base = plural + "/" + k
			err := s.render(n, base+".html", layout)
			if err != nil {
				return err
			}

			if a := s.Tmpl.Lookup("rss.xml"); a != nil {
				// XML Feed
				n.Url = helpers.Urlize(plural + "/" + k + ".xml")
				n.Permalink = permalink(s, n.Url)
				err := s.render(n, base+".xml", "rss.xml")
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
Example #3
0
File: site.go Project: colyli/hugo
func (s *Site) RenderLists() error {
	for section, data := range s.Sections {
		n := s.NewNode()
		n.Title = strings.Title(inflect.Pluralize(section))
		n.Url = helpers.Urlize(section + "/" + "index.html")
		n.Permalink = permalink(s, n.Url)
		n.RSSlink = permalink(s, section+".xml")
		n.Date = data[0].Page.Date
		n.Data["Pages"] = data.Pages()
		layout := "indexes/" + section + ".html"

		err := s.render(n, section, layout, "_default/indexes.html")
		if err != nil {
			return err
		}

		if a := s.Tmpl.Lookup("rss.xml"); a != nil {
			// XML Feed
			n.Url = helpers.Urlize(section + ".xml")
			n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url)
			err = s.render(n, section+".xml", "rss.xml")
			if err != nil {
				return err
			}
		}
	}
	return nil
}
Example #4
0
File: site.go Project: johnsto/hugo
func (s *Site) RenderHomePage() error {
	n := s.NewNode()
	n.Title = n.Site.Title
	s.setUrls(n, "/")
	n.Data["Pages"] = s.Pages
	layouts := []string{"index.html", "_default/list.html", "_default/single.html"}
	err := s.render(n, "/", s.appendThemeTemplates(layouts)...)
	if err != nil {
		return err
	}

	if !viper.GetBool("DisableRSS") {
		// XML Feed
		n.Url = helpers.Urlize("index.xml")
		n.Title = "Recent Content"
		n.Permalink = s.permalink("index.xml")
		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
		}

		if !viper.GetBool("DisableRSS") {
			rssLayouts := []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"}
			err := s.render(n, ".xml", s.appendThemeTemplates(rssLayouts)...)
			if err != nil {
				return err
			}
		}
	}

	// Force `UglyUrls` option to force `404.html` file name
	switch s.Target.(type) {
	case *target.Filesystem:
		if !s.Target.(*target.Filesystem).UglyUrls {
			s.Target.(*target.Filesystem).UglyUrls = true
			defer func() { s.Target.(*target.Filesystem).UglyUrls = false }()
		}
	}

	n.Url = helpers.Urlize("404.html")
	n.Title = "404 Page not found"
	n.Permalink = s.permalink("404.html")

	nfLayouts := []string{"404.html"}
	nfErr := s.render(n, "404.html", s.appendThemeTemplates(nfLayouts)...)
	if nfErr != nil {
		return nfErr
	}

	return nil
}
Example #5
0
File: site.go Project: jempe/hugo
func (s *Site) RenderHomePage() error {
	n := s.newHomeNode()
	layouts := []string{"index.html", "_default/list.html", "_default/single.html"}
	b, err := s.renderPage("homepage", n, s.appendThemeTemplates(layouts)...)
	if err != nil {
		return err
	}
	if err := s.WriteDestPage("/", b); err != nil {
		return err
	}

	if !viper.GetBool("DisableRSS") {
		// XML Feed
		n.Url = helpers.Urlize("index.xml")
		n.Title = "Recent Content"
		n.Permalink = s.permalink("index.xml")
		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
		}

		if !viper.GetBool("DisableRSS") {
			rssLayouts := []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"}
			b, err := s.renderXML("homepage rss", n, s.appendThemeTemplates(rssLayouts)...)
			if err != nil {
				return err
			}
			if err := s.WriteDestFile("rss.xml", b); err != nil {
				return err
			}
		}
	}

	n.Url = helpers.Urlize("404.html")
	n.Title = "404 Page not found"
	n.Permalink = s.permalink("404.html")

	nfLayouts := []string{"404.html"}
	b, nfErr := s.renderPage("404 page", n, s.appendThemeTemplates(nfLayouts)...)
	if nfErr != nil {
		return nfErr
	}
	if err := s.WriteDestFile("404.html", b); err != nil {
		return err
	}

	return nil
}
Example #6
0
func (s *Site) RenderHomePage() error {
	n := s.NewNode()
	n.Title = n.Site.Title
	s.setUrls(n, "/")
	n.Data["Pages"] = s.Pages
	layouts := []string{"index.html", "_default/list.html", "_default/single.html"}
	err := s.render(n, "/", s.appendThemeTemplates(layouts)...)
	if err != nil {
		return err
	}

	if !viper.GetBool("DisableRSS") {
		// XML Feed
		n.Url = helpers.Urlize("index.xml")
		n.Title = "Recent Content"
		n.Permalink = s.permalink("index.xml")
		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
		}

		if !viper.GetBool("DisableRSS") {
			rssLayouts := []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"}
			err := s.render(n, ".xml", s.appendThemeTemplates(rssLayouts)...)
			if err != nil {
				return err
			}
		}
	}

	n.Url = helpers.Urlize("404.html")
	n.Title = "404 Page not found"
	n.Permalink = s.permalink("404.html")

	nfLayouts := []string{"404.html"}
	nfErr := s.render(n, "404.html", s.appendThemeTemplates(nfLayouts)...)
	if nfErr != nil {
		return nfErr
	}

	return nil
}
Example #7
0
func (h *HTMLRedirectAlias) Translate(alias string) (aliasPath string, err error) {
	if len(alias) <= 0 {
		return
	}

	if strings.HasSuffix(alias, "/") {
		alias = alias + "index.html"
	} else if !strings.HasSuffix(alias, ".html") {
		alias = alias + "/index.html"
	}
	return path.Join(h.PublishDir, helpers.Urlize(alias)), nil
}
Example #8
0
File: site.go Project: GuoJing/hugo
func (s *Site) RenderHomePage() error {
	n := s.NewNode()
	n.Title = n.Site.Title
	s.setUrls(n, "/")
	n.Data["Pages"] = s.Pages
	err := s.render(n, "/", "index.html")
	if err != nil {
		return err
	}

	if a := s.Tmpl.Lookup("rss.xml"); a != nil {
		// XML Feed
		n.Url = helpers.Urlize("index.xml")
		n.Title = "Recent Content"
		n.Permalink = s.permalink("index.xml")
		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
		}
		err := s.render(n, ".xml", "rss.xml")
		if err != nil {
			return err
		}
	}

	if a := s.Tmpl.Lookup("404.html"); a != nil {
		n.Url = helpers.Urlize("404.html")
		n.Title = "404 Page not found"
		n.Permalink = s.permalink("404.html")
		return s.render(n, "404.html", "404.html")
	}

	return nil
}
Example #9
0
File: site.go Project: colyli/hugo
func (s *Site) RenderIndexesIndexes() (err error) {
	layout := "indexes/indexes.html"
	if s.Tmpl.Lookup(layout) != nil {
		for singular, plural := range s.Config.Indexes {
			n := s.NewNode()
			n.Title = strings.Title(plural)
			url := helpers.Urlize(plural)
			n.Url = url + "/index.html"
			n.Permalink = permalink(s, n.Url)
			n.Data["Singular"] = singular
			n.Data["Plural"] = plural
			n.Data["Index"] = s.Indexes[plural]
			// keep the following just for legacy reasons
			n.Data["OrderedIndex"] = s.Indexes[plural]

			err := s.render(n, plural+"/index.html", layout)
			if err != nil {
				return err
			}
		}
	}
	return
}
Example #10
0
File: page.go Project: GuoJing/hugo
func (page *Page) update(f interface{}) error {
	m := f.(map[string]interface{})

	for k, v := range m {
		loki := strings.ToLower(k)
		switch loki {
		case "title":
			page.Title = interfaceToString(v)
		case "linktitle":
			page.linkTitle = interfaceToString(v)
		case "description":
			page.Description = interfaceToString(v)
		case "slug":
			page.Slug = helpers.Urlize(interfaceToString(v))
		case "url":
			if url := interfaceToString(v); strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
				return fmt.Errorf("Only relative urls are supported, %v provided", url)
			}
			page.Url = helpers.Urlize(interfaceToString(v))
		case "type":
			page.contentType = interfaceToString(v)
		case "keywords":
			page.Keywords = interfaceArrayToStringArray(v)
		case "date", "pubdate":
			page.Date = interfaceToTime(v)
		case "draft":
			page.Draft = interfaceToBool(v)
		case "layout":
			page.layout = interfaceToString(v)
		case "markup":
			page.Markup = interfaceToString(v)
		case "weight":
			page.Weight = interfaceToInt(v)
		case "aliases":
			page.Aliases = interfaceArrayToStringArray(v)
			for _, alias := range page.Aliases {
				if strings.HasPrefix(alias, "http://") || strings.HasPrefix(alias, "https://") {
					return fmt.Errorf("Only relative aliases are supported, %v provided", alias)
				}
			}
		case "status":
			page.Status = interfaceToString(v)
		default:
			// If not one of the explicit values, store in Params
			switch vv := v.(type) {
			case bool:
				page.Params[loki] = vv
			case string:
				page.Params[loki] = vv
			case int64, int32, int16, int8, int:
				page.Params[loki] = vv
			case float64, float32:
				page.Params[loki] = vv
			case time.Time:
				page.Params[loki] = vv
			default: // handle array of strings as well
				switch vvv := vv.(type) {
				case []interface{}:
					var a = make([]string, len(vvv))
					for i, u := range vvv {
						a[i] = interfaceToString(u)
					}
					page.Params[loki] = a
				}
			}
		}
	}
	return nil

}
Example #11
0
// pageToPermalinkFilename returns the URL-safe form of the filename
func pageToPermalinkFilename(p *Page, _ string) (string, error) {
	//var extension = p.Source.Ext
	//var name = p.Source.Path()[0 : len(p.Source.Path())-len(extension)]
	return helpers.Urlize(p.Source.BaseFileName()), nil
}
Example #12
0
// pageToPermalinkTitle returns the URL-safe form of the title
func pageToPermalinkTitle(p *Page, _ string) (string, error) {
	// Page contains Node which has Title
	// (also contains UrlPath which has Slug, sometimes)
	return helpers.Urlize(p.Title), nil
}
Example #13
0
func (page *Page) update(f interface{}) error {
	if f == nil {
		return fmt.Errorf("no metadata found")
	}
	m := f.(map[string]interface{})
	var err error
	for k, v := range m {
		loki := strings.ToLower(k)
		switch loki {
		case "title":
			page.Title = cast.ToString(v)
		case "linktitle":
			page.linkTitle = cast.ToString(v)
		case "description":
			page.Description = cast.ToString(v)
		case "slug":
			page.Slug = helpers.Urlize(cast.ToString(v))
		case "url":
			if url := cast.ToString(v); strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
				return fmt.Errorf("Only relative urls are supported, %v provided", url)
			}
			page.Url = helpers.Urlize(cast.ToString(v))
		case "type":
			page.contentType = cast.ToString(v)
		case "extension", "ext":
			page.extension = cast.ToString(v)
		case "keywords":
			page.Keywords = cast.ToStringSlice(v)
		case "date":
			page.Date, err = cast.ToTimeE(v)
			if err != nil {
				jww.ERROR.Printf("Failed to parse date '%v' in page %s", v, page.File.Path())
			}
		case "publishdate", "pubdate":
			page.PublishDate, err = cast.ToTimeE(v)
			if err != nil {
				jww.ERROR.Printf("Failed to parse publishdate '%v' in page %s", v, page.File.Path())
			}
		case "draft":
			page.Draft = cast.ToBool(v)
		case "layout":
			page.layout = cast.ToString(v)
		case "markup":
			page.Markup = cast.ToString(v)
		case "weight":
			page.Weight = cast.ToInt(v)
		case "aliases":
			page.Aliases = cast.ToStringSlice(v)
			for _, alias := range page.Aliases {
				if strings.HasPrefix(alias, "http://") || strings.HasPrefix(alias, "https://") {
					return fmt.Errorf("Only relative aliases are supported, %v provided", alias)
				}
			}
		case "status":
			page.Status = cast.ToString(v)
		case "sitemap":
			page.Sitemap = parseSitemap(cast.ToStringMap(v))
		default:
			// If not one of the explicit values, store in Params
			switch vv := v.(type) {
			case bool:
				page.Params[loki] = vv
			case string:
				page.Params[loki] = vv
			case int64, int32, int16, int8, int:
				page.Params[loki] = vv
			case float64, float32:
				page.Params[loki] = vv
			case time.Time:
				page.Params[loki] = vv
			default: // handle array of strings as well
				switch vvv := vv.(type) {
				case []interface{}:
					var a = make([]string, len(vvv))
					for i, u := range vvv {
						a[i] = cast.ToString(u)
					}
					page.Params[loki] = a
				default:
					page.Params[loki] = vv
				}
			}
		}
	}
	return nil

}
Example #14
0
// pageToPermalinkFilename returns the URL-safe form of the filename
func pageToPermalinkFilename(p *Page, _ string) (string, error) {
	var extension = filepath.Ext(p.FileName)
	var name = p.FileName[0 : len(p.FileName)-len(extension)]
	return helpers.Urlize(name), nil
}
Example #15
0
File: site.go Project: johnsto/hugo
func (s *Site) prepUrl(in string) string {
	return helpers.Urlize(s.PrettifyUrl(in))
}
Example #16
0
File: site.go Project: jaden/hugo
func (s *Site) RenderHomePage() error {
	n := s.newHomeNode()
	layouts := s.appendThemeTemplates([]string{"index.html", "_default/list.html", "_default/single.html"})

	b, err := s.renderPage("homepage", n, layouts...)

	if err != nil {
		return err
	}
	if err := s.WriteDestPage("/", b); err != nil {
		return err
	}

	if n.paginator != nil {

		paginatePath := viper.GetString("paginatePath")

		// write alias for page 1
		s.WriteDestAlias(filepath.FromSlash(fmt.Sprintf("/%s/%d", paginatePath, 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 {
				homePagerNode.Date = pager.Pages()[0].Date
			}
			pageNumber := i + 1
			htmlBase := fmt.Sprintf("/%s/%d", paginatePath, pageNumber)
			b, err := s.renderPage(fmt.Sprintf("homepage_%d", pageNumber), homePagerNode, layouts...)
			if err != nil {
				return err
			}
			if err := s.WriteDestPage(filepath.FromSlash(htmlBase), b); err != nil {
				return err
			}

		}
	}

	if !viper.GetBool("DisableRSS") {
		// XML Feed
		n.Url = s.permalinkStr("index.xml")
		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
		}

		rssLayouts := []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"}
		b, err := s.renderXML("homepage rss", n, s.appendThemeTemplates(rssLayouts)...)
		if err != nil {
			return err
		}
		if err := s.WriteDestFile("index.xml", b); err != nil {
			return err
		}
	}

	n.Url = helpers.Urlize("404.html")
	n.Title = "404 Page not found"
	n.Permalink = s.permalink("404.html")

	nfLayouts := []string{"404.html"}
	b, nfErr := s.renderPage("404 page", n, s.appendThemeTemplates(nfLayouts)...)
	if nfErr != nil {
		return nfErr
	}
	if err := s.WriteDestFile("404.html", b); err != nil {
		return err
	}

	return nil
}
Example #17
0
File: index.go Project: colyli/hugo
// KeyPrep... Indexes should be case insensitive. Can make it easily conditional later.
func kp(in string) string {
	return helpers.Urlize(in)
}