mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
57e10f174e
commit
60c9f3b1c3
2 changed files with 12 additions and 1 deletions
|
@ -111,6 +111,10 @@ func TestPageBundlerSite(t *testing.T) {
|
|||
assert.Contains(firstPage.Content, "TheContent")
|
||||
assert.Len(leafBundle1.Resources, 6) // 2 pages 3 images 1 custom mime type
|
||||
|
||||
assert.Equal(firstPage, pageResources.GetByPrefix("1"))
|
||||
assert.Equal(secondPage, pageResources.GetByPrefix("2"))
|
||||
assert.Nil(pageResources.GetByPrefix("doesnotexist"))
|
||||
|
||||
imageResources := leafBundle1.Resources.ByType("image")
|
||||
assert.Len(imageResources, 3)
|
||||
image := imageResources[0]
|
||||
|
|
|
@ -72,8 +72,15 @@ func (r Resources) ByType(tp string) Resources {
|
|||
func (r Resources) GetByPrefix(prefix string) Resource {
|
||||
prefix = strings.ToLower(prefix)
|
||||
for _, resource := range r {
|
||||
_, name := filepath.Split(resource.RelPermalink())
|
||||
var name string
|
||||
f, ok := resource.(source.File)
|
||||
if ok {
|
||||
name = f.BaseFileName()
|
||||
} else {
|
||||
_, name = filepath.Split(resource.RelPermalink())
|
||||
}
|
||||
name = strings.ToLower(name)
|
||||
|
||||
if strings.HasPrefix(name, prefix) {
|
||||
return resource
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue