页面与布局
深入了解如何创建页面、使用布局和构建内容。
本快速入门将带你完成创建第一个自定义页面并将 varsha 站点准备好部署的步骤。假设你已经安装了 varsha。
如果开发服务器尚未运行,启动它:
npm run dev在浏览器中打开 http://localhost:4321,你应该能看到 varsha 的首页。
打开 astro.config.mjs 并更新站点配置以匹配你的品牌:
export default defineConfig({ site: 'https://your-domain.com', // 替换为你的域名 // ... integrations: [ sitemap(), starlight({ title: 'Your Product Name', description: 'A short description of your product or service.', // ... }), ],});在 src/pages/about.astro 创建一个新文件:
---import MarketingLayout from '../components/MarketingLayout.astro';---
<MarketingLayout title="About Us" description="Learn about our company and mission." canonicalPath="/about/"> <main class="page"> <section class="hero"> <h1>About Us</h1> <p>We build tools that help people ship faster.</p> </section>
<section class="section"> <div class="container"> <h2>Our Mission</h2> <p> This is your first custom page. Edit it freely — add sections, components, images, and whatever else your site needs. </p> </div> </section> </main></MarketingLayout>访问 http://localhost:4321/about 查看新页面。它将自动继承站点页眉、页脚、主题切换器和 “Built with varsha” 署名。
打开 src/components/MarketingLayout.astro,在导航中添加新页面的链接:
<div class="nav-links"> <a href="/">Home</a> <a href="/about/">About</a> <!-- 现有链接 --></div>记得同时更新移动端导航面板(.nav-menu-panel)以保持桌面和移动端导航同步。
在任意页面按 / 或 t 键打开主题切换器。varsha 内置 18+ 主题:
你选择的主题会保存在 localStorage 中,跨会话保持。
在 src/content/blog/my-first-post.md 创建一篇新博客文章:
---title: "My First Post"description: "Hello world from my varsha site."pubDate: "2025-01-15"---
Welcome to my blog! This is my first post powered by varsha.
## What's next
- Write more posts- Customize the design- Deploy to production访问 http://localhost:4321/blog/ 查看文章。
准备好上线后,创建生产构建:
npm run build部署前在本地预览生产构建:
npm run preview静态输出将生成在 dist/ 目录中,可以部署到任何静态托管平台。
最快的部署方式是使用 Vercel:
npx vercel或者将你的 Git 仓库连接到 Vercel、Netlify、Cloudflare Pages,每次推送时自动部署。有关平台特定的说明,请参阅部署指南。
在 5 分钟内,你已经:
MarketingLayout 创建了新页面