verless / verless

A Static Site Generator designed for Markdown-based content with a focus on simplicity and performance.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tags plugin: Initialize routes of list pages

dominikbraun opened this issue · comments

The tags plugin maintains a map of tags (keys) and a list page (values) that contains pages with that tag. If the tag doesn't exist in the map yet, a new list page is generated (see line 37):

https://github.com/verless/verless/blob/master/plugin/tags/tags.go#L32-L43

This is okay so far, but the list page doesn't receive a Route:

// createListPage initializes a new list page for a given key.
func (t *tags) createListPage(key string) {
t.m[key] = &model.ListPage{
Pages: make([]*model.Page, 0),
}
}

List pages with an empty route cause weird behavior. In order to fix this issue, the list page needs their Route field set. This should be something like Route: tagsDir + "/" + key or so.

Can you help me understand this issue ? As I recall ListPage extends Page model.

So where should I add Route: tagsDir + "/" + key ?

So ListPage represents a special Page that does not only contain typical page information like a route or title, but also a list of Pages. verless creates a list page for each directory inside content and references all pages inside that directory. Therefore, it is an overview for all pages inside a route.

That Route: tagsDir + "/" + key part should go into the ListPage initialization - something like that:

t.m[key] = &model.ListPage{
 	Route: tagsDir + "/" + key,
 	Pages: make([]*model.Page, 0), 
 } 

@dominikbraun can you check PR if it is right solution or not ? I don't know how to test if this is right or not.

Fixed with #188.