Derive Date And Permalink From Filename
2026-02-25 ยท by Tola
path: showcase/2026_02_25_meta-from-filename.typ
filename: 2026_02_25_meta-from-filename.typ
permalink: /showcase/meta-from-filename/
parsed.date: 2026-02-25
parsed.slug: meta-from-filename
m.date: 2026-02-25
m.permalink: /showcase/meta-from-filename/
Introduction
This post demonstrates the path and filename fields in @tola/current.
For 2026_02_25_meta-from-filename.typ, the template infers:
datefrom theYYYY_MM_DDprefixpermalinkfrom directory + slug (remaining filename parts)
How It Works
path provides the source file path relative to the content directory, and filename provides the last segment:
#import "@tola/current:0.0.0": path, filename
// path = "showcase/2026_02_25_meta-from-filename.typ"
// filename = "2026_02_25_meta-from-filename.typ"You can parse the filename to extract the date:
#let parts = filename.split("_")
#let date = datetime(
year: int(parts.at(0)),
month: int(parts.at(1)),
day: int(parts.at(2)),
)And derive the permalink from path + parsed slug:
// skip YYYY_MM_DD, keep slug part
#let slug = parts.slice(3).join("-")
// remove filename, keep directory
#let dir = path.split("/").slice(0, -1).join("/")
// permalink: "/slug/" or "/dir/slug/"
#let permalink = if dir == "" {
"/" + slug + "/"
} else {
"/" + dir + "/" + slug + "/"
}Benefits
- File names can include dates for chronological sorting in file managers
- URLs remain clean without date prefixes (auto-derived from slug)
dateandpermalinkstay derived from one source (no duplication)