本文整理汇总了Golang中github.com/spf13/hugo/helpers.GetThemeDir函数的典型用法代码示例。如果您正苦于以下问题:Golang GetThemeDir函数的具体用法?Golang GetThemeDir怎么用?Golang GetThemeDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetThemeDir函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: isThemeVsHugoVersionMismatch
// isThemeVsHugoVersionMismatch returns whether the current Hugo version is
// less than the theme's min_version.
func isThemeVsHugoVersionMismatch() (mismatch bool, requiredMinVersion string) {
if !helpers.ThemeSet() {
return
}
themeDir := helpers.GetThemeDir()
fs := hugofs.SourceFs
path := filepath.Join(themeDir, "theme.toml")
exists, err := helpers.Exists(path, fs)
if err != nil || !exists {
return
}
f, err := fs.Open(path)
if err != nil {
return
}
defer f.Close()
b, err := ioutil.ReadAll(f)
if err != nil {
return
}
c, err := parser.HandleTOMLMetaData(b)
if err != nil {
return
}
config := c.(map[string]interface{})
if minVersion, ok := config["min_version"]; ok {
switch minVersion.(type) {
case float32:
return helpers.HugoVersionNumber < minVersion.(float32), fmt.Sprint(minVersion)
case float64:
return helpers.HugoVersionNumber < minVersion.(float64), fmt.Sprint(minVersion)
default:
return
}
}
return
}
开发者ID:nitoyon,项目名称:hugo,代码行数:54,代码来源:hugo.go
示例2: InitializeConfig
//.........这里部分代码省略.........
if flagChanged(cmdV.Flags(), "preserveTaxonomyNames") {
viper.Set("PreserveTaxonomyNames", preserveTaxonomyNames)
}
if flagChanged(cmdV.Flags(), "ignoreCache") {
viper.Set("IgnoreCache", ignoreCache)
}
if flagChanged(cmdV.Flags(), "forceSyncStatic") {
viper.Set("ForceSyncStatic", forceSync)
}
if flagChanged(cmdV.Flags(), "noTimes") {
viper.Set("NoTimes", noTimes)
}
}
if baseURL != "" {
if !strings.HasSuffix(baseURL, "/") {
baseURL = baseURL + "/"
}
viper.Set("BaseURL", baseURL)
}
if !viper.GetBool("RelativeURLs") && viper.GetString("BaseURL") == "" {
jww.ERROR.Println("No 'baseurl' set in configuration or as a flag. Features like page menus will not work without one.")
}
if theme != "" {
viper.Set("theme", theme)
}
if destination != "" {
viper.Set("PublishDir", destination)
}
if source != "" {
dir, _ := filepath.Abs(source)
viper.Set("WorkingDir", dir)
} else {
dir, _ := os.Getwd()
viper.Set("WorkingDir", dir)
}
if contentDir != "" {
viper.Set("ContentDir", contentDir)
}
if layoutDir != "" {
viper.Set("LayoutDir", layoutDir)
}
if cacheDir != "" {
if helpers.FilePathSeparator != cacheDir[len(cacheDir)-1:] {
cacheDir = cacheDir + helpers.FilePathSeparator
}
isDir, err := helpers.DirExists(cacheDir, hugofs.SourceFs)
utils.CheckErr(err)
if isDir == false {
mkdir(cacheDir)
}
viper.Set("CacheDir", cacheDir)
} else {
viper.Set("CacheDir", helpers.GetTempDir("hugo_cache", hugofs.SourceFs))
}
if verboseLog || logging || (viper.IsSet("LogFile") && viper.GetString("LogFile") != "") {
if viper.IsSet("LogFile") && viper.GetString("LogFile") != "" {
jww.SetLogFile(viper.GetString("LogFile"))
} else {
jww.UseTempLogFile("hugo")
}
} else {
jww.DiscardLogging()
}
if viper.GetBool("verbose") {
jww.SetStdoutThreshold(jww.LevelInfo)
}
if verboseLog {
jww.SetLogThreshold(jww.LevelInfo)
}
jww.INFO.Println("Using config file:", viper.ConfigFileUsed())
themeDir := helpers.GetThemeDir()
if themeDir != "" {
if _, err := os.Stat(themeDir); os.IsNotExist(err) {
return newSystemError("Unable to find theme Directory:", themeDir)
}
}
themeVersionMismatch, minVersion := isThemeVsHugoVersionMismatch()
if themeVersionMismatch {
jww.ERROR.Printf("Current theme does not support Hugo version %s. Minimum version required is %s\n",
helpers.HugoReleaseVersion(), minVersion)
}
return nil
}
开发者ID:nitoyon,项目名称:hugo,代码行数:101,代码来源:hugo.go
示例3: InitializeConfig
//.........这里部分代码省略.........
viper.Set("DisableSitemap", DisableSitemap)
}
if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
viper.Set("Verbose", Verbose)
}
if hugoCmdV.PersistentFlags().Lookup("pluralizeListTitles").Changed {
viper.Set("PluralizeListTitles", PluralizeListTitles)
}
if hugoCmdV.PersistentFlags().Lookup("preserveTaxonomyNames").Changed {
viper.Set("PreserveTaxonomyNames", PreserveTaxonomyNames)
}
if hugoCmdV.PersistentFlags().Lookup("editor").Changed {
viper.Set("NewContentEditor", Editor)
}
if hugoCmdV.PersistentFlags().Lookup("logFile").Changed {
viper.Set("LogFile", LogFile)
}
if BaseURL != "" {
if !strings.HasSuffix(BaseURL, "/") {
BaseURL = BaseURL + "/"
}
viper.Set("BaseURL", BaseURL)
}
if !viper.GetBool("RelativeURLs") && viper.GetString("BaseURL") == "" {
jww.ERROR.Println("No 'baseurl' set in configuration or as a flag. Features like page menus will not work without one.")
}
if Theme != "" {
viper.Set("theme", Theme)
}
if Destination != "" {
viper.Set("PublishDir", Destination)
}
if Source != "" {
viper.Set("WorkingDir", Source)
} else {
dir, _ := os.Getwd()
viper.Set("WorkingDir", dir)
}
if hugoCmdV.PersistentFlags().Lookup("ignoreCache").Changed {
viper.Set("IgnoreCache", IgnoreCache)
}
if CacheDir != "" {
if helpers.FilePathSeparator != CacheDir[len(CacheDir)-1:] {
CacheDir = CacheDir + helpers.FilePathSeparator
}
isDir, err := helpers.DirExists(CacheDir, hugofs.SourceFs)
utils.CheckErr(err)
if isDir == false {
mkdir(CacheDir)
}
viper.Set("CacheDir", CacheDir)
} else {
viper.Set("CacheDir", helpers.GetTempDir("hugo_cache", hugofs.SourceFs))
}
if VerboseLog || Logging || (viper.IsSet("LogFile") && viper.GetString("LogFile") != "") {
if viper.IsSet("LogFile") && viper.GetString("LogFile") != "" {
jww.SetLogFile(viper.GetString("LogFile"))
} else {
jww.UseTempLogFile("hugo")
}
} else {
jww.DiscardLogging()
}
if viper.GetBool("verbose") {
jww.SetStdoutThreshold(jww.LevelInfo)
}
if VerboseLog {
jww.SetLogThreshold(jww.LevelInfo)
}
jww.INFO.Println("Using config file:", viper.ConfigFileUsed())
themeDir := helpers.GetThemeDir()
if themeDir != "" {
if _, err := os.Stat(themeDir); os.IsNotExist(err) {
jww.FATAL.Fatalln("Unable to find theme Directory:", themeDir)
}
}
themeVersionMismatch, minVersion := helpers.IsThemeVsHugoVersionMismatch()
if themeVersionMismatch {
jww.ERROR.Printf("Current theme does not support Hugo version %s. Minimum version required is %s\n",
helpers.HugoReleaseVersion(), minVersion)
}
}
开发者ID:nicrioux,项目名称:hugo,代码行数:101,代码来源:hugo.go
示例4: InitializeConfig
//.........这里部分代码省略.........
}
}
if baseURL != "" {
if !strings.HasSuffix(baseURL, "/") {
baseURL = baseURL + "/"
}
viper.Set("baseURL", baseURL)
}
if !viper.GetBool("relativeURLs") && viper.GetString("baseURL") == "" {
jww.ERROR.Println("No 'baseurl' set in configuration or as a flag. Features like page menus will not work without one.")
}
if theme != "" {
viper.Set("theme", theme)
}
if destination != "" {
viper.Set("publishDir", destination)
}
var dir string
if source != "" {
dir, _ = filepath.Abs(source)
} else {
dir, _ = os.Getwd()
}
viper.Set("workingDir", dir)
if contentDir != "" {
viper.Set("contentDir", contentDir)
}
if layoutDir != "" {
viper.Set("layoutDir", layoutDir)
}
if cacheDir != "" {
viper.Set("cacheDir", cacheDir)
}
cacheDir = viper.GetString("cacheDir")
if cacheDir != "" {
if helpers.FilePathSeparator != cacheDir[len(cacheDir)-1:] {
cacheDir = cacheDir + helpers.FilePathSeparator
}
isDir, err := helpers.DirExists(cacheDir, hugofs.Source())
utils.CheckErr(err)
if isDir == false {
mkdir(cacheDir)
}
viper.Set("cacheDir", cacheDir)
} else {
viper.Set("cacheDir", helpers.GetTempDir("hugo_cache", hugofs.Source()))
}
if verboseLog || logging || (viper.IsSet("logFile") && viper.GetString("logFile") != "") {
if viper.IsSet("logFile") && viper.GetString("logFile") != "" {
jww.SetLogFile(viper.GetString("logFile"))
} else {
jww.UseTempLogFile("hugo")
}
} else {
jww.DiscardLogging()
}
if quiet {
jww.SetStdoutThreshold(jww.LevelError)
} else if viper.GetBool("verbose") {
jww.SetStdoutThreshold(jww.LevelInfo)
}
if verboseLog {
jww.SetLogThreshold(jww.LevelInfo)
}
jww.INFO.Println("Using config file:", viper.ConfigFileUsed())
// Init file systems. This may be changed at a later point.
hugofs.InitDefaultFs()
themeDir := helpers.GetThemeDir()
if themeDir != "" {
if _, err := hugofs.Source().Stat(themeDir); os.IsNotExist(err) {
return newSystemError("Unable to find theme Directory:", themeDir)
}
}
themeVersionMismatch, minVersion := isThemeVsHugoVersionMismatch()
if themeVersionMismatch {
jww.ERROR.Printf("Current theme does not support Hugo version %s. Minimum version required is %s\n",
helpers.HugoReleaseVersion(), minVersion)
}
return nil
}
开发者ID:tubo028,项目名称:hugo,代码行数:101,代码来源:hugo.go
示例5: 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
示例6: 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
注:本文中的github.com/spf13/hugo/helpers.GetThemeDir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论