Skip to content
Go back

详细的 Astro 框架学习计划

Edit page

我来为你制定一个详细的Astro框架学习计划,基于你现有的学习资源。让我先查看一下你已有的Astro学习材料。 Read file: Notebook/零碎/astro/Astro学习计划.md 基于你现有的学习资源,我来为你制定一个7天Astro框架学习计划,专门针对构建博客网站。这个计划比现有材料更加紧凑和实用。

🎯 7天Astro博客开发计划

前置条件检查

根据你现有的知识基础,你已经具备:

每日详细计划

第1天:环境搭建与基础概念 (周一)

上午 (2小时)

下午 (2小时)

实践任务

# 创建项目
npm create astro@latest my-blog --template blog
cd my-blog
npm install
npm run dev

第2天:博客基础架构 (周二)

上午 (2.5小时)

下午 (2.5小时)

实践任务

// src/content/config.ts
import { defineCollection, z } from 'astro:content';

const blog = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    description: z.string(),
    pubDate: z.coerce.date(),
    updatedDate: z.coerce.date().optional(),
    heroImage: z.string().optional(),
    tags: z.array(z.string()).default([]),
  }),
});

export const collections = { blog };

第3天:组件化开发 (周三)

上午 (2.5小时)

下午 (2.5小时)

实践任务

---
// src/components/BlogCard.astro
export interface Props {
  title: string;
  description: string;
  pubDate: Date;
  slug: string;
  tags: string[];
}
const { title, description, pubDate, slug, tags } = Astro.props;
---
<article class="blog-card">
  <h2><a href={`/blog/${slug}`}>{title}</a></h2>
  <p>{description}</p>
  <time>{pubDate.toLocaleDateString()}</time>
  <div class="tags">
    {tags.map(tag => <span class="tag">{tag}</span>)}
  </div>
</article>

第4天:高级功能实现 (周四)

上午 (2.5小时)

下午 (2.5小时)

实践任务

// src/pages/rss.xml.ts
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';

export async function GET(context) {
  const posts = await getCollection('blog');
  return rss({
    title: 'My Astro Blog',
    description: 'My blog built with Astro',
    site: context.site,
    items: posts.map((post) => ({
      title: post.data.title,
      pubDate: post.data.pubDate,
      description: post.data.description,
      link: `/blog/${post.slug}/`,
    })),
  });
}

第5天:SEO与性能优化 (周五)

上午 (2.5小时)

下午 (2.5小时)

实践任务

---
// src/layouts/BaseLayout.astro
export interface Props {
  title: string;
  description: string;
  image?: string;
}
const { title, description, image = '/default-og-image.png' } = Astro.props;
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
---

<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width" />
    <title>{title}</title>
    <meta name="description" content={description} />
    
    <!-- Open Graph -->
    <meta property="og:type" content="website" />
    <meta property="og:url" content={canonicalURL} />
    <meta property="og:title" content={title} />
    <meta property="og:description" content={description} />
    <meta property="og:image" content={new URL(image, Astro.url)} />
  </head>
  <body>
    <slot />
  </body>
</html>

第6天:部署准备 (周六)

上午 (2小时)

下午 (3小时)

部署配置

# netlify.toml
[build]
  command = "npm run build"
  publish = "dist"

[[redirects]]
  from = "/api/*"
  to = "/.netlify/functions/:splat"
  status = 200

第7天:上线与优化 (周日)

上午 (2小时)

下午 (3小时)

每日学习资源

官方文档重点

推荐插件和工具

{
  "devDependencies": {
    "@astrojs/tailwind": "^5.0.0",
    "@astrojs/sitemap": "^3.0.0",
    "@astrojs/mdx": "^2.0.0",
    "astro-compress": "^2.0.0",
    "sharp": "^0.32.0"
  }
}

项目结构建议

my-blog/
├── src/
│   ├── components/
│   │   ├── BlogCard.astro
│   │   ├── Navigation.astro
│   │   └── Footer.astro
│   ├── layouts/
│   │   ├── BaseLayout.astro
│   │   └── BlogLayout.astro
│   ├── content/
│   │   └── blog/
│   │       ├── first-post.md
│   │       └── second-post.md
│   ├── pages/
│   │   ├── index.astro
│   │   ├── blog/
│   │   │   ├── [...slug].astro
│   │   │   └── index.astro
│   │   └── tags/
│   │       └── [tag].astro
│   └── styles/
│       └── global.css
├── public/
├── astro.config.mjs
└── package.json

学习检查点

后续学习方向

  1. Astro 3.0+新特性:视图转换API
  2. 服务端渲染(SSR):动态内容处理
  3. API集成:headless CMS集成
  4. 性能优化:Core Web Vitals优化
  5. 多语言支持:国际化(i18n)

这个计划充分利用了你现有的学习资源,同时保持了一周完成的紧凑性。每天的学习任务都是具体可执行的,最终你将拥有一个功能完整的Astro博客网站。

你觉得这个计划如何?需要我调整某个部分的重点吗?


Edit page
Share this post on:

Previous Post
Astro 框架学习计划
Next Post
.gitignore文件生成和编写