From 879902fd75cd690ad3cfcae33e471a1668959a51 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 28 Dec 2023 03:52:54 +0300 Subject: [PATCH] sort-fix --- src/components/Article/FullArticle.tsx | 2 +- src/components/Feed/ArticleCard/ArticleCard.tsx | 2 +- src/components/Views/AllAuthors.tsx | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index eb0eca28..7998265e 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -76,7 +76,7 @@ export const FullArticle = (props: Props) => { const main_topic_slug = props.article.topics.length > 0 ? props.article.main_topic : null const mt = props.article.topics.find((tpc: Topic) => tpc.slug === main_topic_slug) if (mt) { - mt.title = lang() === 'en' ? capitalize(mt.slug.replace('-', ' ')) : mt.title + mt.title = lang() === 'en' ? capitalize(mt.slug.replace(/-/, ' ')) : mt.title return mt } else { return props.article.topics[0] diff --git a/src/components/Feed/ArticleCard/ArticleCard.tsx b/src/components/Feed/ArticleCard/ArticleCard.tsx index 3d452ffa..29ee31dc 100644 --- a/src/components/Feed/ArticleCard/ArticleCard.tsx +++ b/src/components/Feed/ArticleCard/ArticleCard.tsx @@ -89,7 +89,7 @@ export const ArticleCard = (props: ArticleCardProps) => { const mainTopicSlug = props.article.main_topic || '' const mainTopic = props.article.topics?.find((tpc: Topic) => tpc.slug === mainTopicSlug) const mainTopicTitle = - mainTopicSlug && lang() === 'en' ? mainTopicSlug.replace('-', ' ') : mainTopic?.title || '' + mainTopicSlug && lang() === 'en' ? mainTopicSlug.replace(/-/, ' ') : mainTopic?.title || '' const formattedDate = createMemo(() => { let r = '' diff --git a/src/components/Views/AllAuthors.tsx b/src/components/Views/AllAuthors.tsx index e59e8360..b749372c 100644 --- a/src/components/Views/AllAuthors.tsx +++ b/src/components/Views/AllAuthors.tsx @@ -17,6 +17,7 @@ import { AuthorBadge } from '../Author/AuthorBadge' import styles from './AllAuthors.module.scss' import { isCyrillic } from '../../utils/cyrillic' import { capitalize } from '../../utils/capitalize' +import { translit } from '../../utils/ru2en' type AllAuthorsPageSearchParams = { by: '' | 'name' | 'shouts' | 'followers' @@ -78,7 +79,7 @@ export const AllAuthorsView = (props: Props) => { }[searchParams().by]() const translate = (author: Author) => lang() === 'en' && isCyrillic(author.name) - ? capitalize(author.slug.replace(/-/, ' '), true) + ? capitalize(translit(author.name.replace(/ё/, 'e').replace(/ь/, '')).replace(/-/, ' '), true) : author.name const byLetter = createMemo<{ [letter: string]: Author[] }>(() => { return sortedAuthors().reduce( @@ -86,6 +87,8 @@ export const AllAuthorsView = (props: Props) => { let letter = '' if (!letter && author && author.name) { const name = translate(author) + .replace(/[^A-zА-я0-9]/, ' ') + .trim() const nameParts = name.trim().split(' ') const found = nameParts.filter(Boolean).pop() if (found && found.length > 0) { @@ -96,8 +99,12 @@ export const AllAuthorsView = (props: Props) => { if (/[^A-z]/.test(letter) && lang() === 'en') letter = '@' if (!acc[letter]) acc[letter] = [] - + author.name = translate(author) acc[letter].push(author) + + // Sort authors within each letter group alphabetically by name + acc[letter].sort((a, b) => a.name.localeCompare(b.name)) + return acc }, {} as { [letter: string]: Author[] },