Page scan
Scan a directory and return page metadata as a TT array variable.
Page scan
The scan: prefix in tt_page_var scans a directory for .md files
and returns an array of page objects. Use it to build indexes, listings,
and navigation from page metadata.
Syntax
---
tt_page_var:
pages: scan:/blog/*.md sort=date desc
---
Pattern rules
- Must start with
/(docroot-relative) - Must end with
.md - Standard shell glob patterns work (
*.md,post-*.md) - Use
**for recursive scanning across all subdirectories:scan:/**/*.mdscans the entire docroot - At most 200 files are read per scan, the first 200 in file-name order
(then sorted), so the same pages are listed on every render. Set
scan_limit:inlazysite.confto change it. A capped scan logs a warning. NAME_totalbeside the list counts the pages the pattern matched that the reader may see, beforefilter=and before the cap, so a page can sayshowing [% posts.size %] of [% posts_total %]limit=Nandoffset=Npage the list afterfilter=andsort=:scan:/blog/*.md sort=date desc offset=10 limit=10is the second ten.limit=is capped byscan_limit, andoffset=reaches no further than the pages the scan read, so raisescan_limitto page a longer list.NAME_totalis not changed by them. A value that is not a whole number is ignored and logged.- Files outside the docroot are excluded (realpath check)
Page object fields
Each scanned page returns these fields:
url- docroot-relative URL (.mdstripped,/indexnormalised to/)title- from front mattertitle:or empty stringsubtitle- from front mattersubtitle:or empty stringdate- from front matterdate:or file mtime (YYYY-MM-DD format)tags- array of tags from front matter (YAML list, comma-separated, or single value)excerpt- first 500 characters of the raw page body (after front matter), used for search snippetssearchable- 1 or 0, from front mattersearch:or the site-widesearch_defaultsettingpath- full filesystem path to the.mdfile
Sort modifier
Append sort=FIELD DIRECTION to the pattern:
scan:/blog/*.md sort=date desc
scan:/docs/*.md sort=title asc
scan:/pages/*.md sort=filename asc
Supported fields: date, title, filename. Default: filename asc.
Direction is optional and defaults to asc.
Paging modifiers
Append limit=N and offset=N to list part of the sorted result:
scan:/blog/*.md sort=date desc limit=10
scan:/blog/*.md sort=date desc offset=10 limit=10
They apply after filter= and sort=. limit= is capped by the site's
scan_limit; offset= counts into the pages the scan read.
Example
---
title: Blog
tt_page_var:
posts: scan:/blog/*.md sort=date desc
---
[% FOREACH post IN posts %]
### [% post.title %]
*[% post.date %]* - [% post.subtitle %]
[Read more]([% post.url %])
[% END %]
Notes
- Scans can also be defined in
lazysite.conffor site-wide variables - Tags are parsed from YAML list format, comma-separated strings, or
single values into an array:
[% page.tags.join(', ') %] - The scan is performed at render time - results reflect the current state of the filesystem
- Filtered scan - filter results by field value
- Search - build a search index from scan results
- TT variables - all variable sources and types