6
1
Fork 0

almost solved basepath problem

pull/1/head
parent 1aa20d896e
commit 13194630ac

@ -13,13 +13,17 @@ export default defineConfig({
}, },
markdown: { markdown: {
remarkPlugins: [remarkMath], remarkPlugins: [remarkMath],
remarkRehype: {
passThrough: ['html'],
},
shikiConfig: { shikiConfig: {
theme: 'github-light', theme: 'github-light',
}, },
}, },
integrations: [mdx()], integrations: [
mdx({
remarkPlugins: [remarkMath],
shikiConfig: {
theme: 'github-light',
},
}),
],
output: 'static', output: 'static',
}) })

@ -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('./') ? (
<>
<Fragment set:html={`<!-- External or relative link -->`} />
<a href={href} {...rest}>
<slot />
</a>
</>
) : (
<>
<Fragment set:html={`<!-- Internal link, Basepath: "${basepath}/" -->`} />
<a href={basepath + (href.startsWith(basepath) ? href.slice(basepath.length) : href)} {...rest}>
<slot />
</a>
</>
)
}

@ -1,4 +1,6 @@
--- ---
import Link from '@/components/Link.astro'
type Props = { type Props = {
post: { post: {
title: string title: string
@ -14,9 +16,9 @@ const { post } = Astro.props
<div class="card"> <div class="card">
<div class="title"> <div class="title">
<a href={post.url}> <Link href={post.url}>
{post.title} {post.title}
</a> </Link>
</div> </div>
<div class="date"> <div class="date">
{ {
@ -36,9 +38,9 @@ const { post } = Astro.props
<div class="tags"> <div class="tags">
{ {
post.tags?.map(tag => ( post.tags?.map(tag => (
<a href={`/posts/tags/${tag}`} class="tag"> <Link href={`/posts/tags/${tag}`} class="tag">
#{tag} #{tag}
</a> </Link>
)) ))
} }
</div> </div>

@ -1,5 +1,6 @@
--- ---
import config from '@/config' import config from '@/config'
import Link from '@/components/Link.astro'
import 'katex/dist/katex.min.css' import 'katex/dist/katex.min.css'
import '@/themes/base.css' import '@/themes/base.css'
@ -61,7 +62,7 @@ import '@/themes/modern.css'
<body> <body>
<header> <header>
<h1> <h1>
<a href="/">{config.title}</a> <Link href="/">{config.title}</Link>
</h1> </h1>
<div class="spacer"></div> <div class="spacer"></div>
@ -76,9 +77,9 @@ import '@/themes/modern.css'
</label> </label>
<nav> <nav>
<div class="nav-item"><a href="/">Home</a></div> <div class="nav-item"><Link href="/">Home</Link></div>
<div class="nav-item"><a href="/appunti">Appunti</a></div> <div class="nav-item"><Link href="/appunti">Appunti</Link></div>
<div class="nav-item"><a href="/posts">Post</a></div> <div class="nav-item"><Link href="/posts">Post</Link></div>
</nav> </nav>
</header> </header>

@ -1,6 +1,7 @@
--- ---
import config from '@/config' import config from '@/config'
import Base from './Base.astro' import Base from './Base.astro'
import Link from '@/components/Link.astro'
type Props = { type Props = {
frontmatter: { frontmatter: {
@ -34,9 +35,9 @@ const { frontmatter } = Astro.props
frontmatter.tags && frontmatter.tags.length > 0 ? ( frontmatter.tags && frontmatter.tags.length > 0 ? (
<div class="tags"> <div class="tags">
{frontmatter.tags.map(tag => ( {frontmatter.tags.map(tag => (
<a href={`/posts/tags/${tag}`} class="tag"> <Link href={`/posts/tags/${tag}`} class="tag">
#{tag} #{tag}
</a> </Link>
))} ))}
</div> </div>
) : null ) : null

@ -3,6 +3,8 @@ layout: '@/layouts/Post.astro'
title: Appunti title: Appunti
--- ---
import Link from '@/components/Link.astro'
## Corso 1 ## Corso 1
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod beatae, alias vitae assumenda quia 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. commodi iusto. Enim harum perspiciatis quae ea nihil iusto saepe cum! Doloribus, ullam dolorum.
<p class="text-center"> <p class="text-center">
<a class="button" href="/materiale/dispensa-1.pdf">Scarica</a> <Link class="button" href="/materiale/dispensa-1.pdf">Scarica</Link>
</p> </p>
## Corso 2 ## Corso 2
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod beatae, alias vitae assumenda quia 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. commodi iusto. Enim harum perspiciatis quae ea nihil iusto saepe cum! Doloribus, ullam dolorum.
<p class="text-center"> <p class="text-center">
<a class="button" href="/materiale/dispensa-1.pdf">Scarica</a> <Link class="button" href="/materiale/dispensa-1.pdf">Scarica</Link>
</p> </p>
## Corso 3 ## 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. commodi iusto. Enim harum perspiciatis quae ea nihil iusto saepe cum! Doloribus, ullam dolorum.
<p class="text-center"> <p class="text-center">
<a class="button" href="/materiale/dispensa-1.pdf">Scarica</a> <Link class="button" href="/materiale/dispensa-1.pdf">Scarica</Link>
</p> </p>

@ -1,5 +1,6 @@
--- ---
import Base from '@/layouts/Base.astro' import Base from '@/layouts/Base.astro'
import Link from '@/components/Link.astro'
import type { MarkdownInstance } from 'astro' import type { MarkdownInstance } from 'astro'
import type { PostFrontmatter } from '@/config' import type { PostFrontmatter } from '@/config'
import config from '@/config' import config from '@/config'
@ -12,7 +13,7 @@ const posts = import.meta.glob<MarkdownInstance<PostFrontmatter>>('./*.md', { ea
<main> <main>
<h1>Archivio Post</h1> <h1>Archivio Post</h1>
<p> <p>
<a href="/posts/tags" class="forward-link">Vai all'Archivio Tag →</a> <Link href="/posts/tags" class="forward-link">Vai all'Archivio Tag →</Link>
</p> </p>
<div class="card-list"> <div class="card-list">
{ {

@ -1,5 +1,6 @@
--- ---
import Base from '@/layouts/Base.astro' import Base from '@/layouts/Base.astro'
import Link from '@/components/Link.astro'
import PostCard from '@/components/PostCard.astro' import PostCard from '@/components/PostCard.astro'
import type { MarkdownInstance } from 'astro' import type { MarkdownInstance } from 'astro'
import type { PostFrontmatter } from '@/config' import type { PostFrontmatter } from '@/config'
@ -49,10 +50,10 @@ const { tag, taggedPosts, relatedTags } = Astro.props
<Base> <Base>
<main> <main>
<h2>Post con tag <a href={`/posts/tags/${tag}`}>#{tag}</a></h2> <h2>Post con tag <Link href={`/posts/tags/${tag}`}>#{tag}</Link></h2>
<p> <p>
{taggedPosts.length} post{taggedPosts.length !== 1 ? 's' : ''} trovato{taggedPosts.length !== 1 ? 'i' : ''}. {taggedPosts.length} post{taggedPosts.length !== 1 ? 's' : ''} trovato{taggedPosts.length !== 1 ? 'i' : ''}.
<a href="/posts/tags" class="back-link">← Torna a tutti i tag</a> <Link href="/posts/tags" class="back-link">← Torna a tutti i tag</Link>
</p> </p>
{ {
taggedPosts.length > 0 ? ( taggedPosts.length > 0 ? (
@ -70,9 +71,9 @@ const { tag, taggedPosts, relatedTags } = Astro.props
<> <>
<p>Nessun post trovato per questo tag.</p> <p>Nessun post trovato per questo tag.</p>
<p> <p>
<a href="/posts" class="button"> <Link href="/posts" class="button">
Esplora tutti i post Esplora tutti i post
</a> </Link>
</p> </p>
</> </>
) )
@ -84,9 +85,9 @@ const { tag, taggedPosts, relatedTags } = Astro.props
<h2>Tag correlati</h2> <h2>Tag correlati</h2>
<div class="tags"> <div class="tags">
{relatedTags.map(relatedTag => ( {relatedTags.map(relatedTag => (
<a href={`/posts/tags/${relatedTag}`} class="tag"> <Link href={`/posts/tags/${relatedTag}`} class="tag">
#{relatedTag} #{relatedTag}
</a> </Link>
))} ))}
</div> </div>
</> </>

@ -1,5 +1,6 @@
--- ---
import Base from '@/layouts/Base.astro' import Base from '@/layouts/Base.astro'
import Link from '@/components/Link.astro'
import type { MarkdownInstance } from 'astro' import type { MarkdownInstance } from 'astro'
import type { PostFrontmatter } from '@/config' import type { PostFrontmatter } from '@/config'
@ -38,9 +39,9 @@ const sortedTags = Array.from(tagCounts.entries()).sort((a, b) => {
<div class="tags"> <div class="tags">
{ {
sortedTags.map(([tag, count]) => ( sortedTags.map(([tag, count]) => (
<a href={`/posts/tags/${tag}`} class="tag"> <Link href={`/posts/tags/${tag}`} class="tag">
#{tag} ({count}) #{tag} ({count})
</a> </Link>
)) ))
} }
</div> </div>

Loading…
Cancel
Save