From 5d2c44d838328d945f5b85d9b4a3d80d8e78319d Mon Sep 17 00:00:00 2001 From: Filipe Medeiros Date: Mon, 1 May 2023 20:03:06 +0100 Subject: [PATCH] fix: footnote language Signed-off-by: Filipe Medeiros --- frontend/src/components/BlogPostFootnotes.astro | 9 ++------- .../portableText/components/FootnoteMark.astro | 5 ++++- frontend/src/lib/langToFootnoteString.ts | 13 +++++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 frontend/src/lib/langToFootnoteString.ts diff --git a/frontend/src/components/BlogPostFootnotes.astro b/frontend/src/components/BlogPostFootnotes.astro index c8fb686..0e2a08e 100644 --- a/frontend/src/components/BlogPostFootnotes.astro +++ b/frontend/src/components/BlogPostFootnotes.astro @@ -2,18 +2,13 @@ import type { PortableTextBlock } from '@portabletext/types'; import { PortableText } from 'astro-portabletext'; import InlineLink from './portableText/components/InlineLink.astro'; +import langToFootnoteString from '../lib/langToFootnoteString'; export interface Props { blogPostContent: PortableTextBlock[]; } -let footnoteString: string; -if (Astro.url.pathname.includes('/blogue/')) footnoteString = 'rodape'; -else if (Astro.url.pathname.includes('/blog/')) footnoteString = 'footnot'; -else - throw new Error( - 'Please add the new language to the BlogPostFootnotes component', - ); +const footnoteString = langToFootnoteString(Astro); const { blogPostContent } = Astro.props; diff --git a/frontend/src/components/portableText/components/FootnoteMark.astro b/frontend/src/components/portableText/components/FootnoteMark.astro index 7e35f32..1bd0ae2 100644 --- a/frontend/src/components/portableText/components/FootnoteMark.astro +++ b/frontend/src/components/portableText/components/FootnoteMark.astro @@ -1,11 +1,14 @@ --- import type { PortableTextListItemBlock } from '@portabletext/types'; import InlineLink from '../../InlineLink.astro'; +import langToFootnoteString from '../../../lib/langToFootnoteString'; export interface Props { node: PortableTextListItemBlock; } +const footnoteString = langToFootnoteString(Astro); + // This is an incredible hack!! Ahah // Not sure if safe, but seems to be declare global { @@ -27,7 +30,7 @@ const footnoteCount = globalThis.footnoteCounts[Astro.params.slug!]; {footnoteCount} diff --git a/frontend/src/lib/langToFootnoteString.ts b/frontend/src/lib/langToFootnoteString.ts new file mode 100644 index 0000000..a3348b9 --- /dev/null +++ b/frontend/src/lib/langToFootnoteString.ts @@ -0,0 +1,13 @@ +import type { AstroGlobal } from 'astro'; + +export default function langToFootnoteString(Astro: Readonly) { + let footnoteString: string; + if (Astro.url.pathname.includes('/blogue/')) footnoteString = 'rodape'; + else if (Astro.url.pathname.includes('/blog/')) footnoteString = 'footnot'; + else + throw new Error( + 'Please add the new language to the `langToFootnoteString` function', + ); + + return footnoteString; +}