feat(posts): support short titles for resource cards
Add optional post-level and localized title fields, and use a new postTitleText helper for Resource.title so card/list surfaces prefer short backend-provided titles instead of full body text. When title is missing, fallback to the first non-empty body line, then filename, then post id. Document the backend handoff in docs/posts-title-api.md alongside the other backend task docs.
This commit is contained in:
@@ -11,3 +11,19 @@ export function postDisplayText(post: Post, lang: string): string {
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
export function postTitleText(post: Post, lang: string): string {
|
||||
const key = localizationKey(lang);
|
||||
const localized =
|
||||
post.localizations?.[key as keyof typeof post.localizations];
|
||||
const explicitTitle = localized?.title?.trim() || post.title?.trim();
|
||||
if (explicitTitle) return explicitTitle;
|
||||
|
||||
const text = postDisplayText(post, lang);
|
||||
return (
|
||||
text
|
||||
.split(/\n{1,}/)
|
||||
.map((line) => line.trim())
|
||||
.find(Boolean) || ""
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user