Index: Use automatically detected relative name #391
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
48407b4526
commit
3f46f95894
3 changed files with 38 additions and 2 deletions
|
@ -170,7 +170,7 @@ func (ind *Index) Start(opt IndexOptions) fs.Done {
|
|||
continue
|
||||
}
|
||||
|
||||
if f.FileName() != fileName && ind.files.Ignore(f.RelName(originalsPath), f.ModTime(), opt.Rescan) {
|
||||
if f.FileName() != fileName && ind.files.Ignore(f.RootRelName(), f.ModTime(), opt.Rescan) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -340,6 +340,8 @@ func (m *MediaFile) PathNameInfo() (fileRoot, fileBase, relativePath, relativeNa
|
|||
rootPath = Config().SidecarPath()
|
||||
case entity.RootImport:
|
||||
rootPath = Config().ImportPath()
|
||||
case entity.RootExamples:
|
||||
rootPath = Config().ExamplesPath()
|
||||
default:
|
||||
rootPath = Config().OriginalsPath()
|
||||
}
|
||||
|
@ -366,6 +368,24 @@ func (m *MediaFile) SetFileName(fileName string) {
|
|||
m.fileName = fileName
|
||||
}
|
||||
|
||||
// RootRelName returns the relative filename and automatically detects the root path.
|
||||
func (m *MediaFile) RootRelName() string {
|
||||
var rootPath string
|
||||
|
||||
switch m.Root() {
|
||||
case entity.RootSidecar:
|
||||
rootPath = Config().SidecarPath()
|
||||
case entity.RootImport:
|
||||
rootPath = Config().ImportPath()
|
||||
case entity.RootExamples:
|
||||
rootPath = Config().ExamplesPath()
|
||||
default:
|
||||
rootPath = Config().OriginalsPath()
|
||||
}
|
||||
|
||||
return m.RelName(rootPath)
|
||||
}
|
||||
|
||||
// RelName returns the relative filename.
|
||||
func (m *MediaFile) RelName(directory string) string {
|
||||
return fs.RelName(m.fileName, directory)
|
||||
|
|
|
@ -625,10 +625,26 @@ func TestMediaFile_SetFilename(t *testing.T) {
|
|||
assert.Equal(t, "turtle_brown_blue", mediaFile.fileName)
|
||||
}
|
||||
|
||||
func TestMediaFile_RelativeFilename(t *testing.T) {
|
||||
func TestMediaFile_RootRelName(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/tree_white.jpg")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Run("examples_path", func(t *testing.T) {
|
||||
filename := mediaFile.RootRelName()
|
||||
assert.Equal(t, "tree_white.jpg", filename)
|
||||
})
|
||||
}
|
||||
|
||||
func TestMediaFile_RelName(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/tree_white.jpg")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue