示例#1
0
文件: site.go 项目: RoyRui/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
}
示例#2
0
文件: site.go 项目: RoyRui/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
}
示例#3
0
文件: site.go 项目: RoyRui/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
}
示例#4
0
文件: page.go 项目: nelsonsilva/hugo
func (page *Page) update(f interface{}) error {
	m := f.(map[string]interface{})

	for k, v := range m {
		switch strings.ToLower(k) {
		case "title":
			page.Title = interfaceToString(v)
		case "description":
			page.Description = interfaceToString(v)
		case "slug":
			page.Slug = helper.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 = helper.Urlize(interfaceToString(v))
		case "type":
			page.contentType = interfaceToString(v)
		case "keywords":
			page.Keywords = interfaceArrayToStringArray(v)
		case "date", "pubdate":
			page.Date = interfaceToStringToDate(v)
		case "draft":
			page.Draft = interfaceToBool(v)
		case "layout":
			page.layout = interfaceToString(v)
		case "markup":
			page.Markup = interfaceToString(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 string: // handle string values
				page.Params[strings.ToLower(k)] = 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[strings.ToLower(k)] = a
				}
			}
		}
	}
	return nil

}
示例#5
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
}
示例#6
0
文件: site.go 项目: nelsonsilva/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]
			n.Data["OrderedIndex"] = s.Info.Indexes[plural]

			err := s.render(n, plural+"/index.html", layout)
			if err != nil {
				return err
			}
		}
	}
	return
}
示例#7
0
文件: index.go 项目: nelsonsilva/hugo
// KeyPrep... Indexes should be case insensitive. Can make it easily conditional later.
func kp(in string) string {
	return template.Urlize(in)
}
示例#8
0
文件: permalinks.go 项目: RoyRui/hugo
// 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 helper.Urlize(p.Title), nil
}