本文整理汇总了Golang中github.com/spf13/hugo/helpers.Urlize函数的典型用法代码示例。如果您正苦于以下问题:Golang Urlize函数的具体用法?Golang Urlize怎么用?Golang Urlize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Urlize函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RenderHomePage
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
}
开发者ID:colyli,项目名称:hugo,代码行数:32,代码来源:site.go
示例2: RenderIndexes
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
}
开发者ID:colyli,项目名称:hugo,代码行数:35,代码来源:site.go
示例3: RenderLists
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
}
开发者ID:colyli,项目名称:hugo,代码行数:28,代码来源:site.go
示例4: RenderHomePage
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
}
开发者ID:johnsto,项目名称:hugo,代码行数:55,代码来源:site.go
示例5: RenderHomePage
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
}
开发者ID:jempe,项目名称:hugo,代码行数:52,代码来源:site.go
示例6: RenderHomePage
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
}
开发者ID:rayleyva,项目名称:hugo,代码行数:46,代码来源:site.go
示例7: Translate
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
}
开发者ID:4honor,项目名称:hugo,代码行数:12,代码来源:htmlredirect.go
示例8: RenderHomePage
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
}
开发者ID:GuoJing,项目名称:hugo,代码行数:38,代码来源:site.go
示例9: RenderIndexesIndexes
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
}
开发者ID:colyli,项目名称:hugo,代码行数:23,代码来源:site.go
示例10: update
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
}
开发者ID:GuoJing,项目名称:hugo,代码行数:70,代码来源:page.go
示例11: pageToPermalinkFilename
// 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
}
开发者ID:dunn,项目名称:hugo,代码行数:6,代码来源:permalinks.go
示例12: pageToPermalinkTitle
// 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
}
开发者ID:dunn,项目名称:hugo,代码行数:6,代码来源:permalinks.go
示例13: update
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
}
开发者ID:reedobrien,项目名称:hugo,代码行数:87,代码来源:page.go
示例14: pageToPermalinkFilename
// 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
}
开发者ID:GeertJohan,项目名称:hugo,代码行数:6,代码来源:permalinks.go
示例15: prepUrl
func (s *Site) prepUrl(in string) string {
return helpers.Urlize(s.PrettifyUrl(in))
}
开发者ID:johnsto,项目名称:hugo,代码行数:3,代码来源:site.go
示例16: RenderHomePage
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
}
开发者ID:jaden,项目名称:hugo,代码行数:84,代码来源:site.go
示例17: kp
// KeyPrep... Indexes should be case insensitive. Can make it easily conditional later.
func kp(in string) string {
return helpers.Urlize(in)
}
开发者ID:colyli,项目名称:hugo,代码行数:4,代码来源:index.go
注:本文中的github.com/spf13/hugo/helpers.Urlize函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论