28 lines
882 B
TypeScript
28 lines
882 B
TypeScript
import { t } from '@/i18n'
|
|
import type { Byline } from '@/lib/articleTypes'
|
|
|
|
export function authorsSummary(authors: Byline[]) {
|
|
const [first] = authors
|
|
if (!first) {
|
|
return t('No authors')
|
|
}
|
|
return authors.length === 1 ? first.name : t('{0} +{1}', [first.name, authors.length - 1])
|
|
}
|
|
|
|
export function metaSummary(authors: Byline[], siteName: string | null) {
|
|
const summary = authorsSummary(authors)
|
|
return siteName ? t('{0} · {1}', [siteName, summary]) : summary
|
|
}
|
|
|
|
export function insertionTarget(from: number, gap: number) {
|
|
return gap > from ? gap - 1 : gap
|
|
}
|
|
|
|
export function sameIds(left: Byline[], right: Byline[]) {
|
|
return left.length === right.length && left.every((item, index) => item.id === right[index]?.id)
|
|
}
|
|
|
|
export function toBylines(authors: Byline[]): Byline[] {
|
|
return authors.map(({ id, name, slug, avatar_id }) => ({ id, name, slug, avatar_id }))
|
|
}
|