Path
A path field holds the url segment of an entry, its slug. It fills itself with a slug of the title while it's empty, and editors can change it. Config.document adds one for you; add it yourself to types made with Config.type that need a url.
import {Config, Field} from 'alinea'
export const Author = Config.type('Author', {
fields: {
title: Field.text('Name', {required: true, width: 0.5}),
path: Field.path('Path', {required: true, width: 0.5})
}
})The path of an entry is stored in the field named path: Alinea reads it to name the entry's file and build its url.
Options
from: the name of the text field, next to the path field, whose slug is suggested while the path is empty. Defaults to'title'.The common options
help,width,inline,initialValue,required,validate,readOnlyandhidden.sharedis not supported: every translation has its own path, so urls can be translated.
How entry paths are generated
When an entry is created, the slug of its title is saved as its path.
After that the path no longer follows the title, so fixing a typo in a title doesn't change a published url. Editors change the path by hand when they want a new url.
Slugs are lowercase. Accents are removed from Latin letters, letters and digits of other scripts are kept, apostrophes are dropped and everything else becomes a dash:
"L'été à Paris!"becomeslete-a-paris.Paths are unique among siblings. When a sibling already uses a path, a number is added:
about,about-1,about-2.
When the path of a published entry changes, its file and the folder with its children are renamed and its url changes, for its children too. Documents keep the old url in their metadata aliases so you can redirect it.
Slugs for other fields
A path field also works as a slug input elsewhere, for example an anchor for a section in a list. Point from at the field to suggest a slug from:
import {Config, Field} from 'alinea'
export const Section = Config.type('Section', {
fields: {
heading: Field.text('Heading', {width: 0.5}),
anchor: Field.path('Anchor', {from: 'heading', width: 0.5})
}
})The suggestion is only displayed: such a field stays empty until an editor types in it, so fall back to the heading when you render it.
A fixed path for the home page
A path of index is left out of the url, so an index entry at the top of a root is served on /. Seed the home page from the root's children with the key index, and make its path read-only so editors can't move it:
import {Config, Field} from 'alinea'
export const Home = Config.document('Home', {
fields: {
path: Field.path('Path', {readOnly: true, width: 0.5})
}
})
export const pages = Config.root('Pages', {
contains: ['Page'],
children: {
index: Config.page({type: Home, fields: {title: 'Home'}})
}
})Seeded entries are created automatically and can't be moved or deleted in the dashboard.
Entries created in the dashboard always start with the slug of their title as path, an initialValue on the path field isn't used for them.