Allow artworks to have one primary category and extra secondaries.
Keep artwork_category as membership, store a deterministic primary_category_id, and let upload plus studio pick up to five additional same-type categories without changing canonical URLs.
This commit is contained in:
@@ -103,6 +103,33 @@ export function buildCategoryTree(contentTypes = []) {
|
||||
return Array.from(rootsById.values())
|
||||
}
|
||||
|
||||
export function compareCategoryNames(a, b) {
|
||||
return String(a?.name || '').localeCompare(String(b?.name || ''), undefined, {
|
||||
numeric: true,
|
||||
sensitivity: 'base',
|
||||
})
|
||||
}
|
||||
|
||||
export function additionalCategoryOptions(roots = [], primaryId = '') {
|
||||
const options = []
|
||||
const seen = new Set()
|
||||
const primary = String(primaryId || '')
|
||||
|
||||
roots.forEach((root) => {
|
||||
const items = [root, ...(Array.isArray(root.children) ? root.children : [])]
|
||||
items.forEach((item) => {
|
||||
const id = String(item?.id || '')
|
||||
if (!id || id === primary || seen.has(id)) {
|
||||
return
|
||||
}
|
||||
seen.add(id)
|
||||
options.push({ id, name: item.name || `Category ${id}` })
|
||||
})
|
||||
})
|
||||
|
||||
return options.sort(compareCategoryNames)
|
||||
}
|
||||
|
||||
// ─── Content type helpers ─────────────────────────────────────────────────────
|
||||
export function getContentTypeValue(type) {
|
||||
if (!type) return ''
|
||||
|
||||
Reference in New Issue
Block a user