WeightedPages vs. Pages slice

I’m working on a shortcode that accepts either a tag or a type to list site content. The problem is the data by tag returns a WeightedPage slice while the pages by type returns a slice of Pages so I can’t easily write one template for both use cases. Querying based on these inputs seems to give different results:

Shortcode usage in Markdown

{{< infinite-list tag="florida" >}}
{{< infinite-list type="feature" >}}

Shortcode implementation

{{ $tag := lower (.Get "tag") | urlize }}
{{ $type := .Get "type" }}
{{ $pages := (or (where (index .Site.Taxonomies.tags $tag) "Page.Section" $section) (where .Site.Pages "Type" $type )) }}

// See what's in here:
{{ $pages }}

// where .Site.Pages "Type" $type yeilds:
// -> Pages(10)

// where (index .Site.Taxonomies.tags $tag yeilds: 
// -> [WeightedPage(0,"Employee spotlight: Dr. Wylie Carr, external affairs") WeightedPage(0,"Enhancing the climate resilience of America’s natural resources") WeightedPage(0,"Family adventure day in Louisiana") WeightedPage(0,"Friends of Wolf Creek National Fish Hatchery prepare fishing events") WeightedPage(0,"Kentucky annual meeting includes dam breach visit") WeightedPage(0,"Mississippi field office welcomes three new hires") WeightedPage(0,"Students help restore Everglades") WeightedPage(0,"Volunteer builds outdoor kiosk for Sam D. Hamilton Noxubee Refuge") WeightedPage(0,"Volunteers spruce up Natchitoches National Fish Hatchery") WeightedPage(0,"Whooping crane reintroduction continues in Louisiana") WeightedPage(0,"Wolf Creek volunteers make lasting improvements") WeightedPage(0,"Support and cooperation cure the New World screwworm infestation in the Keys") WeightedPage(0,"Strategic conservation assessment will help guide gulf conservation") WeightedPage(0,"Oyster reef project designed to aid pelican island")]

Is there an easy way to account for this so I don’t have to write two separate templates or two different shortcodes?

Currently no, but … I’m not sure why the Page isn’t embedded in WeighedPage so the two slices would be interchangeable. @spf13? I guess we could fix the now without breaking stuff.

1 Like