blob: 66f3145685d06e1d04573facb4b00bd783f12dd4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package thumb
import (
"path/filepath"
"strings"
)
// DirName is the on-disk directory name used to store generated thumbnails.
// It is a hidden subdirectory placed alongside the source media files.
const DirName = ".thumbnails"
// thumbExt is the canonical extension used for all generated thumbnails.
// Thumbnails are always JPEGs regardless of the source media type.
const thumbExt = ".jpg"
// ThumbnailDir returns the conventional thumbnail directory inside parent.
// The directory is a hidden ".thumbnails" subfolder sitting next to the
// source media. filepath.Join handles any trailing slashes on parent.
func ThumbnailDir(parent string) string {
return filepath.Join(parent, DirName)
}
// ThumbnailNameFor returns the canonical thumbnail filename for the given
// source file (basename without extension + ".jpg"). For dotfiles (e.g.
// ".bashrc") filepath.Ext returns the leading-dot name itself; TrimSuffix
// then yields an empty base, producing just ".jpg" — matching the historical
// behaviour of the inlined helpers being replaced.
func ThumbnailNameFor(srcPath string) string {
base := filepath.Base(srcPath)
return strings.TrimSuffix(base, filepath.Ext(base)) + thumbExt
}
// ThumbnailPathFor returns the full path to the thumbnail for srcPath stored
// under parent/.thumbnails/. parent is the directory that should contain the
// thumbnail folder (typically the set directory or the source's parent dir).
func ThumbnailPathFor(srcPath, parent string) string {
return filepath.Join(ThumbnailDir(parent), ThumbnailNameFor(srcPath))
}
|