本文整理汇总了Golang中github.com/spf13/hugo/helpers.GetStaticDirPath函数的典型用法代码示例。如果您正苦于以下问题:Golang GetStaticDirPath函数的具体用法?Golang GetStaticDirPath怎么用?Golang GetStaticDirPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetStaticDirPath函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: copyStatic
func copyStatic() error {
publishDir := helpers.AbsPathify(viper.GetString("PublishDir")) + helpers.FilePathSeparator
// If root, remove the second '/'
if publishDir == "//" {
publishDir = helpers.FilePathSeparator
}
syncer := fsync.NewSyncer()
syncer.NoTimes = viper.GetBool("notimes")
syncer.SrcFs = hugofs.SourceFs
syncer.DestFs = hugofs.DestinationFS
themeDir, err := helpers.GetThemeStaticDirPath()
if err != nil {
jww.WARN.Println(err)
}
// Copy the theme's static directory
if themeDir != "" {
jww.INFO.Println("syncing from", themeDir, "to", publishDir)
utils.CheckErr(syncer.Sync(publishDir, themeDir), fmt.Sprintf("Error copying static files of theme to %s", publishDir))
}
// Copy the site's own static directory
staticDir := helpers.GetStaticDirPath() + helpers.FilePathSeparator
if _, err := os.Stat(staticDir); err == nil {
jww.INFO.Println("syncing from", staticDir, "to", publishDir)
return syncer.Sync(publishDir, staticDir)
} else if os.IsNotExist(err) {
jww.WARN.Println("Unable to find Static Directory:", staticDir)
}
return nil
}
开发者ID:jacksonjp,项目名称:hugo,代码行数:34,代码来源:hugo.go
示例2: getStaticSourceFs
func getStaticSourceFs() afero.Fs {
source := hugofs.SourceFs
themeDir, err := helpers.GetThemeStaticDirPath()
staticDir := helpers.GetStaticDirPath() + helpers.FilePathSeparator
useTheme := true
useStatic := true
if err != nil {
jww.WARN.Println(err)
useTheme = false
} else {
if _, err := source.Stat(themeDir); os.IsNotExist(err) {
jww.WARN.Println("Unable to find Theme Static Directory:", themeDir)
useTheme = false
}
}
if _, err := source.Stat(staticDir); os.IsNotExist(err) {
jww.WARN.Println("Unable to find Static Directory:", staticDir)
useStatic = false
}
if !useStatic && !useTheme {
return nil
}
if !useStatic {
jww.INFO.Println(themeDir, "is the only static directory available to sync from")
return afero.NewReadOnlyFs(afero.NewBasePathFs(source, themeDir))
}
if !useTheme {
jww.INFO.Println(staticDir, "is the only static directory available to sync from")
return afero.NewReadOnlyFs(afero.NewBasePathFs(source, staticDir))
}
jww.INFO.Println("using a UnionFS for static directory comprised of:")
jww.INFO.Println("Base:", themeDir)
jww.INFO.Println("Overlay:", staticDir)
base := afero.NewReadOnlyFs(afero.NewBasePathFs(hugofs.SourceFs, themeDir))
overlay := afero.NewReadOnlyFs(afero.NewBasePathFs(hugofs.SourceFs, staticDir))
return afero.NewCopyOnWriteFs(base, overlay)
}
开发者ID:nitoyon,项目名称:hugo,代码行数:44,代码来源:hugo.go
示例3: getStaticSourceFs
func getStaticSourceFs() afero.Fs {
source := hugofs.SourceFs
themeDir, err := helpers.GetThemeStaticDirPath()
staticDir := helpers.GetStaticDirPath() + helpers.FilePathSeparator
useTheme := true
useStatic := true
if err != nil {
jww.WARN.Println(err)
useTheme = false
} else {
if _, err := source.Stat(themeDir); os.IsNotExist(err) {
jww.WARN.Println("Unable to find Theme Static Directory:", themeDir)
useTheme = false
}
}
if _, err := source.Stat(staticDir); os.IsNotExist(err) {
jww.WARN.Println("Unable to find Static Directory:", staticDir)
useStatic = false
}
if !useStatic && !useTheme {
return nil
}
if !useStatic {
return afero.NewReadOnlyFs(afero.NewBasePathFs(source, themeDir))
}
if !useTheme {
return afero.NewReadOnlyFs(afero.NewBasePathFs(source, staticDir))
}
base := afero.NewReadOnlyFs(afero.NewBasePathFs(hugofs.SourceFs, themeDir))
overlay := afero.NewReadOnlyFs(afero.NewBasePathFs(hugofs.SourceFs, staticDir))
return afero.NewCopyOnWriteFs(base, overlay)
}
开发者ID:orozcoig,项目名称:hugo,代码行数:39,代码来源:hugo.go
示例4: NewWatcher
// NewWatcher creates a new watcher to watch filesystem events.
func NewWatcher(port int) error {
if runtime.GOOS == "darwin" {
tweakLimit()
}
watcher, err := watcher.New(1 * time.Second)
var wg sync.WaitGroup
if err != nil {
return err
}
defer watcher.Close()
wg.Add(1)
for _, d := range getDirList() {
if d != "" {
_ = watcher.Add(d)
}
}
go func() {
for {
select {
case evs := <-watcher.Events:
jww.INFO.Println("Received System Events:", evs)
staticEvents := []fsnotify.Event{}
dynamicEvents := []fsnotify.Event{}
for _, ev := range evs {
ext := filepath.Ext(ev.Name)
istemp := strings.HasSuffix(ext, "~") ||
(ext == ".swp") ||
(ext == ".swx") ||
(ext == ".tmp") ||
(ext == ".DS_Store") ||
filepath.Base(ev.Name) == "4913" ||
strings.HasPrefix(ext, ".goutputstream") ||
strings.HasSuffix(ext, "jb_old___") ||
strings.HasSuffix(ext, "jb_bak___")
if istemp {
continue
}
// Sometimes during rm -rf operations a '"": REMOVE' is triggered. Just ignore these
if ev.Name == "" {
continue
}
// Write and rename operations are often followed by CHMOD.
// There may be valid use cases for rebuilding the site on CHMOD,
// but that will require more complex logic than this simple conditional.
// On OS X this seems to be related to Spotlight, see:
// https://github.com/go-fsnotify/fsnotify/issues/15
// A workaround is to put your site(s) on the Spotlight exception list,
// but that may be a little mysterious for most end users.
// So, for now, we skip reload on CHMOD.
if ev.Op&fsnotify.Chmod == fsnotify.Chmod {
continue
}
walkAdder := func(path string, f os.FileInfo, err error) error {
if f.IsDir() {
jww.FEEDBACK.Println("adding created directory to watchlist", path)
watcher.Add(path)
}
return nil
}
// recursively add new directories to watch list
// When mkdir -p is used, only the top directory triggers an event (at least on OSX)
if ev.Op&fsnotify.Create == fsnotify.Create {
if s, err := hugofs.SourceFs.Stat(ev.Name); err == nil && s.Mode().IsDir() {
afero.Walk(hugofs.SourceFs, ev.Name, walkAdder)
}
}
isstatic := strings.HasPrefix(ev.Name, helpers.GetStaticDirPath()) || (len(helpers.GetThemesDirPath()) > 0 && strings.HasPrefix(ev.Name, helpers.GetThemesDirPath()))
if isstatic {
staticEvents = append(staticEvents, ev)
} else {
dynamicEvents = append(dynamicEvents, ev)
}
}
if len(staticEvents) > 0 {
publishDir := helpers.AbsPathify(viper.GetString("PublishDir")) + helpers.FilePathSeparator
// If root, remove the second '/'
if publishDir == "//" {
publishDir = helpers.FilePathSeparator
}
jww.FEEDBACK.Println("\nStatic file changes detected")
const layout = "2006-01-02 15:04 -0700"
fmt.Println(time.Now().Format(layout))
//.........这里部分代码省略.........
开发者ID:nitoyon,项目名称:hugo,代码行数:101,代码来源:hugo.go
示例5: NewWatcher
// NewWatcher creates a new watcher to watch filesystem events.
func NewWatcher(port int) error {
if runtime.GOOS == "darwin" {
tweakLimit()
}
watcher, err := watcher.New(1 * time.Second)
var wg sync.WaitGroup
if err != nil {
fmt.Println(err)
return err
}
defer watcher.Close()
wg.Add(1)
for _, d := range getDirList() {
if d != "" {
_ = watcher.Add(d)
}
}
go func() {
for {
select {
case evs := <-watcher.Events:
jww.INFO.Println("File System Event:", evs)
staticChanged := false
dynamicChanged := false
staticFilesChanged := make(map[string]bool)
for _, ev := range evs {
ext := filepath.Ext(ev.Name)
istemp := strings.HasSuffix(ext, "~") || (ext == ".swp") || (ext == ".swx") || (ext == ".tmp") || strings.HasPrefix(ext, ".goutputstream")
if istemp {
continue
}
// renames are always followed with Create/Modify
if ev.Op&fsnotify.Rename == fsnotify.Rename {
continue
}
isstatic := strings.HasPrefix(ev.Name, helpers.GetStaticDirPath()) || (len(helpers.GetThemesDirPath()) > 0 && strings.HasPrefix(ev.Name, helpers.GetThemesDirPath()))
staticChanged = staticChanged || isstatic
dynamicChanged = dynamicChanged || !isstatic
if isstatic {
if staticPath, err := helpers.MakeStaticPathRelative(ev.Name); err == nil {
staticFilesChanged[staticPath] = true
}
}
// add new directory to watch list
if s, err := os.Stat(ev.Name); err == nil && s.Mode().IsDir() {
if ev.Op&fsnotify.Create == fsnotify.Create {
watcher.Add(ev.Name)
}
}
}
if staticChanged {
jww.FEEDBACK.Printf("Static file changed, syncing\n\n")
utils.StopOnErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", helpers.AbsPathify(viper.GetString("PublishDir"))))
if !BuildWatch && !viper.GetBool("DisableLiveReload") {
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initalized
// force refresh when more than one file
if len(staticFilesChanged) == 1 {
for path := range staticFilesChanged {
livereload.RefreshPath(path)
}
} else {
livereload.ForceRefresh()
}
}
}
if dynamicChanged {
fmt.Print("\nChange detected, rebuilding site\n")
const layout = "2006-01-02 15:04 -0700"
fmt.Println(time.Now().Format(layout))
utils.CheckErr(buildSite(true))
if !BuildWatch && !viper.GetBool("DisableLiveReload") {
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initalized
livereload.ForceRefresh()
}
}
case err := <-watcher.Errors:
if err != nil {
fmt.Println("error:", err)
}
}
}
}()
//.........这里部分代码省略.........
开发者ID:nicrioux,项目名称:hugo,代码行数:101,代码来源:hugo.go
示例6: NewWatcher
// NewWatcher creates a new watcher to watch filesystem events.
func NewWatcher(port int) error {
if runtime.GOOS == "darwin" {
tweakLimit()
}
watcher, err := watcher.New(1 * time.Second)
var wg sync.WaitGroup
if err != nil {
return err
}
defer watcher.Close()
wg.Add(1)
for _, d := range getDirList() {
if d != "" {
_ = watcher.Add(d)
}
}
go func() {
for {
select {
case evs := <-watcher.Events:
jww.INFO.Println("File System Event:", evs)
staticChanged := false
dynamicChanged := false
staticFilesChanged := make(map[string]bool)
for _, ev := range evs {
ext := filepath.Ext(ev.Name)
istemp := strings.HasSuffix(ext, "~") || (ext == ".swp") || (ext == ".swx") || (ext == ".tmp") || strings.HasPrefix(ext, ".goutputstream") || strings.HasSuffix(ext, "jb_old___") || strings.HasSuffix(ext, "jb_bak___")
if istemp {
continue
}
// renames are always followed with Create/Modify
if ev.Op&fsnotify.Rename == fsnotify.Rename {
continue
}
// Write and rename operations are often followed by CHMOD.
// There may be valid use cases for rebuilding the site on CHMOD,
// but that will require more complex logic than this simple conditional.
// On OS X this seems to be related to Spotlight, see:
// https://github.com/go-fsnotify/fsnotify/issues/15
// A workaround is to put your site(s) on the Spotlight exception list,
// but that may be a little mysterious for most end users.
// So, for now, we skip reload on CHMOD.
if ev.Op&fsnotify.Chmod == fsnotify.Chmod {
continue
}
isstatic := strings.HasPrefix(ev.Name, helpers.GetStaticDirPath()) || (len(helpers.GetThemesDirPath()) > 0 && strings.HasPrefix(ev.Name, helpers.GetThemesDirPath()))
staticChanged = staticChanged || isstatic
dynamicChanged = dynamicChanged || !isstatic
if isstatic {
staticFilesChanged[ev.Name] = true
}
// add new directory to watch list
if s, err := os.Stat(ev.Name); err == nil && s.Mode().IsDir() {
if ev.Op&fsnotify.Create == fsnotify.Create {
watcher.Add(ev.Name)
}
}
}
if staticChanged {
jww.FEEDBACK.Printf("Static file changed, syncing\n")
if viper.GetBool("ForceSyncStatic") {
jww.FEEDBACK.Printf("Syncing all static files\n")
err := copyStatic()
if err != nil {
fmt.Println(err)
utils.StopOnErr(err, fmt.Sprintf("Error copying static files to %s", helpers.AbsPathify(viper.GetString("PublishDir"))))
}
} else {
syncer := fsync.NewSyncer()
syncer.NoTimes = viper.GetBool("notimes")
syncer.SrcFs = hugofs.SourceFs
syncer.DestFs = hugofs.DestinationFS
publishDir := helpers.AbsPathify(viper.GetString("PublishDir")) + helpers.FilePathSeparator
if publishDir == "//" || publishDir == helpers.FilePathSeparator {
publishDir = ""
}
staticDir := helpers.GetStaticDirPath()
themeStaticDir := helpers.GetThemesDirPath()
jww.FEEDBACK.Printf("StaticDir '%s'\nThemeStaticDir '%s'\n", staticDir, themeStaticDir)
for path := range staticFilesChanged {
//.........这里部分代码省略.........
开发者ID:jacksonjp,项目名称:hugo,代码行数:101,代码来源:hugo.go
注:本文中的github.com/spf13/hugo/helpers.GetStaticDirPath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论