From 5ae60424033cd3de79dd70d535eee0f6d6765b97 Mon Sep 17 00:00:00 2001 From: Mikal S <7761729+revam@users.noreply.github.com> Date: Fri, 3 Nov 2023 08:40:22 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20fix=20anidb=20description=E2=80=A6=20aga?= =?UTF-8?q?in=20(#666)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: fix anidb description… again - add missing link templates to regex, since we only accounted for short links, but people also insert long links, - merge multi spaces into single space, - remove summary credits, and - account for people's disability to spell correctly. * fix: fix tag descriptions --- src/components/Collection/AnidbDescription.tsx | 17 +++++++++++++---- src/pages/collection/series/SeriesTags.tsx | 5 ++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/Collection/AnidbDescription.tsx b/src/components/Collection/AnidbDescription.tsx index 50677183f..3dddc2fa1 100644 --- a/src/components/Collection/AnidbDescription.tsx +++ b/src/components/Collection/AnidbDescription.tsx @@ -1,16 +1,25 @@ import React, { useMemo } from 'react'; -const RemoveSummaryRegex = /^\n(Source|Note|Summary):.*/mg; +// The question marks are there because people can't spell… +const RemoveSummaryRegex = /\b(Sour?ce|Note|Summ?ary):([^\r\n]+|$)/mg; + +const MultiSpacesRegex = /\s{2,}/g; + const CleanMiscLinesRegex = /^(\*|--|~) /sg; + const CleanMultiEmptyLinesRegex = /\n{2,}/sg; -const LinkRegex = /(?http:\/\/anidb\.net\/(?ch|cr|[feat])(?\d+)) \[(?[^\]]+)]/g; + +// eslint-disable-next-line operator-linebreak -- Because dprint and eslint can't agree otherwise. Feel free to fix it. +const LinkRegex = + /(?http:\/\/anidb\.net\/(?ch|cr|[feat]|(?:character|creator|file|episode|anime|tag)\/)(?\d+)) \[(?[^\]]+)]/g; const AnidbDescription = ({ text }: { text: string }) => { const modifiedText = useMemo(() => { const cleanedText = text .replaceAll(CleanMiscLinesRegex, '') .replaceAll(RemoveSummaryRegex, '') - .replaceAll(CleanMultiEmptyLinesRegex, '\n'); + .replaceAll(CleanMultiEmptyLinesRegex, '\n') + .replaceAll(MultiSpacesRegex, ' '); const lines = [] as React.ReactNode[]; let prevPos = 0; @@ -21,7 +30,7 @@ const AnidbDescription = ({ text }: { text: string }) => { lines.push(cleanedText.substring(prevPos, pos)); prevPos = pos + link[0].length; lines.push( - link[4], + link.groups!.text, ); link = LinkRegex.exec(cleanedText); } diff --git a/src/pages/collection/series/SeriesTags.tsx b/src/pages/collection/series/SeriesTags.tsx index 5c74e59b4..2b5a5c361 100644 --- a/src/pages/collection/series/SeriesTags.tsx +++ b/src/pages/collection/series/SeriesTags.tsx @@ -5,6 +5,7 @@ import { Icon } from '@mdi/react'; import cx from 'classnames'; import { map } from 'lodash'; +import AnidbDescription from '@/components/Collection/AnidbDescription'; import Input from '@/components/Input/Input'; import ShokoPanel from '@/components/Panels/ShokoPanel'; import { useGetSeriesTagsQuery } from '@/core/rtkQuery/splitV3Api/seriesApi'; @@ -27,7 +28,9 @@ function SeriesTag(props: { item: TagType }) {   -
{item.Description}
+
+ +
); }