diff --git a/README.md b/README.md index f1b989b..f992650 100644 --- a/README.md +++ b/README.md @@ -62,17 +62,17 @@ In addition to the limitations listed below, this software isn't robust. Jekyll, ### Current Limitations Missing features: + - Themes - Excerpts - Pagination - Math - CSV and JSON data files - Plugins. (Some plugins are emulated. See the [plugin board](https://github.com/osteele/gojekyll/projects/2) for their status.) -- `site-static_files`, `site.html_files`, and `site.tags` -- These Liquid filters: `group_by_exp`, `cgi_escape`, `uri_escape`, `scssify`, and `smartify` +- Template filters `group_by_exp`, `cgi_escape`, `uri_escape`, and `scssify` - More Liquid tags and filters, listed [here](https://github.com/osteele/liquid#differences-from-liquid). -- Windows compatibility - Markdown features: [attribute lists](https://kramdown.gettalong.org/syntax.html#attribute-list-definitions), [automatic ids](https://kramdown.gettalong.org/converter/html.html#auto-ids), [`markdown=1`](https://kramdown.gettalong.org/syntax.html#html-blocks). +- Windows compatibility Also see the [detailed status](#feature-status) below. diff --git a/site/drop.go b/site/drop.go index 962e253..d0b5734 100644 --- a/site/drop.go +++ b/site/drop.go @@ -10,8 +10,8 @@ import ( // ToLiquid returns the site variable for template evaluation. func (s *Site) ToLiquid() interface{} { - // double-checked lock is okay here, since it's okay if this gets - // written twice + // double-checked lock is okay here, since it's okay if this is + // computed and set twice if len(s.drop) == 0 { s.Lock() defer s.Unlock() @@ -32,12 +32,12 @@ func (s *Site) initializeDrop() { vars := templates.MergeVariableMaps(s.config.Variables, map[string]interface{}{ "data": s.data, "documents": s.docs, + "html_files": s.htmlFiles(), "html_pages": s.htmlPages(), "pages": s.Pages(), - "static_files": s.StaticFiles(), + "static_files": s.staticFiles(), // TODO read time from _config, if it's available "time": time.Now(), - // TODO static_files, html_files, tags.TAG }) collections := []interface{}{} for _, c := range s.Collections { @@ -59,6 +59,20 @@ func (s *Site) setPageContent() error { return nil } +// The following functions are only used in the drop, therefore they're +// non-public and they're listed here. +// +// Since the drop is cached, there's no effort to cache these too. + +func (s *Site) htmlFiles() (out []*pages.StaticFile) { + for _, p := range s.staticFiles() { + if p.OutputExt() == ".html" { + out = append(out, p) + } + } + return +} + func (s *Site) htmlPages() (out []pages.Page) { for _, p := range s.Pages() { if p.OutputExt() == ".html" { @@ -67,3 +81,12 @@ func (s *Site) htmlPages() (out []pages.Page) { } return } + +func (s *Site) staticFiles() (out []*pages.StaticFile) { + for _, d := range s.docs { + if sd, ok := d.(*pages.StaticFile); ok { + out = append(out, sd) + } + } + return +} diff --git a/site/posts.go b/site/posts.go index caf1682..9ed6722 100644 --- a/site/posts.go +++ b/site/posts.go @@ -20,15 +20,20 @@ func (s *Site) setPostVariables() { return } var ( - ps = c.Pages() - related = ps - categories = map[string][]pages.Page{} - tags = map[string][]pages.Page{} + ps = c.Pages() + related = ps ) if len(related) > 10 { related = related[:10] } - for _, p := range ps { + s.drop["categories"] = s.groupPagesBy(func(p pages.Page) []string { return p.Categories() }) + s.drop["tags"] = s.groupPagesBy(func(p pages.Page) []string { return p.Tags() }) + s.drop["related_posts"] = related +} + +func (s *Site) groupPagesBy(getter func(pages.Page) []string) map[string][]pages.Page { + categories := map[string][]pages.Page{} + for _, p := range s.Pages() { for _, k := range p.Categories() { ps, found := categories[k] if !found { @@ -37,7 +42,5 @@ func (s *Site) setPostVariables() { categories[k] = append(ps, p) } } - s.drop["categories"] = categories - s.drop["tags"] = tags - s.drop["related_posts"] = related + return categories } diff --git a/site/site.go b/site/site.go index e9b9510..d36bd8a 100644 --- a/site/site.go +++ b/site/site.go @@ -50,16 +50,6 @@ func (s *Site) OutputPages() []pages.Document { return out } -// StaticFiles returns a list of static files. -func (s *Site) StaticFiles() (out []*pages.StaticFile) { - for _, d := range s.docs { - if sd, ok := d.(*pages.StaticFile); ok { - out = append(out, sd) - } - } - return -} - // Pages returns all the pages, output or not. func (s *Site) Pages() (out []pages.Page) { for _, d := range s.docs {