A slug is a URL portion that identifies a page with human-readable keywords.
https://bobscoolblog.com/posts/happy-new-year.html
Happy New Year!
Incidentally, this page’s slug is happy-new-year. If you share this URL with someone, they’ll have some idea what the page is about. (It also helps you remember what you wrote!) The words in the URL are also given some weight by search engines.
The term comes from newspapers and typesetting.
Some people like to write a slug by hand in the front matter at the top of a file.
post1.md
---
title: Happy New Year!
slug: happy-new-year
---
Incidentally, this page's slug is **happy-new-year**. If you share this URL with someone, they'll have some idea what the page is about. (It also helps _you_ remember what you wrote!) The words in the URL are also given some weight by search engines.
Slugs are generally lowercase with hyphens.
An Origami map can change the keys of a set of files from file names to the slugs.
site.ori
{
posts/ = Tree.map(markdown/, {
key: (post) => `${ post.slug }.html`
})
}
http://localhost:5000/posts
Index
Don’t want to write slugs by hand? Turn titles into slugs with the slug function!
post1.md
---
title: Happy New Year!
---
Incidentally, this page's slug is **happy-new-year**. If you share this URL with someone, they'll have some idea what the page is about. (It also helps _you_ remember what you wrote!) The words in the URL are also given some weight by search engines.
site.ori
{
posts/ = Tree.map(markdown/, {
key: (post) => `${ Origami.slug(post.title) }.html`
})
}
Same result, less typing per post.
Read more: Origami.slug() function