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; +}