Post now use displayable_description
This commit is contained in:
parent
22f7c39dff
commit
d5e7d704bf
|
@ -107,12 +107,8 @@ export const SearchPopup = (): JSX.Element => {
|
||||||
q,
|
q,
|
||||||
limit: SEARCH_LIMIT,
|
limit: SEARCH_LIMIT,
|
||||||
attributesToRetrieve: ["translations", "thumbnail", "slug", "date", "categories"],
|
attributesToRetrieve: ["translations", "thumbnail", "slug", "date", "categories"],
|
||||||
attributesToHighlight: [
|
attributesToHighlight: ["translations.title", "translations.displayable_description"],
|
||||||
"translations.title",
|
attributesToCrop: ["translations.displayable_description"],
|
||||||
"translations.excerpt",
|
|
||||||
"translations.body",
|
|
||||||
],
|
|
||||||
attributesToCrop: ["translations.body"],
|
|
||||||
filter: ["hidden = false"],
|
filter: ["hidden = false"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -376,12 +372,10 @@ export const SearchPopup = (): JSX.Element => {
|
||||||
onClick={() => setSearchOpened(false)}
|
onClick={() => setSearchOpened(false)}
|
||||||
translations={filterHasAttributes(item._formatted.translations, [
|
translations={filterHasAttributes(item._formatted.translations, [
|
||||||
"language.data.attributes.code",
|
"language.data.attributes.code",
|
||||||
]).map(({ excerpt, body, language, ...otherAttributes }) => ({
|
]).map(({ excerpt, displayable_description, language, ...otherAttributes }) => ({
|
||||||
...otherAttributes,
|
...otherAttributes,
|
||||||
description: containsHighlight(excerpt)
|
description: containsHighlight(displayable_description)
|
||||||
? excerpt
|
? displayable_description
|
||||||
: containsHighlight(body)
|
|
||||||
? body
|
|
||||||
: excerpt,
|
: excerpt,
|
||||||
language: language.data.attributes.code,
|
language: language.data.attributes.code,
|
||||||
}))}
|
}))}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import { convert } from "html-to-text";
|
import { prettyMarkdown } from "helpers/formatters";
|
||||||
import { sanitize } from "isomorphic-dompurify";
|
import { filterDefined, isDefined, isDefinedAndNotEmpty } from "helpers/asserts";
|
||||||
import { marked } from "marked";
|
|
||||||
import { filterDefined, isDefined, isDefinedAndNotEmpty } from "./asserts";
|
|
||||||
|
|
||||||
export const getDescription = (
|
export const getDescription = (
|
||||||
description: string | null | undefined,
|
description: string | null | undefined,
|
||||||
|
@ -28,43 +26,6 @@ export const getDescription = (
|
||||||
return result;
|
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 =>
|
const prettyChip = (items: (string | undefined)[]): string =>
|
||||||
items
|
items
|
||||||
.filter((item) => isDefined(item))
|
.filter((item) => isDefined(item))
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { convert } from "html-to-text";
|
||||||
|
import { sanitize } from "isomorphic-dompurify";
|
||||||
|
import { marked } from "marked";
|
||||||
import { convertPrice } from "./numbers";
|
import { convertPrice } from "./numbers";
|
||||||
import { isDefinedAndNotEmpty, isUndefined } from "./asserts";
|
import { isDefinedAndNotEmpty, isUndefined } from "./asserts";
|
||||||
import { datePickerToDate } from "./date";
|
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 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();
|
||||||
|
};
|
||||||
|
|
|
@ -79,8 +79,8 @@ const News = ({ ...otherProps }: Props): JSX.Element => {
|
||||||
hitsPerPage: 25,
|
hitsPerPage: 25,
|
||||||
page,
|
page,
|
||||||
attributesToRetrieve: ["translations", "thumbnail", "slug", "date", "categories"],
|
attributesToRetrieve: ["translations", "thumbnail", "slug", "date", "categories"],
|
||||||
attributesToHighlight: ["translations.title", "translations.excerpt", "translations.body"],
|
attributesToHighlight: ["translations.title", "translations.displayable_description"],
|
||||||
attributesToCrop: ["translations.body"],
|
attributesToCrop: ["translations.displayable_description"],
|
||||||
sort: ["sortable_date:desc"],
|
sort: ["sortable_date:desc"],
|
||||||
filter: ["hidden = false"],
|
filter: ["hidden = false"],
|
||||||
});
|
});
|
||||||
|
@ -168,12 +168,10 @@ const News = ({ ...otherProps }: Props): JSX.Element => {
|
||||||
href={`/news/${item.slug}`}
|
href={`/news/${item.slug}`}
|
||||||
translations={filterHasAttributes(item._formatted.translations, [
|
translations={filterHasAttributes(item._formatted.translations, [
|
||||||
"language.data.attributes.code",
|
"language.data.attributes.code",
|
||||||
]).map(({ excerpt, body, language, ...otherAttributes }) => ({
|
]).map(({ excerpt, displayable_description, language, ...otherAttributes }) => ({
|
||||||
...otherAttributes,
|
...otherAttributes,
|
||||||
description: containsHighlight(excerpt)
|
description: containsHighlight(displayable_description)
|
||||||
? excerpt
|
? displayable_description
|
||||||
: containsHighlight(body)
|
|
||||||
? body
|
|
||||||
: excerpt,
|
: excerpt,
|
||||||
language: language.data.attributes.code,
|
language: language.data.attributes.code,
|
||||||
}))}
|
}))}
|
||||||
|
|
|
@ -18,6 +18,8 @@ export interface MeiliLibraryItem extends LibraryItemAttributesFragment {
|
||||||
sortable_name: string;
|
sortable_name: string;
|
||||||
sortable_price: number | undefined;
|
sortable_price: number | undefined;
|
||||||
sortable_date: number | undefined;
|
sortable_date: number | undefined;
|
||||||
|
groupable_year: number | undefined;
|
||||||
|
filterable_categories: string[];
|
||||||
untangible_group_item: boolean;
|
untangible_group_item: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +41,15 @@ export interface MeiliVideo extends VideoAttributesFragment {
|
||||||
channel_uid?: string;
|
channel_uid?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MeiliPost extends PostAttributesFragment {
|
export interface MeiliPost extends Omit<PostAttributesFragment, "translations"> {
|
||||||
id: string;
|
id: string;
|
||||||
sortable_date: number;
|
sortable_date: number;
|
||||||
|
translations: (Omit<
|
||||||
|
NonNullable<NonNullable<PostAttributesFragment["translations"]>[number]>,
|
||||||
|
"body"
|
||||||
|
> & {
|
||||||
|
displayable_description?: string | null;
|
||||||
|
})[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MeiliWikiPage extends Omit<WikiPageAttributesFragment, "translations"> {
|
export interface MeiliWikiPage extends Omit<WikiPageAttributesFragment, "translations"> {
|
||||||
|
|
Loading…
Reference in New Issue