Config: Do not search empty template paths for files #2946
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
bfdb436724
commit
6806e74f7d
|
@ -107,8 +107,10 @@ func (c *Config) TemplatesPath() string {
|
||||||
|
|
||||||
// CustomTemplatesPath returns the path to custom templates.
|
// CustomTemplatesPath returns the path to custom templates.
|
||||||
func (c *Config) CustomTemplatesPath() string {
|
func (c *Config) CustomTemplatesPath() string {
|
||||||
if p := c.CustomAssetsPath(); p != "" {
|
if dir := c.CustomAssetsPath(); dir == "" {
|
||||||
return filepath.Join(p, "templates")
|
return ""
|
||||||
|
} else if dir = filepath.Join(dir, "templates"); fs.PathExists(dir) {
|
||||||
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
@ -118,10 +120,22 @@ func (c *Config) CustomTemplatesPath() string {
|
||||||
func (c *Config) TemplateFiles() []string {
|
func (c *Config) TemplateFiles() []string {
|
||||||
results := make([]string, 0, 32)
|
results := make([]string, 0, 32)
|
||||||
|
|
||||||
tmplPaths := []string{c.TemplatesPath(), c.CustomTemplatesPath()}
|
var tmplPaths []string
|
||||||
|
|
||||||
for _, p := range tmplPaths {
|
// Path set for custom templates?
|
||||||
matches, err := filepath.Glob(regexp.QuoteMeta(p) + "/[A-Za-z0-9]*.*")
|
if cDir := c.CustomTemplatesPath(); cDir != "" {
|
||||||
|
tmplPaths = []string{c.TemplatesPath(), cDir}
|
||||||
|
} else {
|
||||||
|
tmplPaths = []string{c.TemplatesPath()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find template files.
|
||||||
|
for _, dir := range tmplPaths {
|
||||||
|
if dir == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
matches, err := filepath.Glob(regexp.QuoteMeta(dir) + "/[A-Za-z0-9]*.*")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
@ -139,8 +153,8 @@ func (c *Config) TemplateFiles() []string {
|
||||||
func (c *Config) TemplateExists(name string) bool {
|
func (c *Config) TemplateExists(name string) bool {
|
||||||
if found := fs.FileExists(filepath.Join(c.TemplatesPath(), name)); found {
|
if found := fs.FileExists(filepath.Join(c.TemplatesPath(), name)); found {
|
||||||
return true
|
return true
|
||||||
} else if p := c.CustomTemplatesPath(); p != "" {
|
} else if dir := c.CustomTemplatesPath(); dir != "" {
|
||||||
return fs.FileExists(filepath.Join(p, name))
|
return fs.FileExists(filepath.Join(dir, name))
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue