本文整理汇总了Golang中github.com/spf13/hugo/helpers.Filename函数的典型用法代码示例。如果您正苦于以下问题:Golang Filename函数的具体用法?Golang Filename怎么用?Golang Filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Filename函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: createMetadata
// createMetadata generates Metadata for a new page based upon the metadata
// found in an archetype.
func createMetadata(archetype parser.Page, name string) (map[string]interface{}, error) {
archMetadata, err := archetype.Metadata()
if err != nil {
return nil, err
}
metadata, err := cast.ToStringMapE(archMetadata)
if err != nil {
return nil, err
}
for k := range metadata {
switch strings.ToLower(k) {
case "date":
metadata[k] = time.Now()
case "title":
metadata[k] = helpers.MakeTitle(helpers.Filename(name))
}
}
caseimatch := func(m map[string]interface{}, key string) bool {
for k := range m {
if strings.ToLower(k) == strings.ToLower(key) {
return true
}
}
return false
}
if metadata == nil {
metadata = make(map[string]interface{})
}
if !caseimatch(metadata, "date") {
metadata["date"] = time.Now()
}
if !caseimatch(metadata, "title") {
metadata["title"] = helpers.MakeTitle(helpers.Filename(name))
}
if x := parser.FormatSanitize(viper.GetString("metaDataFormat")); x == "json" || x == "yaml" || x == "toml" {
metadata["date"] = time.Now().Format(time.RFC3339)
}
return metadata, nil
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:49,代码来源:content.go
示例2: NewFile
// NewFile creates a new File pointer with the given relative path.
func NewFile(relpath string) *File {
f := &File{
relpath: relpath,
}
f.dir, f.logicalName = filepath.Split(f.relpath)
f.ext = strings.TrimPrefix(filepath.Ext(f.LogicalName()), ".")
f.baseName = helpers.Filename(f.LogicalName())
f.lang = strings.TrimPrefix(filepath.Ext(f.baseName), ".")
if f.lang == "" {
f.lang = viper.GetString("defaultContentLanguage")
}
f.translationBaseName = helpers.Filename(f.baseName)
f.section = helpers.GuessSection(f.Dir())
f.uniqueID = helpers.Md5String(f.LogicalName())
return f
}
开发者ID:tubo028,项目名称:hugo,代码行数:21,代码来源:file.go
示例3: NewContent
func NewContent(kind, name string) (err error) {
jww.INFO.Println("attempting to create ", name, "of", kind)
location := FindArchetype(kind)
var by []byte
if location != "" {
by, err = ioutil.ReadFile(location)
if err != nil {
jww.ERROR.Println(err)
}
}
if location == "" || err != nil {
by = []byte("+++\n title = \"title\"\n draft = true \n+++\n")
}
psr, err := parser.ReadFrom(bytes.NewReader(by))
if err != nil {
return err
}
metadata, err := psr.Metadata()
if err != nil {
return err
}
newmetadata, err := cast.ToStringMapE(metadata)
if err != nil {
return err
}
for k, _ := range newmetadata {
switch strings.ToLower(k) {
case "date":
newmetadata[k] = time.Now()
case "title":
newmetadata[k] = helpers.MakeTitle(helpers.Filename(name))
}
}
caseimatch := func(m map[string]interface{}, key string) bool {
for k, _ := range m {
if strings.ToLower(k) == strings.ToLower(key) {
return true
}
}
return false
}
if !caseimatch(newmetadata, "date") {
newmetadata["date"] = time.Now()
}
if !caseimatch(newmetadata, "title") {
newmetadata["title"] = helpers.MakeTitle(helpers.Filename(name))
}
page, err := hugolib.NewPage(name)
if err != nil {
return err
}
if x := viper.GetString("MetaDataFormat"); x == "json" || x == "yaml" || x == "toml" {
newmetadata["date"] = time.Now().Format(time.RFC3339)
}
page.Dir = viper.GetString("sourceDir")
page.SetSourceMetaData(newmetadata, parser.FormatToLeadRune(viper.GetString("MetaDataFormat")))
if err = page.SafeSaveSourceAs(path.Join(viper.GetString("contentDir"), name)); err != nil {
return
}
jww.FEEDBACK.Println(helpers.AbsPathify(path.Join(viper.GetString("contentDir"), name)), "created")
return nil
}
开发者ID:hugo-alves,项目名称:hugo,代码行数:75,代码来源:content.go
示例4: loadTemplates
func (t *GoHTMLTemplate) loadTemplates(absPath string, prefix string) {
jww.DEBUG.Printf("Load templates from path %q prefix %q", absPath, prefix)
walker := func(path string, fi os.FileInfo, err error) error {
if err != nil {
return nil
}
jww.DEBUG.Println("Template path", path)
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
link, err := filepath.EvalSymlinks(absPath)
if err != nil {
jww.ERROR.Printf("Cannot read symbolic link '%s', error was: %s", absPath, err)
return nil
}
linkfi, err := hugofs.Source().Stat(link)
if err != nil {
jww.ERROR.Printf("Cannot stat '%s', error was: %s", link, err)
return nil
}
if !linkfi.Mode().IsRegular() {
jww.ERROR.Printf("Symbolic links for directories not supported, skipping '%s'", absPath)
}
return nil
}
if !fi.IsDir() {
if isDotFile(path) || isBackupFile(path) || isBaseTemplate(path) {
return nil
}
tplName := t.GenerateTemplateNameFrom(absPath, path)
if prefix != "" {
tplName = strings.Trim(prefix, "/") + "/" + tplName
}
var baseTemplatePath string
// Ace and Go templates may have both a base and inner template.
pathDir := filepath.Dir(path)
if filepath.Ext(path) != ".amber" && !strings.HasSuffix(pathDir, "partials") && !strings.HasSuffix(pathDir, "shortcodes") {
innerMarkers := goTemplateInnerMarkers
baseFileName := fmt.Sprintf("%s.html", baseFileBase)
if filepath.Ext(path) == ".ace" {
innerMarkers = aceTemplateInnerMarkers
baseFileName = fmt.Sprintf("%s.ace", baseFileBase)
}
// This may be a view that shouldn't have base template
// Have to look inside it to make sure
needsBase, err := helpers.FileContainsAny(path, innerMarkers, hugofs.Source())
if err != nil {
return err
}
if needsBase {
// Look for base template in the follwing order:
// 1. <current-path>/<template-name>-baseof.<suffix>, e.g. list-baseof.<suffix>.
// 2. <current-path>/baseof.<suffix>
// 3. _default/<template-name>-baseof.<suffix>, e.g. list-baseof.<suffix>.
// 4. _default/baseof.<suffix>
// 5. <themedir>/layouts/_default/<template-name>-baseof.<suffix>
// 6. <themedir>/layouts/_default/baseof.<suffix>
currBaseFilename := fmt.Sprintf("%s-%s", helpers.Filename(path), baseFileName)
templateDir := filepath.Dir(path)
themeDir := helpers.GetThemeDir()
pathsToCheck := []string{
filepath.Join(templateDir, currBaseFilename),
filepath.Join(templateDir, baseFileName),
filepath.Join(absPath, "_default", currBaseFilename),
filepath.Join(absPath, "_default", baseFileName),
filepath.Join(themeDir, "layouts", "_default", currBaseFilename),
filepath.Join(themeDir, "layouts", "_default", baseFileName),
}
for _, pathToCheck := range pathsToCheck {
if ok, err := helpers.Exists(pathToCheck, hugofs.Source()); err == nil && ok {
baseTemplatePath = pathToCheck
break
}
}
}
}
if err := t.AddTemplateFile(tplName, baseTemplatePath, path); err != nil {
jww.ERROR.Printf("Failed to add template %s: %s", tplName, err)
}
}
return nil
}
if err := helpers.SymbolicWalk(hugofs.Source(), absPath, walker); err != nil {
jww.ERROR.Printf("Failed to load templates: %s", err)
}
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:98,代码来源:template.go
示例5: loadTemplates
func (t *GoHTMLTemplate) loadTemplates(absPath string, prefix string) {
walker := func(path string, fi os.FileInfo, err error) error {
if err != nil {
return nil
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
link, err := filepath.EvalSymlinks(absPath)
if err != nil {
jww.ERROR.Printf("Cannot read symbolic link '%s', error was: %s", absPath, err)
return nil
}
linkfi, err := os.Stat(link)
if err != nil {
jww.ERROR.Printf("Cannot stat '%s', error was: %s", link, err)
return nil
}
if !linkfi.Mode().IsRegular() {
jww.ERROR.Printf("Symbolic links for directories not supported, skipping '%s'", absPath)
}
return nil
}
if !fi.IsDir() {
if isDotFile(path) || isBackupFile(path) || isBaseTemplate(path) {
return nil
}
tplName := t.GenerateTemplateNameFrom(absPath, path)
if prefix != "" {
tplName = strings.Trim(prefix, "/") + "/" + tplName
}
var baseTemplatePath string
// ACE templates may have both a base and inner template.
if filepath.Ext(path) == ".ace" && !strings.HasSuffix(filepath.Dir(path), "partials") {
// This may be a view that shouldn't have base template
// Have to look inside it to make sure
needsBase, err := helpers.FileContains(path, aceTemplateInnerMarker, hugofs.OsFs)
if err != nil {
return err
}
if needsBase {
// Look for base template in the follwing order:
// 1. <current-path>/<template-name>-baseof.ace, e.g. list-baseof.ace.
// 2. <current-path>/baseof.ace
// 3. _default/<template-name>-baseof.ace, e.g. list-baseof.ace.
// 4. _default/baseof.ace
// 5. <themedir>/layouts/_default/<template-name>-baseof.ace
// 6. <themedir>/layouts/_default/baseof.ace
currBaseAceFilename := fmt.Sprintf("%s-%s", helpers.Filename(path), baseAceFilename)
templateDir := filepath.Dir(path)
themeDir := helpers.GetThemeDir()
pathsToCheck := []string{
filepath.Join(templateDir, currBaseAceFilename),
filepath.Join(templateDir, baseAceFilename),
filepath.Join(absPath, "_default", currBaseAceFilename),
filepath.Join(absPath, "_default", baseAceFilename),
filepath.Join(themeDir, "layouts", "_default", currBaseAceFilename),
filepath.Join(themeDir, "layouts", "_default", baseAceFilename),
}
for _, pathToCheck := range pathsToCheck {
if ok, err := helpers.Exists(pathToCheck, hugofs.OsFs); err == nil && ok {
baseTemplatePath = pathToCheck
break
}
}
}
}
t.AddTemplateFile(tplName, baseTemplatePath, path)
}
return nil
}
filepath.Walk(absPath, walker)
}
开发者ID:mariuccio,项目名称:hugo,代码行数:84,代码来源:template.go
示例6: BaseFileName
// BaseFileName Filename without extension
func (f *File) BaseFileName() string {
return helpers.Filename(f.LogicalName())
}
开发者ID:yanwushuang,项目名称:pango,代码行数:4,代码来源:file.go
注:本文中的github.com/spf13/hugo/helpers.Filename函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论