mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
Normalize paths within hugo
filepath was used inconsistently throughout the hugolib. With the introduction of source and target modules, all path are normalized to "/". This simplifies the processing of paths. It does mean that contributors need to be aware of using path/filepath in any module other than source or target is not recommended. The current exception is hugolib/config.go
This commit is contained in:
@@ -103,7 +103,7 @@ func (c *Config) readInConfig() {
|
||||
|
||||
func (c *Config) setPath(p string) {
|
||||
if p == "" {
|
||||
path, err := FindPath()
|
||||
path, err := findPath()
|
||||
if err != nil {
|
||||
fmt.Printf("Error finding path: %s", err)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func (c *Config) GetPath() string {
|
||||
return c.Path
|
||||
}
|
||||
|
||||
func FindPath() (string, error) {
|
||||
func findPath() (string, error) {
|
||||
serverFile, err := filepath.Abs(os.Args[0])
|
||||
|
||||
if err != nil {
|
||||
@@ -147,13 +147,14 @@ func FindPath() (string, error) {
|
||||
return path, nil
|
||||
}
|
||||
|
||||
// GetAbsPath return the absolute path for a given path with the internal slashes
|
||||
// properly converted.
|
||||
func (c *Config) GetAbsPath(name string) string {
|
||||
if filepath.IsAbs(name) {
|
||||
return name
|
||||
}
|
||||
|
||||
p := filepath.Join(c.GetPath(), name)
|
||||
return p
|
||||
return filepath.ToSlash(filepath.Join(c.GetPath(), name))
|
||||
}
|
||||
|
||||
func (c *Config) findConfigFile(configFileName string) (string, error) {
|
||||
|
Reference in New Issue
Block a user