diff --git a/bic b/bic index 66a8d0f..cb60769 100755 --- a/bic +++ b/bic @@ -173,7 +173,8 @@ build_posts() { date="$(mk_date "${_post}")" slug="$(mk_slug "${filename_sans_id%.md}")" id="$(mk_id "${filename}" "${filename_sans_id}")" - export title body date slug id post tags + [[ -n "${tags[*]}" ]] && has_tags=true + export title body date slug id post tags has_tags mo \ "${SRC_DIR}"/entry.html \ > "${DEST_DIR}/${slug}.html" diff --git a/docs/index.md b/docs/index.md index 2bcf2b4..9124003 100644 --- a/docs/index.md +++ b/docs/index.md @@ -135,8 +135,10 @@ Some specific keys used within entries (posts or drafts) and pages: - `slug`, to be used in URL (does _not_ contain the `.html` file extension) - `title`, taken from first line of file `# ...` - `date`, literally the `mtime` of the file -- `id`, the number prefix for an entry encoded with [Hashids] +- `id`, the number prefix for an _entry_ encoded with [Hashids] - `body`, converted Markdown to HTML contents (sans title) +- `tags`, list of all tags for the _entry_ +- `has_tags`, if the _entry_ has tags (useful for conditional templating) Drafts will have a `draft` key set. Likewise, posts will have a `post` key set. diff --git a/tests/tags/entry.html b/tests/tags/entry.html index bb3ef8a..b900905 100644 --- a/tests/tags/entry.html +++ b/tests/tags/entry.html @@ -9,3 +9,5 @@ {{#ALL_TAGS}} - {{@key}} {{.}} {{/ALL_TAGS}} + +{{#has_tags}}has_tags defined{{/has_tags}} diff --git a/tests/test.bats b/tests/test.bats index da44731..537ca5b 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -158,6 +158,8 @@ run cat tests/tags/build/sitemap.xml [[ "${output}" == *"tags"* ]] [[ "${output}" == *"tags/one"* ]] + run cat tests/tags/build/test.html + [[ "${output}" == *"has_tags defined"* ]] rm -rf tests/tags/build [[ ! -d tests/tags/build ]] }