mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
Support files in content mounts
This commit is a general improvement of handling if single file mounts. Fixes #6684 Fixes #6696
This commit is contained in:
@@ -35,6 +35,9 @@ import (
|
||||
|
||||
const (
|
||||
metaKeyFilename = "filename"
|
||||
metaKeyPathFile = "pathFile" // Path of filename relative to a root.
|
||||
metaKeyIsFileMount = "isFileMount" // Whether the source mount was a file.
|
||||
metaKeyMountRoot = "mountRoot"
|
||||
metaKeyOriginalFilename = "originalFilename"
|
||||
metaKeyName = "name"
|
||||
metaKeyPath = "path"
|
||||
@@ -108,10 +111,34 @@ func (f FileMeta) Lang() string {
|
||||
return f.stringV(metaKeyLang)
|
||||
}
|
||||
|
||||
// Path returns the relative file path to where this file is mounted.
|
||||
func (f FileMeta) Path() string {
|
||||
return f.stringV(metaKeyPath)
|
||||
}
|
||||
|
||||
// PathFile returns the relative file path for the file source. This
|
||||
// will in most cases be the same as Path.
|
||||
func (f FileMeta) PathFile() string {
|
||||
pf := f.stringV(metaKeyPathFile)
|
||||
if f.isFileMount() {
|
||||
return pf
|
||||
}
|
||||
mountRoot := f.mountRoot()
|
||||
if mountRoot == pf {
|
||||
return f.Path()
|
||||
}
|
||||
|
||||
return pf + (strings.TrimPrefix(f.Path(), mountRoot))
|
||||
}
|
||||
|
||||
func (f FileMeta) mountRoot() string {
|
||||
return f.stringV(metaKeyMountRoot)
|
||||
}
|
||||
|
||||
func (f FileMeta) isFileMount() bool {
|
||||
return f.GetBool(metaKeyIsFileMount)
|
||||
}
|
||||
|
||||
func (f FileMeta) Weight() int {
|
||||
return f.GetInt(metaKeyWeight)
|
||||
}
|
||||
@@ -129,10 +156,6 @@ func (f FileMeta) IsSymlink() bool {
|
||||
return f.GetBool(metaKeyIsSymlink)
|
||||
}
|
||||
|
||||
func (f FileMeta) String() string {
|
||||
return f.Filename()
|
||||
}
|
||||
|
||||
func (f FileMeta) Watch() bool {
|
||||
if v, found := f["watch"]; found {
|
||||
return v.(bool)
|
||||
@@ -210,6 +233,14 @@ func NewFileMetaInfo(fi os.FileInfo, m FileMeta) FileMetaInfo {
|
||||
return &fileInfoMeta{FileInfo: fi, m: m}
|
||||
}
|
||||
|
||||
func copyFileMeta(m FileMeta) FileMeta {
|
||||
c := make(FileMeta)
|
||||
for k, v := range m {
|
||||
c[k] = v
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// Merge metadata, last entry wins.
|
||||
func mergeFileMeta(from, to FileMeta) {
|
||||
if from == nil {
|
||||
|
Reference in New Issue
Block a user