fix: footnote language

Signed-off-by: Filipe Medeiros <hello@filipesm.eu>
This commit is contained in:
Filipe Medeiros 2023-05-01 20:03:06 +01:00
parent 76c6fc84e3
commit 5d2c44d838
Signed by: filipe
GPG key ID: 9533BD5467CC1E78
3 changed files with 19 additions and 8 deletions

View file

@ -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;

View file

@ -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!];
<slot /><InlineLink
class="align-super ml-1 text-sm"
href={`#footnote-${footnoteCount}`}
href={`#${footnoteString}-${footnoteCount}`}
>
{footnoteCount}
</InlineLink>

View file

@ -0,0 +1,13 @@
import type { AstroGlobal } from 'astro';
export default function langToFootnoteString(Astro: Readonly<AstroGlobal>) {
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;
}