diff --git a/astro.config.mjs b/astro.config.mjs index 212f4c8..06ff26d 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -13,13 +13,17 @@ export default defineConfig({ }, markdown: { remarkPlugins: [remarkMath], - remarkRehype: { - passThrough: ['html'], - }, shikiConfig: { theme: 'github-light', }, }, - integrations: [mdx()], + integrations: [ + mdx({ + remarkPlugins: [remarkMath], + shikiConfig: { + theme: 'github-light', + }, + }), + ], output: 'static', }) diff --git a/src/components/Link.astro b/src/components/Link.astro new file mode 100644 index 0000000..c31906a --- /dev/null +++ b/src/components/Link.astro @@ -0,0 +1,34 @@ +--- +import type { JSX } from 'astro/jsx-runtime' + +type Props = { + href: string +} & JSX.AnchorHTMLAttributes + +const { href, ...rest } = Astro.props + +const basepath = Astro.site?.pathname || '' + +// assert link starts with http, ./ or / +if (!href.startsWith('://') && !href.startsWith('./') && !href.startsWith('/')) { + throw new Error(`Invalid href: ${href}. It must be an external link or start with './', or '/'`) +} +--- + +{ + href.includes('://') || href.startsWith('./') ? ( + <> + `} /> + + + + + ) : ( + <> + `} /> + + + + + ) +} diff --git a/src/components/PostCard.astro b/src/components/PostCard.astro index 825de2d..76a2bcf 100644 --- a/src/components/PostCard.astro +++ b/src/components/PostCard.astro @@ -1,4 +1,6 @@ --- +import Link from '@/components/Link.astro' + type Props = { post: { title: string @@ -14,9 +16,9 @@ const { post } = Astro.props
{ @@ -36,9 +38,9 @@ const { post } = Astro.props
{ post.tags?.map(tag => ( - + #{tag} - + )) }
diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index 15122f3..1903fbc 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -1,5 +1,6 @@ --- import config from '@/config' +import Link from '@/components/Link.astro' import 'katex/dist/katex.min.css' import '@/themes/base.css' @@ -61,7 +62,7 @@ import '@/themes/modern.css'

- {config.title} + {config.title}

@@ -76,9 +77,9 @@ import '@/themes/modern.css'
diff --git a/src/layouts/Post.astro b/src/layouts/Post.astro index 65a2fbe..92c6001 100644 --- a/src/layouts/Post.astro +++ b/src/layouts/Post.astro @@ -1,6 +1,7 @@ --- import config from '@/config' import Base from './Base.astro' +import Link from '@/components/Link.astro' type Props = { frontmatter: { @@ -34,9 +35,9 @@ const { frontmatter } = Astro.props frontmatter.tags && frontmatter.tags.length > 0 ? (
{frontmatter.tags.map(tag => ( - + #{tag} - + ))}
) : null diff --git a/src/pages/appunti/index.md b/src/pages/appunti/index.mdx similarity index 80% rename from src/pages/appunti/index.md rename to src/pages/appunti/index.mdx index 50ab561..72efe8d 100644 --- a/src/pages/appunti/index.md +++ b/src/pages/appunti/index.mdx @@ -3,6 +3,8 @@ layout: '@/layouts/Post.astro' title: Appunti --- +import Link from '@/components/Link.astro' + ## Corso 1 Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod beatae, alias vitae assumenda quia @@ -10,9 +12,10 @@ corporis quos natus laboriosam illo consectetur. Praesentium explicabo vitae ass commodi iusto. Enim harum perspiciatis quae ea nihil iusto saepe cum! Doloribus, ullam dolorum.

- Scarica + Scarica

+ ## Corso 2 Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod beatae, alias vitae assumenda quia @@ -20,7 +23,7 @@ corporis quos natus laboriosam illo consectetur. Praesentium explicabo vitae ass commodi iusto. Enim harum perspiciatis quae ea nihil iusto saepe cum! Doloribus, ullam dolorum.

- Scarica + Scarica

## Corso 3 @@ -30,5 +33,5 @@ corporis quos natus laboriosam illo consectetur. Praesentium explicabo vitae ass commodi iusto. Enim harum perspiciatis quae ea nihil iusto saepe cum! Doloribus, ullam dolorum.

- Scarica + Scarica

diff --git a/src/pages/posts/index.astro b/src/pages/posts/index.astro index 94ed820..c5c946f 100644 --- a/src/pages/posts/index.astro +++ b/src/pages/posts/index.astro @@ -1,5 +1,6 @@ --- import Base from '@/layouts/Base.astro' +import Link from '@/components/Link.astro' import type { MarkdownInstance } from 'astro' import type { PostFrontmatter } from '@/config' import config from '@/config' @@ -12,7 +13,7 @@ const posts = import.meta.glob>('./*.md', { ea

Archivio Post

- Vai all'Archivio Tag → + Vai all'Archivio Tag →

{ diff --git a/src/pages/posts/tags/[tag].astro b/src/pages/posts/tags/[tag].astro index 243321b..e53394b 100644 --- a/src/pages/posts/tags/[tag].astro +++ b/src/pages/posts/tags/[tag].astro @@ -1,5 +1,6 @@ --- import Base from '@/layouts/Base.astro' +import Link from '@/components/Link.astro' import PostCard from '@/components/PostCard.astro' import type { MarkdownInstance } from 'astro' import type { PostFrontmatter } from '@/config' @@ -49,10 +50,10 @@ const { tag, taggedPosts, relatedTags } = Astro.props
-

Post con tag #{tag}

+

Post con tag #{tag}

{taggedPosts.length} post{taggedPosts.length !== 1 ? 's' : ''} trovato{taggedPosts.length !== 1 ? 'i' : ''}. - ← Torna a tutti i tag + ← Torna a tutti i tag

{ taggedPosts.length > 0 ? ( @@ -70,9 +71,9 @@ const { tag, taggedPosts, relatedTags } = Astro.props <>

Nessun post trovato per questo tag.

- + Esplora tutti i post - +

) @@ -84,9 +85,9 @@ const { tag, taggedPosts, relatedTags } = Astro.props

Tag correlati

{relatedTags.map(relatedTag => ( - + #{relatedTag} - + ))}
diff --git a/src/pages/posts/tags/index.astro b/src/pages/posts/tags/index.astro index a156f11..f4f0341 100644 --- a/src/pages/posts/tags/index.astro +++ b/src/pages/posts/tags/index.astro @@ -1,5 +1,6 @@ --- import Base from '@/layouts/Base.astro' +import Link from '@/components/Link.astro' import type { MarkdownInstance } from 'astro' import type { PostFrontmatter } from '@/config' @@ -38,9 +39,9 @@ const sortedTags = Array.from(tagCounts.entries()).sort((a, b) => {
{ sortedTags.map(([tag, count]) => ( - + #{tag} ({count}) - + )) }