本文整理汇总了Golang中github.com/spf13/hugo/helpers.AbsPathify函数的典型用法代码示例。如果您正苦于以下问题:Golang AbsPathify函数的具体用法?Golang AbsPathify怎么用?Golang AbsPathify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AbsPathify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: serve
func serve(port int) {
jww.FEEDBACK.Println("Serving pages from " + helpers.AbsPathify(viper.GetString("PublishDir")))
httpFs := &afero.HttpFs{SourceFs: hugofs.DestinationFS}
fileserver := http.FileServer(httpFs.Dir(helpers.AbsPathify(viper.GetString("PublishDir"))))
u, err := url.Parse(viper.GetString("BaseUrl"))
if err != nil {
jww.ERROR.Fatalf("Invalid BaseUrl: %s", err)
}
if u.Path == "" || u.Path == "/" {
http.Handle("/", fileserver)
} else {
http.Handle(u.Path, http.StripPrefix(u.Path, fileserver))
}
u.Scheme = "http"
jww.FEEDBACK.Printf("Web Server is available at %s\n", u.String())
fmt.Println("Press Ctrl+C to stop")
err = http.ListenAndServe(":"+strconv.Itoa(port), nil)
if err != nil {
jww.ERROR.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
}
示例2: copyStatic
func copyStatic() error {
staticDir := helpers.AbsPathify(viper.GetString("StaticDir")) + "/"
if _, err := os.Stat(staticDir); os.IsNotExist(err) {
jww.ERROR.Println("Unable to find Static Directory:", staticDir)
return nil
}
publishDir := helpers.AbsPathify(viper.GetString("PublishDir")) + "/"
syncer := fsync.NewSyncer()
syncer.NoTimes = viper.GetBool("notimes")
syncer.SrcFs = hugofs.SourceFs
syncer.DestFs = hugofs.DestinationFS
themeDir, err := helpers.GetThemeStaticDirPath()
if err != nil {
jww.ERROR.Println(err)
return nil
}
if themeDir != "" {
// Copy Static to Destination
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 Static to Destination
jww.INFO.Println("syncing from", staticDir, "to", publishDir)
return syncer.Sync(publishDir, staticDir)
}
示例3: FindArchetype
func FindArchetype(kind string) (outpath string) {
search := []string{helpers.AbsPathify(viper.GetString("archetypeDir"))}
if viper.GetString("theme") != "" {
themeDir := path.Join(helpers.AbsPathify("themes/"+viper.GetString("theme")), "/archetypes/")
if _, err := os.Stat(themeDir); os.IsNotExist(err) {
jww.ERROR.Println("Unable to find archetypes directory for theme :", viper.GetString("theme"), "in", themeDir)
} else {
search = append(search, themeDir)
}
}
for _, x := range search {
// If the new content isn't in a subdirectory, kind == "".
// Therefore it should be excluded otherwise `is a directory`
// error will occur. github.com/spf13/hugo/issues/411
var pathsToCheck []string
if kind == "" {
pathsToCheck = []string{"default.md", "default"}
} else {
pathsToCheck = []string{kind + ".md", kind, "default.md", "default"}
}
for _, p := range pathsToCheck {
curpath := path.Join(x, p)
jww.DEBUG.Println("checking", curpath, "for archetypes")
if exists, _ := helpers.Exists(curpath); exists {
jww.INFO.Println("curpath: " + curpath)
return curpath
}
}
}
return ""
}
示例4: copyStatic
func copyStatic() error {
publishDir := helpers.AbsPathify(viper.GetString("PublishDir")) + "/"
// If root, remove the second '/'
if publishDir == "//" {
publishDir = "/"
}
syncer := fsync.NewSyncer()
syncer.NoTimes = viper.GetBool("notimes")
syncer.SrcFs = hugofs.SourceFs
syncer.DestFs = hugofs.DestinationFS
themeDir, err := helpers.GetThemeStaticDirPath()
if err != nil {
jww.ERROR.Println(err)
return nil
}
// 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.AbsPathify(viper.GetString("StaticDir")) + "/"
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
}
示例5: build
func build(watches ...bool) error {
// Hugo writes the output to memory instead of the disk
// This is only used for benchmark testing. Cause the content is only visible
// in memory
if renderToMemory {
hugofs.DestinationFS = new(afero.MemMapFs)
// Rendering to memoryFS, publish to Root regardless of publishDir.
viper.Set("PublishDir", "/")
}
if err := copyStatic(); err != nil {
return fmt.Errorf("Error copying static files to %s: %s", helpers.AbsPathify(viper.GetString("PublishDir")), err)
}
watch := false
if len(watches) > 0 && watches[0] {
watch = true
}
if err := buildSite(buildWatch || watch); err != nil {
return fmt.Errorf("Error building site: %s", err)
}
if buildWatch {
jww.FEEDBACK.Println("Watching for changes in", helpers.AbsPathify(viper.GetString("ContentDir")))
jww.FEEDBACK.Println("Press Ctrl+C to stop")
utils.CheckErr(NewWatcher(0))
}
return nil
}
示例6: copyStatic
func copyStatic() error {
staticDir := helpers.AbsPathify(viper.GetString("StaticDir")) + "/"
if _, err := os.Stat(staticDir); os.IsNotExist(err) {
jww.ERROR.Println("Unable to find Static Directory:", viper.GetString("theme"), "in", staticDir)
return nil
}
publishDir := helpers.AbsPathify(viper.GetString("PublishDir")) + "/"
if themeSet() {
themeDir := helpers.AbsPathify("themes/"+viper.GetString("theme")) + "/static/"
if _, err := os.Stat(themeDir); os.IsNotExist(err) {
jww.ERROR.Println("Unable to find static directory for theme :", viper.GetString("theme"), "in", themeDir)
return nil
}
// Copy Static to Destination
jww.INFO.Println("syncing from", themeDir, "to", publishDir)
utils.CheckErr(fsync.Sync(publishDir, themeDir), fmt.Sprintf("Error copying static files of theme to %s", publishDir))
}
// Copy Static to Destination
jww.INFO.Println("syncing from", staticDir, "to", publishDir)
return fsync.Sync(publishDir, staticDir)
}
示例7: FindArchetype
func FindArchetype(kind string) (outpath string) {
search := []string{helpers.AbsPathify(viper.GetString("archetypeDir"))}
if viper.GetString("theme") != "" {
themeDir := path.Join(helpers.AbsPathify("themes/"+viper.GetString("theme")), "/archetypes/")
if _, err := os.Stat(themeDir); os.IsNotExist(err) {
jww.ERROR.Println("Unable to find archetypes directory for theme :", viper.GetString("theme"), "in", themeDir)
} else {
search = append(search, themeDir)
}
}
for _, x := range search {
pathsToCheck := []string{kind + ".md", kind, "default.md", "default"}
for _, p := range pathsToCheck {
curpath := path.Join(x, p)
jww.DEBUG.Println("checking", curpath, "for archetypes")
if exists, _ := helpers.Exists(curpath); exists {
return curpath
}
}
}
return ""
}
示例8: serve
func serve(port int) {
jww.FEEDBACK.Println("Serving pages from " + helpers.AbsPathify(viper.GetString("PublishDir")))
httpFs := &afero.HttpFs{SourceFs: hugofs.DestinationFS}
fs := filesOnlyFs{httpFs.Dir(helpers.AbsPathify(viper.GetString("PublishDir")))}
fileserver := http.FileServer(fs)
// We're only interested in the path
u, err := url.Parse(viper.GetString("BaseURL"))
if err != nil {
jww.ERROR.Fatalf("Invalid BaseURL: %s", err)
}
if u.Path == "" || u.Path == "/" {
http.Handle("/", fileserver)
} else {
http.Handle(u.Path, http.StripPrefix(u.Path, fileserver))
}
u.Scheme = "http"
jww.FEEDBACK.Printf("Web Server is available at %s (bind address %s)\n", u.String(), serverInterface)
fmt.Println("Press Ctrl+C to stop")
endpoint := net.JoinHostPort(serverInterface, strconv.Itoa(port))
err = http.ListenAndServe(endpoint, nil)
if err != nil {
jww.ERROR.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
}
示例9: getDirList
func getDirList() []string {
var a []string
walker := func(path string, fi os.FileInfo, err error) error {
if err != nil {
jww.ERROR.Println("Walker: ", err)
return nil
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
jww.ERROR.Printf("Symbolic links not supported, skipping '%s'", path)
return nil
}
if fi.IsDir() {
a = append(a, path)
}
return nil
}
filepath.Walk(helpers.AbsPathify(viper.GetString("ContentDir")), walker)
filepath.Walk(helpers.AbsPathify(viper.GetString("LayoutDir")), walker)
filepath.Walk(helpers.AbsPathify(viper.GetString("StaticDir")), walker)
if themeSet() {
filepath.Walk(helpers.AbsPathify("themes/"+viper.GetString("theme")), walker)
}
return a
}
示例10: NewContent
// NewContent creates a new content file in the content directory based upon the
// given kind, which is used to lookup an archetype.
func NewContent(fs afero.Fs, kind, name string) (err error) {
jww.INFO.Println("attempting to create ", name, "of", kind)
location := FindArchetype(fs, kind)
var by []byte
if location != "" {
by, err = afero.ReadFile(fs, 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 := createMetadata(psr, name)
if err != nil {
jww.ERROR.Printf("Error processing archetype file %s: %s\n", location, err)
return err
}
page, err := hugolib.NewPage(name)
if err != nil {
return err
}
if err = page.SetSourceMetaData(metadata, parser.FormatToLeadRune(viper.GetString("metaDataFormat"))); err != nil {
return
}
page.SetSourceContent(psr.Content())
if err = page.SafeSaveSourceAs(filepath.Join(viper.GetString("contentDir"), name)); err != nil {
return
}
jww.FEEDBACK.Println(helpers.AbsPathify(filepath.Join(viper.GetString("contentDir"), name)), "created")
editor := viper.GetString("newContentEditor")
if editor != "" {
jww.FEEDBACK.Printf("Editing %s with %q ...\n", name, editor)
cmd := exec.Command(editor, helpers.AbsPathify(path.Join(viper.GetString("contentDir"), name)))
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
return nil
}
示例11: copyStatic
func copyStatic() error {
staticDir := helpers.AbsPathify(viper.GetString("StaticDir")) + "/"
if _, err := os.Stat(staticDir); os.IsNotExist(err) {
return nil
}
publishDir := helpers.AbsPathify(viper.GetString("PublishDir")) + "/"
// Copy Static to Destination
jww.INFO.Println("syncing from", staticDir, "to", publishDir)
return fsync.Sync(publishDir, staticDir)
}
示例12: serve
func serve(port int) {
jww.FEEDBACK.Println("Serving pages from " + helpers.AbsPathify(viper.GetString("PublishDir")))
jww.FEEDBACK.Printf("Web Server is available at %s\n", viper.GetString("BaseUrl"))
fmt.Println("Press ctrl+c to stop")
http.Handle("/", http.FileServer(http.Dir(helpers.AbsPathify(viper.GetString("PublishDir")))))
err := http.ListenAndServe(":"+strconv.Itoa(port), nil)
if err != nil {
jww.ERROR.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
}
示例13: getDirList
// getDirList provides NewWatcher() with a list of directories to watch for changes.
func getDirList() []string {
var a []string
dataDir := helpers.AbsPathify(viper.GetString("DataDir"))
walker := func(path string, fi os.FileInfo, err error) error {
if err != nil {
if path == dataDir && os.IsNotExist(err) {
jww.WARN.Println("Skip DataDir:", err)
return nil
}
jww.ERROR.Println("Walker: ", err)
return nil
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
link, err := filepath.EvalSymlinks(path)
if err != nil {
jww.ERROR.Printf("Cannot read symbolic link '%s', error was: %s", path, 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'", path)
}
return nil
}
if fi.IsDir() {
if fi.Name() == ".git" ||
fi.Name() == "node_modules" || fi.Name() == "bower_components" {
return filepath.SkipDir
}
a = append(a, path)
}
return nil
}
filepath.Walk(dataDir, walker)
filepath.Walk(helpers.AbsPathify(viper.GetString("ContentDir")), walker)
filepath.Walk(helpers.AbsPathify(viper.GetString("LayoutDir")), walker)
filepath.Walk(helpers.AbsPathify(viper.GetString("StaticDir")), walker)
if helpers.ThemeSet() {
filepath.Walk(helpers.AbsPathify("themes/"+viper.GetString("theme")), walker)
}
return a
}
示例14: build
func build(watches ...bool) {
utils.CheckErr(copyStatic(), fmt.Sprintf("Error copying static files to %s", helpers.AbsPathify(viper.GetString("PublishDir"))))
watch := false
if len(watches) > 0 && watches[0] {
watch = true
}
utils.StopOnErr(buildSite(BuildWatch || watch))
if BuildWatch {
jww.FEEDBACK.Println("Watching for changes in", helpers.AbsPathify(viper.GetString("ContentDir")))
jww.FEEDBACK.Println("Press Ctrl+C to stop")
utils.CheckErr(NewWatcher(0))
}
}
示例15: copyStatic
func copyStatic() error {
publishDir := helpers.AbsPathify(viper.GetString("publishDir")) + helpers.FilePathSeparator
// If root, remove the second '/'
if publishDir == "//" {
publishDir = helpers.FilePathSeparator
}
// Includes both theme/static & /static
staticSourceFs := getStaticSourceFs()
if staticSourceFs == nil {
jww.WARN.Println("No static directories found to sync")
return nil
}
syncer := fsync.NewSyncer()
syncer.NoTimes = viper.GetBool("notimes")
syncer.SrcFs = staticSourceFs
syncer.DestFs = hugofs.Destination()
// Now that we are using a unionFs for the static directories
// We can effectively clean the publishDir on initial sync
syncer.Delete = viper.GetBool("cleanDestinationDir")
if syncer.Delete {
jww.INFO.Println("removing all files from destination that don't exist in static dirs")
}
jww.INFO.Println("syncing static files to", publishDir)
// because we are using a baseFs (to get the union right).
// set sync src to root
return syncer.Sync(publishDir, helpers.FilePathSeparator)
}