33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import type { AuthorPresentationDraft } from './articlePublisher'
|
|
|
|
const CONTENT_SEPARATOR = '\n\n---\n\nDescription du contenu :\n'
|
|
const MAINNET_ADDRESS_LABEL = 'Adresse Bitcoin mainnet (pour le sponsoring)'
|
|
|
|
export function extractAuthorNameFromTitle(title: string): string {
|
|
const result = title.replace(/^Présentation de /, '').trim()
|
|
return result.length > 0 ? result : 'Auteur'
|
|
}
|
|
|
|
export function parseAuthorPresentationDraft(draft: AuthorPresentationDraft): {
|
|
presentation: string
|
|
contentDescription: string
|
|
} {
|
|
const separatorIndex = draft.content.indexOf(CONTENT_SEPARATOR)
|
|
const presentation = separatorIndex !== -1 ? draft.content.substring(0, separatorIndex) : draft.presentation
|
|
const rawContentDescription =
|
|
separatorIndex !== -1 ? draft.content.substring(separatorIndex + CONTENT_SEPARATOR.length) : draft.contentDescription
|
|
|
|
return {
|
|
presentation,
|
|
contentDescription: stripMainnetAddressLine(rawContentDescription),
|
|
}
|
|
}
|
|
|
|
function stripMainnetAddressLine(value: string): string {
|
|
return value
|
|
.split('\n')
|
|
.filter((line) => !line.includes(MAINNET_ADDRESS_LABEL))
|
|
.join('\n')
|
|
.trim()
|
|
}
|