diff --git a/src/components/Panels/SearchPopup.tsx b/src/components/Panels/SearchPopup.tsx index a991da5..01e37d0 100644 --- a/src/components/Panels/SearchPopup.tsx +++ b/src/components/Panels/SearchPopup.tsx @@ -107,12 +107,8 @@ export const SearchPopup = (): JSX.Element => { q, limit: SEARCH_LIMIT, attributesToRetrieve: ["translations", "thumbnail", "slug", "date", "categories"], - attributesToHighlight: [ - "translations.title", - "translations.excerpt", - "translations.body", - ], - attributesToCrop: ["translations.body"], + attributesToHighlight: ["translations.title", "translations.displayable_description"], + attributesToCrop: ["translations.displayable_description"], filter: ["hidden = false"], }, { @@ -376,12 +372,10 @@ export const SearchPopup = (): JSX.Element => { onClick={() => setSearchOpened(false)} translations={filterHasAttributes(item._formatted.translations, [ "language.data.attributes.code", - ]).map(({ excerpt, body, language, ...otherAttributes }) => ({ + ]).map(({ excerpt, displayable_description, language, ...otherAttributes }) => ({ ...otherAttributes, - description: containsHighlight(excerpt) - ? excerpt - : containsHighlight(body) - ? body + description: containsHighlight(displayable_description) + ? displayable_description : excerpt, language: language.data.attributes.code, }))} diff --git a/src/helpers/description.ts b/src/helpers/description.ts index 5607dfd..f50887d 100644 --- a/src/helpers/description.ts +++ b/src/helpers/description.ts @@ -1,7 +1,5 @@ -import { convert } from "html-to-text"; -import { sanitize } from "isomorphic-dompurify"; -import { marked } from "marked"; -import { filterDefined, isDefined, isDefinedAndNotEmpty } from "./asserts"; +import { prettyMarkdown } from "helpers/formatters"; +import { filterDefined, isDefined, isDefinedAndNotEmpty } from "helpers/asserts"; export const getDescription = ( description: string | null | undefined, @@ -28,43 +26,6 @@ export const getDescription = ( return result; }; -const block = (text: string) => `${text}\n\n`; -const escapeBlock = (text: string) => `${escape(text)}\n\n`; -const line = (text: string) => `${text}\n`; -const inline = (text: string) => text; -const newline = () => "\n"; -const empty = () => ""; - -const TxtRenderer: marked.Renderer = { - // Block elements - code: escapeBlock, - blockquote: block, - html: empty, - heading: block, - hr: newline, - list: (text) => block(text.trim()), - listitem: line, - checkbox: empty, - paragraph: block, - table: (header, body) => line(header + body), - tablerow: (text) => line(text.trim()), - tablecell: (text) => `${text} `, - // Inline elements - strong: inline, - em: inline, - codespan: inline, - br: newline, - del: inline, - link: (_0, _1, text) => text, - image: (_0, _1, text) => text, - text: inline, - // etc. - options: {}, -}; - -const prettyMarkdown = (markdown: string): string => - convert(sanitize(marked(markdown, { renderer: TxtRenderer }))).trim(); - const prettyChip = (items: (string | undefined)[]): string => items .filter((item) => isDefined(item)) diff --git a/src/helpers/formatters.ts b/src/helpers/formatters.ts index 4b253fe..7e60b12 100644 --- a/src/helpers/formatters.ts +++ b/src/helpers/formatters.ts @@ -1,3 +1,6 @@ +import { convert } from "html-to-text"; +import { sanitize } from "isomorphic-dompurify"; +import { marked } from "marked"; import { convertPrice } from "./numbers"; import { isDefinedAndNotEmpty, isUndefined } from "./asserts"; import { datePickerToDate } from "./date"; @@ -261,3 +264,41 @@ export const slugify = (string: string | undefined): string => { }; export const sJoin = (...args: (string | null | undefined)[]): string => args.join(""); + +export const prettyMarkdown = (markdown: string): string => { + const block = (text: string) => `${text}\n\n`; + const escapeBlock = (text: string) => `${escape(text)}\n\n`; + const line = (text: string) => `${text}\n`; + const inline = (text: string) => text; + const newline = () => "\n"; + const empty = () => ""; + + const TxtRenderer: marked.Renderer = { + // Block elements + code: escapeBlock, + blockquote: block, + html: empty, + heading: block, + hr: newline, + list: (text) => block(text.trim()), + listitem: line, + checkbox: empty, + paragraph: block, + table: (header, body) => line(header + body), + tablerow: (text) => line(text.trim()), + tablecell: (text) => `${text} `, + // Inline elements + strong: inline, + em: inline, + codespan: inline, + br: newline, + del: inline, + link: (_0, _1, text) => text, + image: (_0, _1, text) => text, + text: inline, + // etc. + options: {}, + }; + + return convert(sanitize(marked(markdown, { renderer: TxtRenderer }))).trim(); +}; diff --git a/src/pages/news/index.tsx b/src/pages/news/index.tsx index 3faba66..7d5133f 100644 --- a/src/pages/news/index.tsx +++ b/src/pages/news/index.tsx @@ -79,8 +79,8 @@ const News = ({ ...otherProps }: Props): JSX.Element => { hitsPerPage: 25, page, attributesToRetrieve: ["translations", "thumbnail", "slug", "date", "categories"], - attributesToHighlight: ["translations.title", "translations.excerpt", "translations.body"], - attributesToCrop: ["translations.body"], + attributesToHighlight: ["translations.title", "translations.displayable_description"], + attributesToCrop: ["translations.displayable_description"], sort: ["sortable_date:desc"], filter: ["hidden = false"], }); @@ -168,12 +168,10 @@ const News = ({ ...otherProps }: Props): JSX.Element => { href={`/news/${item.slug}`} translations={filterHasAttributes(item._formatted.translations, [ "language.data.attributes.code", - ]).map(({ excerpt, body, language, ...otherAttributes }) => ({ + ]).map(({ excerpt, displayable_description, language, ...otherAttributes }) => ({ ...otherAttributes, - description: containsHighlight(excerpt) - ? excerpt - : containsHighlight(body) - ? body + description: containsHighlight(displayable_description) + ? displayable_description : excerpt, language: language.data.attributes.code, }))} diff --git a/src/shared/meilisearch-graphql-typings/meiliTypes.ts b/src/shared/meilisearch-graphql-typings/meiliTypes.ts index d5989d1..b72e0af 100644 --- a/src/shared/meilisearch-graphql-typings/meiliTypes.ts +++ b/src/shared/meilisearch-graphql-typings/meiliTypes.ts @@ -18,6 +18,8 @@ export interface MeiliLibraryItem extends LibraryItemAttributesFragment { sortable_name: string; sortable_price: number | undefined; sortable_date: number | undefined; + groupable_year: number | undefined; + filterable_categories: string[]; untangible_group_item: boolean; } @@ -39,9 +41,15 @@ export interface MeiliVideo extends VideoAttributesFragment { channel_uid?: string; } -export interface MeiliPost extends PostAttributesFragment { +export interface MeiliPost extends Omit { id: string; sortable_date: number; + translations: (Omit< + NonNullable[number]>, + "body" + > & { + displayable_description?: string | null; + })[]; } export interface MeiliWikiPage extends Omit {