From 0cf71b4d954c987c6d4e8f475cea82dde1404dab Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:06:41 +0200 Subject: [PATCH] Added missing search preview types --- .../Previews/ChronologyEventPreview.astro | 48 +++ src/components/Previews/FolderPreview.astro | 56 ++++ src/components/Previews/GenericPreview.astro | 18 +- src/components/Previews/RecorderPreview.astro | 36 +++ src/i18n/wordings-keys.ts | 5 +- src/pages/[locale]/index.astro | 5 +- src/pages/[locale]/search/index.astro | 9 + src/shared/meilisearch/meilisearch-sdk.ts | 9 +- src/shared/openExchange/rates.json | 292 +++++++++--------- 9 files changed, 320 insertions(+), 158 deletions(-) create mode 100644 src/components/Previews/ChronologyEventPreview.astro create mode 100644 src/components/Previews/FolderPreview.astro create mode 100644 src/components/Previews/RecorderPreview.astro diff --git a/src/components/Previews/ChronologyEventPreview.astro b/src/components/Previews/ChronologyEventPreview.astro new file mode 100644 index 0000000..b578938 --- /dev/null +++ b/src/components/Previews/ChronologyEventPreview.astro @@ -0,0 +1,48 @@ +--- +import GenericPreview from "components/Previews/GenericPreview.astro"; +import { getI18n } from "src/i18n/i18n"; +import type { EndpointChronologyEvent } from "src/shared/payload/payload-sdk"; +import { formatRichTextToString, formatTimelineDateToId } from "src/utils/format"; + +interface Props { + event: EndpointChronologyEvent["events"][number]; + date: EndpointChronologyEvent["date"]; +} + +const { getLocalizedUrl, getLocalizedMatch, t, formatTimelineDate } = await getI18n( + Astro.locals.currentLocale +); + +const { + date, + event: { translations }, +} = Astro.props; + +const { title, description, language } = getLocalizedMatch(translations); + +const getTruncatedText = () => { + const getTextContent = () => { + if (title) return title; + if (description) return formatRichTextToString(description); + return ""; + }; + + const text = getTextContent(); + const limit = 45; + const truncationMark = "..."; + if (text.length < limit) return text; + return text.substring(0, limit - truncationMark.length) + truncationMark; +}; +--- + +{/* ------------------------------------------- HTML ------------------------------------------- */} + + diff --git a/src/components/Previews/FolderPreview.astro b/src/components/Previews/FolderPreview.astro new file mode 100644 index 0000000..00096ff --- /dev/null +++ b/src/components/Previews/FolderPreview.astro @@ -0,0 +1,56 @@ +--- +import GenericPreview from "components/Previews/GenericPreview.astro"; +import { getI18n } from "src/i18n/i18n"; +import type { EndpointFolder } from "src/shared/payload/payload-sdk"; +import type { Attribute } from "src/utils/attributes"; + +interface Props { + folder: EndpointFolder; +} + +const { getLocalizedUrl, getLocalizedMatch, t } = await getI18n( + Astro.locals.currentLocale +); + +const { + folder: { translations, slug, files, sections, parentPages }, +} = Astro.props; + +const { language, title } = getLocalizedMatch(translations); + +const fileCount = files.length; + +const subfolderCount = + sections.type === "single" + ? sections.subfolders.length + : sections.sections.reduce((acc, section) => acc + section.subfolders.length, 0); + +const attributes: Attribute[] = [ + { + icon: "material-symbols:box", + title: t("global.folders.attributes.content.label"), + values: [{ name: t("global.folders.attributes.content.value", { fileCount, subfolderCount }) }], + }, + { + icon: "material-symbols:keyboard-return", + title: t("global.folders.attributes.parent"), + values: parentPages.flatMap((parent) => { + if (parent.type !== "folder") return []; + const name = getLocalizedMatch(parent.folder.translations).title; + return { name }; + }), + }, +]; +--- + +{/* ------------------------------------------- HTML ------------------------------------------- */} + + diff --git a/src/components/Previews/GenericPreview.astro b/src/components/Previews/GenericPreview.astro index 3080b4b..8e211fb 100644 --- a/src/components/Previews/GenericPreview.astro +++ b/src/components/Previews/GenericPreview.astro @@ -113,8 +113,18 @@ for (const attribute of attributes) {