Skip to content

Commit

Permalink
feat: add has_tags for entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinjasaur committed Jul 14, 2024
1 parent 3f59212 commit fa60875
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bic
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions tests/tags/entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
{{#ALL_TAGS}}
- {{@key}} {{.}}
{{/ALL_TAGS}}

{{#has_tags}}has_tags defined{{/has_tags}}
2 changes: 2 additions & 0 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]]
}

0 comments on commit fa60875

Please sign in to comment.