Communitygithub.com

Illia-sanzh/greenclaw-agent

管理 Astro 静态站点的操作:创建、编辑和删除博客文章,导入文档,上传图片,编辑组件和样式,并通过 Git 自动部署至 Cloudflare Workers。

greenclaw-agent 是什么?

该技能为 AI 代理提供了管理 Astro 静态站点的全套操作指南。它支持创建、编辑和删除基于 Markdown/MDX 的内容集合博客文章,并能够从 .docx 和 .pdf 文档导入内容并转换为 Markdown。同时允许上传图片至 src/assets/ 目录、编辑 .astro 组件和布局、修改 MDX 文件以及全局/组件级样式。变更通过 Git 提交后,可自动触发 Cloudflare Workers 部署(或运行 `npx wrangler deploy`)。技能包含清晰的内容集合 schema、组件和布局示例、动态路由实现以及安全规则,确保项目结构不被破坏。适用于 Claude Code、Cursor 等 AI 代理平台,帮助用户高效完成从内容创作到部署的全流程。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Illia-sanzh/greenclaw-agent/tree/HEAD

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

预览

来自技能 README

alt
alt

文档

Astro 站点管理 —— 代理知识

能力

你可以通过以下操作管理 Astro 静态站点:

  • 创建、编辑和删除博客文章(内容集合中的 Markdown/MDX)
  • 导入文档(.docx,.pdf)并将其转换为 Markdown
  • 在 src/assets/ 中上传和组织图片
  • 编辑组件(.astro)、布局和页面
  • 编辑带有交互式组件的 MDX 文件
  • 修改全局和组件级样式
  • 将更改推送到 Git 以自动部署 Cloudflare Workers(或运行 npx wrangler deploy)
  • 运行 npm 命令(build,dev,add packages)

内容集合

内容集合使用 src/content/,并在 src/content/config.ts 中定义 schema。

博客文章

位置:src/content/blog/*.md 或 *.mdx

必需的 frontmatter:

---
title: "文章标题"
description: "SEO 描述"
pubDate: 2024-01-15
---

可选字段:updatedDate,heroImage,draft,tags

创建文章

  1. 将带有 frontmatter 的 Markdown 文件写入 src/content/blog/<slug>.md
  2. 将图片放入 src/assets/<slug>/
  3. 引用图片:![alt](~/assets/<slug>/image.jpg)
  4. Git add,commit,push 以部署

查询内容集合

在 .astro 页面中:

---
import { getCollection } from "astro:content";
const posts = await getCollection("blog");
const sorted = posts.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
---

组件模式

基本 .astro 组件

---
const { title, class: className } = Astro.props;
---
<section class:list={["section", className]}>
  <h2>{title}</h2>
  <slot />
</section>

<style>
  .section { padding: 2rem; }
</style>

布局模式

---
import BaseHead from "../components/BaseHead.astro";
import Header from "../components/Header.astro";
import Footer from "../components/Footer.astro";
const { title, description } = Astro.props;
---
<html lang="en">
<head><BaseHead title={title} description={description} /></head>
<body>
  <Header />
  <main><slot /></main>
  <Footer />
</body>
</html>

动态路由

文件:src/pages/blog/[...slug].astro

---
import { getCollection } from "astro:content";
export async function getStaticPaths() {
  const posts = await getCollection("blog");
  return posts.map((post) => ({ params: { slug: post.slug }, props: post }));
}
const post = Astro.props;
const { Content } = await post.render();
---
<Content />

安全规则

  • 绝不删除 .git 目录
  • 除非重新安装,否则绝不删除 node_modules/ 或 package-lock.json
  • 绝不强制推送(git push --force)
  • 绝不推送到配置的部署分支以外的其他分支
  • 未经用户明确要求,不得修改 astro.config.mjs 或 wrangler.toml
  • 绝不在项目根目录运行 rm -rf
  • 删除任何组件或页面文件前需请求确认

常见任务

添加一篇博客文章

  1. write_file 创建 src/content/blog/<slug>.md,包含 frontmatter 和内容
  2. git_operations status → add → commit → push

导入文档

  1. convert_document 使用上传的文件路径
  2. read_file 读取生成的 Markdown 以审查
  3. 如有需要,使用 write_file 编辑 frontmatter
  4. git_operations add → commit → push

编辑组件

  1. read_file 读取组件以理解当前代码
  2. write_file 写入更新后的组件
  3. git_operations add → commit → push

修改站点样式

  1. read_file 读取相关的 CSS 文件或组件
  2. write_file 写入更新后的样式
  3. git_operations add → commit → push

上传图片

  1. 使用 write_file 或 run_command 将图片保存到 src/assets/<folder>/
  2. 在 Markdown 中引用:![alt](~/assets/<folder>/image.jpg)
  3. 或在 .astro 中:import img from "~/assets/<folder>/image.jpg"

相关技能