mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
332b65e4cc
commit
beabc8d998
2 changed files with 19 additions and 1 deletions
|
@ -614,10 +614,19 @@ func (c *Client) shouldVendor(path string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) createThemeDirname(modulePath string, isProjectMod bool) (string, error) {
|
func (c *Client) createThemeDirname(modulePath string, isProjectMod bool) (string, error) {
|
||||||
|
invalid := errors.Errorf("invalid module path %q; must be relative to themesDir when defined outside of the project", modulePath)
|
||||||
|
|
||||||
modulePath = filepath.Clean(modulePath)
|
modulePath = filepath.Clean(modulePath)
|
||||||
|
if filepath.IsAbs(modulePath) {
|
||||||
|
if isProjectMod {
|
||||||
|
return modulePath, nil
|
||||||
|
}
|
||||||
|
return "", invalid
|
||||||
|
}
|
||||||
|
|
||||||
moduleDir := filepath.Join(c.ccfg.ThemesDir, modulePath)
|
moduleDir := filepath.Join(c.ccfg.ThemesDir, modulePath)
|
||||||
if !isProjectMod && !strings.HasPrefix(moduleDir, c.ccfg.ThemesDir) {
|
if !isProjectMod && !strings.HasPrefix(moduleDir, c.ccfg.ThemesDir) {
|
||||||
return "", errors.Errorf("invalid module path %q; must be relative to themesDir when defined outside of the project", modulePath)
|
return "", invalid
|
||||||
}
|
}
|
||||||
return moduleDir, nil
|
return moduleDir, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -157,6 +158,14 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
|
||||||
dirname, err = client.createThemeDirname("../../foo", false)
|
dirname, err = client.createThemeDirname("../../foo", false)
|
||||||
c.Assert(err, qt.Not(qt.IsNil))
|
c.Assert(err, qt.Not(qt.IsNil))
|
||||||
|
|
||||||
|
absDir := filepath.Join(client.ccfg.WorkingDir, "..", "..")
|
||||||
|
dirname, err = client.createThemeDirname(absDir, true)
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
c.Assert(dirname, qt.Equals, absDir)
|
||||||
|
dirname, err = client.createThemeDirname(absDir, false)
|
||||||
|
fmt.Println(dirname)
|
||||||
|
c.Assert(err, qt.Not(qt.IsNil))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue