本文整理汇总了Golang中github.com/spf13/hugo/source.File类的典型用法代码示例。如果您正苦于以下问题:Golang File类的具体用法?Golang File怎么用?Golang File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: githubFileLink
// for non-pages in the site tree
func (s *SiteInfo) githubFileLink(ref string, currentPage *Page, relative bool) (string, error) {
var refURL *url.URL
var err error
// TODO can I make this a param to `hugo --use-github-links=/docs`?
// SVEN: add more tests - the prefix might be a real dir inside tho - add some pages that have it as a legitimate path
repositoryPathPrefix := "/docs"
refURL, err = url.Parse(strings.TrimPrefix(ref, repositoryPathPrefix))
if err != nil {
return "", err
}
if refURL.Scheme != "" {
// TODO: consider looking for http(s?)://github.com/user/project/prefix and replacing it - tho this may be intentional, so idk
//return "", fmt.Errorf("Not a plain filepath link (%s)", ref)
// Treat this as not an error, as the link is used as-is
return ref, nil
}
var target *source.File
var link string
if refURL.Path != "" {
refPath := filepath.Clean(filepath.FromSlash(refURL.Path))
if strings.IndexRune(refPath, os.PathSeparator) == 0 { // filepath.IsAbs fails to me.
refPath = refPath[1:]
} else {
if currentPage != nil {
refPath = filepath.Join(currentPage.Source.Dir(), refURL.Path)
}
}
for _, file := range []*source.File(*s.Files) {
if file.Path() == refPath {
target = file
break
}
}
if target == nil {
return "", fmt.Errorf("No file found for \"%s\" on page \"%s\".\n", ref, currentPage.Source.Path())
}
link = target.Path()
// SVEN: look at filepath.Rel() it might help, got the rel/non-rel url's (dangerous tho)
// SVEN: reconsider the fact I hardcoded the `relative` bool in both github resolvers
if relative {
return "./" + filepath.ToSlash(link), nil
} else {
return "/" + filepath.ToSlash(link), nil
}
}
return "", fmt.Errorf("failed to find a file to match \"%s\" on page \"%s\"", ref, currentPage.Source.Path())
}
开发者ID:lismore,项目名称:hugo,代码行数:58,代码来源:site.go
示例2: readData
func readData(f *source.File) (interface{}, error) {
switch f.Extension() {
case "yaml", "yml":
return parser.HandleYamlMetaData(f.Bytes())
case "json":
return parser.HandleJsonMetaData(f.Bytes())
case "toml":
return parser.HandleTomlMetaData(f.Bytes())
default:
return nil, fmt.Errorf("Data not supported for extension '%s'", f.Extension())
}
}
开发者ID:dunn,项目名称:hugo,代码行数:12,代码来源:site.go
示例3: readData
func readData(f *source.File) (interface{}, error) {
switch f.Extension() {
case "yaml", "yml":
return parser.HandleYAMLMetaData(f.Bytes())
case "json":
return parser.HandleJSONMetaData(f.Bytes())
case "toml":
return parser.HandleTOMLMetaData(f.Bytes())
default:
jww.WARN.Printf("Data not supported for extension '%s'", f.Extension())
return nil, nil
}
}
开发者ID:maruel,项目名称:hugo,代码行数:13,代码来源:site.go
示例4: Read
func (b basicPageHandler) Read(f *source.File, s *Site) HandledResult {
page, err := NewPage(f.Path())
if err != nil {
return HandledResult{file: f, err: err}
}
if _, err := page.ReadFrom(f.Contents); err != nil {
return HandledResult{file: f, err: err}
}
page.Site = &s.Info
page.Tmpl = s.Tmpl
return HandledResult{file: f, page: page, err: err}
}
开发者ID:johndunne,项目名称:hugo,代码行数:15,代码来源:handler_page.go
示例5: FileConvert
func (h cssHandler) FileConvert(f *source.File, s *Site) HandledResult {
x := cssmin.Minify(f.Bytes())
s.WriteDestFile(f.Path(), helpers.BytesToReader(x))
return HandledResult{file: f}
}
开发者ID:johndunne,项目名称:hugo,代码行数:5,代码来源:handler_file.go
注:本文中的github.com/spf13/hugo/source.File类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论