feat: use src/content/index.md to render homepage

This commit is contained in:
grassblock 2025-05-24 22:09:25 +08:00
parent 0569d5577b
commit b814569bc6
2 changed files with 19 additions and 5 deletions

6
src/content/index.md Normal file
View file

@ -0,0 +1,6 @@
# Welcome
Thank you for choosing this theme!
If you want to see the posts, check out the [posts](/blog) page.
If you are site owner, you can manually edit the content of this page by editing the `src/content/index.md` file.

View file

@ -1,15 +1,23 @@
--- ---
import Layout from '../layouts/Layout.astro'; import Layout from '../layouts/Layout.astro';
// Conditionally import content if file exists
let HomePageContent;
try {
const module = await import('../content/index.md');
HomePageContent = module.Content;
} catch (e) {
// File doesn't exist or couldn't be imported
console.log('Homepage content not found, using default content');
}
--- ---
<Layout title="" description="That a good start."> <Layout title="" description="That a good start.">
<h1 class="title">~/</h1> <h1 class="title">~/</h1>
<div class="content"> <div class="content">
{HomePageContent ? <HomePageContent/> :
<h3>Welcome!</h3> <h3>Welcome!</h3>
<p>Not much here yet, but you can check out my blog posts <a href="/blog">here</a>.</p>
Not much here yet, but you can check out my blog posts <a href="/blog">here</a>. <p>If you are site owner, please create <code>src/content/index.md</code> to customize this page.</p>
<br /> }
If you are site owner, please edit <code>src/pages/index.astro</code> to customize this page.
</div> </div>
</Layout> </Layout>