mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
1046e9363f
commit
db85e83403
2 changed files with 5 additions and 1 deletions
|
@ -70,8 +70,10 @@ func (r Resources) ByType(tp string) Resources {
|
|||
// "logo" will match logo.png. It returns nil of none found.
|
||||
// In potential ambiguous situations, combine it with ByType.
|
||||
func (r Resources) GetByPrefix(prefix string) Resource {
|
||||
prefix = strings.ToLower(prefix)
|
||||
for _, resource := range r {
|
||||
_, name := filepath.Split(resource.RelPermalink())
|
||||
name = strings.ToLower(name)
|
||||
if strings.HasPrefix(name, prefix) {
|
||||
return resource
|
||||
}
|
||||
|
|
|
@ -113,12 +113,14 @@ func TestResourcesGetByPrefix(t *testing.T) {
|
|||
resources := Resources{
|
||||
spec.newGenericResource(nil, nil, "/public", "/a/foo1.css", "foo1.css", "css"),
|
||||
spec.newGenericResource(nil, nil, "/public", "/a/logo1.png", "logo1.png", "image"),
|
||||
spec.newGenericResource(nil, nil, "/public", "/b/logo2.png", "logo2.png", "image"),
|
||||
spec.newGenericResource(nil, nil, "/public", "/b/Logo2.png", "Logo2.png", "image"),
|
||||
spec.newGenericResource(nil, nil, "/public", "/b/foo2.css", "foo2.css", "css"),
|
||||
spec.newGenericResource(nil, nil, "/public", "/b/foo3.css", "foo3.css", "css")}
|
||||
|
||||
assert.Nil(resources.GetByPrefix("asdf"))
|
||||
assert.Equal("/logo1.png", resources.GetByPrefix("logo").RelPermalink())
|
||||
assert.Equal("/logo1.png", resources.GetByPrefix("loGo").RelPermalink())
|
||||
assert.Equal("/Logo2.png", resources.GetByPrefix("logo2").RelPermalink())
|
||||
assert.Equal("/foo2.css", resources.GetByPrefix("foo2").RelPermalink())
|
||||
assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink())
|
||||
assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink())
|
||||
|
|
Loading…
Reference in a new issue