Foundation + Schemas
This commit is contained in:
6
src/lib/content/assets.ts
Normal file
6
src/lib/content/assets.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export const ASSET_ROOT = 'src/assets/content'
|
||||
|
||||
export const assets = (collection: string) => ({
|
||||
directory: `${ASSET_ROOT}/${collection}`,
|
||||
publicPath: `/${ASSET_ROOT}/${collection}/`,
|
||||
})
|
||||
34
src/lib/content/slug.ts
Normal file
34
src/lib/content/slug.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
export const SEGMENT = /^[a-z0-9][a-z0-9_-]*$/
|
||||
export const OPTIONAL_SEGMENT = /^([a-z0-9][a-z0-9_-]*)?$/
|
||||
export const SEGMENT_MESSAGE = 'Lowercase letters, digits, - and _'
|
||||
|
||||
const UMLAUTS: Record<string, string> = {
|
||||
ä: 'ae',
|
||||
ö: 'oe',
|
||||
ü: 'ue',
|
||||
ß: 'ss',
|
||||
Ä: 'ae',
|
||||
Ö: 'oe',
|
||||
Ü: 'ue',
|
||||
å: 'aa',
|
||||
æ: 'ae',
|
||||
ø: 'oe',
|
||||
Å: 'aa',
|
||||
Æ: 'ae',
|
||||
Ø: 'oe',
|
||||
}
|
||||
|
||||
export const slugify = (text: string): string => {
|
||||
return text
|
||||
.split('')
|
||||
.map((char) => UMLAUTS[char] || char)
|
||||
.join('')
|
||||
.normalize('NFKD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9 _-]/g, '')
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/-+/g, '-')
|
||||
.replace(/^[-_]+|[-_]+$/g, '')
|
||||
}
|
||||
Reference in New Issue
Block a user