fix: footnote language
Signed-off-by: Filipe Medeiros <hello@filipesm.eu>
This commit is contained in:
parent
76c6fc84e3
commit
5d2c44d838
|
@ -2,18 +2,13 @@
|
||||||
import type { PortableTextBlock } from '@portabletext/types';
|
import type { PortableTextBlock } from '@portabletext/types';
|
||||||
import { PortableText } from 'astro-portabletext';
|
import { PortableText } from 'astro-portabletext';
|
||||||
import InlineLink from './portableText/components/InlineLink.astro';
|
import InlineLink from './portableText/components/InlineLink.astro';
|
||||||
|
import langToFootnoteString from '../lib/langToFootnoteString';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
blogPostContent: PortableTextBlock[];
|
blogPostContent: PortableTextBlock[];
|
||||||
}
|
}
|
||||||
|
|
||||||
let footnoteString: string;
|
const footnoteString = langToFootnoteString(Astro);
|
||||||
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 { blogPostContent } = Astro.props;
|
const { blogPostContent } = Astro.props;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
---
|
---
|
||||||
import type { PortableTextListItemBlock } from '@portabletext/types';
|
import type { PortableTextListItemBlock } from '@portabletext/types';
|
||||||
import InlineLink from '../../InlineLink.astro';
|
import InlineLink from '../../InlineLink.astro';
|
||||||
|
import langToFootnoteString from '../../../lib/langToFootnoteString';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
node: PortableTextListItemBlock;
|
node: PortableTextListItemBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const footnoteString = langToFootnoteString(Astro);
|
||||||
|
|
||||||
// This is an incredible hack!! Ahah
|
// This is an incredible hack!! Ahah
|
||||||
// Not sure if safe, but seems to be
|
// Not sure if safe, but seems to be
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -27,7 +30,7 @@ const footnoteCount = globalThis.footnoteCounts[Astro.params.slug!];
|
||||||
|
|
||||||
<slot /><InlineLink
|
<slot /><InlineLink
|
||||||
class="align-super ml-1 text-sm"
|
class="align-super ml-1 text-sm"
|
||||||
href={`#footnote-${footnoteCount}`}
|
href={`#${footnoteString}-${footnoteCount}`}
|
||||||
>
|
>
|
||||||
{footnoteCount}
|
{footnoteCount}
|
||||||
</InlineLink>
|
</InlineLink>
|
||||||
|
|
13
frontend/src/lib/langToFootnoteString.ts
Normal file
13
frontend/src/lib/langToFootnoteString.ts
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue