友链自助申请功能添加教程
点击按钮,AI 将为你生成这篇文章的摘要
一、功能介绍
本教程为 Firefly Astro 博客添加友链自助申请功能,实现两种申请入口:
| 入口位置 | 说明 |
|---|---|
| 右上角按钮 | 醒目的主题色按钮,点击直接跳转 GitHub Issue 表单 |
| 页面内文字链接 | 在申请流程步骤中显示,体验友好 |
功能特点
- ✅ 不破坏原有布局,不影响任何功能
- ✅ 适配明暗主题
- ✅ 支持 GitHub Issue 自动表单
- ✅ 访客一键提交,方便管理
- ✅ 全程只需修改 2 个文件 + 创建 1 个模板
二、准备工作
1. 确认 GitHub 仓库地址
你需要准备一个 GitHub Issue 申请地址,格式如下:
https://github.com/你的用户名/你的仓库名/issues/new?template=friend-request.yml例如:
https://github.com/fqzlr/Firefly/issues/new?template=friend-request.yml2. 确保仓库已启用 Issues
在 GitHub 仓库设置中,确保已启用 Issues 功能。
三、添加 GitHub Issue 模板
步骤 1:创建模板目录
在项目根目录创建以下目录结构:
.github/└── ISSUE_TEMPLATE/ └── friend-request.yml步骤 2:创建模板文件
创建 .github/ISSUE_TEMPLATE/friend-request.yml 文件,内容如下:
name: 友链申请description: 申请添加友情链接title: "【友链申请】"labels: ["友链"]body: - type: input id: site_name attributes: label: 站点名称 description: 请输入你的站点名称 placeholder: 例如:我的博客 validations: required: true
- type: input id: site_url attributes: label: 站点链接 description: 请输入你的站点 URL(需要 HTTPS) placeholder: https://example.com validations: required: true
- type: input id: site_desc attributes: label: 站点描述 description: 请用一句话描述你的站点 placeholder: 一个关于技术分享的个人博客 validations: required: true
- type: input id: site_avatar attributes: label: 站点头像 description: 请输入头像 URL(建议 640x640) placeholder: https://example.com/avatar.png validations: required: true
- type: dropdown id: site_category attributes: label: 站点类别 description: 请选择你的站点类别 options: - 个人博客 - 技术分享 - 生活记录 - 学习笔记 - 作品集 - 其他 validations: required: true
- type: textarea id: site_content attributes: label: 站点内容 description: 请简要描述你站点的主要内容和特色 placeholder: | 我的博客主要分享: - 前端开发技术 - 编程学习笔记 - 开源项目介绍 validations: required: false
- type: checkboxes id: confirmation attributes: label: 确认事项 description: 请确认以下事项 options: - label: 我已将本站添加到我的友链页面 required: true - label: 我的站点支持 HTTPS 访问 required: true - label: 我的站点内容积极向上,无违法违规内容 required: true四、修改 friends.astro
步骤 1:添加申请链接变量
打开 src/pages/friends.astro,在文件顶部的变量区域(第 42 行左右)添加:
// 友链申请链接const friendApplyUrl = "https://github.com/fqzlr/Firefly/issues/new?template=friend-request.yml";步骤 2:替换标题区域布局
找到页面标题部分(约第 51-69 行),替换为以下代码:
<!-- 页面标题和描述 --><div class="flex flex-col gap-4 md:flex-row md:items-end md:justify-between mb-4"> <div> <div class="flex items-center gap-3 mb-3"> <div class="h-8 w-8 rounded-lg bg-(--primary) flex items-center justify-center text-white dark:text-black/70"> <Icon name="material-symbols:group" class="text-[1.5rem]" /> </div> <div class="text-3xl font-bold text-neutral-900 dark:text-neutral-100"> {title} </div> </div> { description && ( <p class="text-base text-neutral-600 dark:text-neutral-400 leading-relaxed"> {description} </p> ) } </div>
<!-- 自助申请友链按钮 --> <div class="flex shrink-0 flex-col items-start gap-2 md:items-end"> <a href={friendApplyUrl} target="_blank" rel="noopener noreferrer" class="inline-flex items-center gap-2 rounded-lg bg-(--primary) px-4 py-2.5 text-sm font-medium text-white dark:text-black/70 transition-all hover:opacity-90 hover:scale-[1.02] active:scale-[0.98]" > <Icon name="material-symbols:add-link-rounded" class="text-lg" /> <span>自助申请友链</span> </a> <p class="text-xs text-neutral-500 dark:text-neutral-400 md:text-right"> 通过 GitHub Issue 提交,系统会自动校验回链并同步收录 </p> </div></div>五、修改 friends.mdx
步骤:添加文字超链接
打开 src/content/spec/friends.mdx,找到 Step 2 部分,将原来的:
<p class="font-semibold text-sm mb-1">评论区留言/发送申请邮件至:<code class="px-1.5 py-0.5 rounded bg-black/5 dark:bg-white/10 text-[0.7rem]">{site.email}</code></p><p class="text-xs text-neutral-500 dark:text-neutral-400 leading-relaxed">申请模板,把内容复制修改后到评论区或邮件中发送</p>替换为:
<p class="font-semibold text-sm mb-1"> <a href="https://github.com/fqzlr/Firefly/issues/new?template=friend-request.yml" target="_blank" class="inline-block text-(--primary) hover:underline"> 自助申请友链 </a> 或评论区留言/发送申请邮件至:<code class="px-1.5 py-0.5 rounded bg-black/5 dark:bg-white/10 text-[0.7rem]">{site.email}</code></p><p class="text-xs text-neutral-500 dark:text-neutral-400 leading-relaxed">推荐通过 GitHub Issue 提交,系统会自动校验回链;也可使用申请模板,把内容复制修改后到评论区或邮件中发送</p>六、注意事项
1. 修改 GitHub 地址
将代码中的 https://github.com/fqzlr/Firefly/issues/new?template=friend-request.yml 替换为你自己的 GitHub 仓库地址。
2. CSS 变量问题
如果按钮文字看不见,可能是 CSS 变量问题,可以使用固定色值:
class="... bg-blue-500 text-white ..."3. 跳转 404
检查以下内容:
- GitHub 用户名是否正确
- 仓库名是否正确
- yml 模板文件名是否正确(区分大小写)
4. 样式错位
只替换教程里对应的代码块,不要改动其他结构。
5. 图标问题
确保项目中已安装 astro-icon 图标库,并且以下图标可用:
material-symbols:groupmaterial-symbols:add-link-rounded
七、使用方法
访客申请流程
- 访客打开友链页面
- 点击右上角「自助申请友链」按钮
- 跳转到 GitHub Issue 表单
- 填写站点信息并提交
- 博主在 GitHub Issues 中查看并审核
博主管理流程
- 在 GitHub 仓库的 Issues 页面查看新申请
- 检查申请信息是否完整
- 确认申请站点已添加本站友链
- 添加申请站点到友链列表
- 关闭 Issue 或添加标签
八、最终效果
你的友链页面现在拥有:
- ✅ 右上角申请按钮:醒目、直观,点击直接跳转
- ✅ 步骤中的文字链接:流程清晰、体验友好
- ✅ GitHub Issue 自动表单:信息完整,方便管理
- ✅ 适配明暗主题:深色/浅色模式都能正常显示
两者配合,访客可以非常方便地提交友链申请,博主也能高效管理友链!
九、常见问题
Q1: 按钮文字看不见?
解决方案: 使用固定色值替代 CSS 变量
class="... bg-blue-500 text-white ..."Q2: 跳转 404?
解决方案: 检查 GitHub 地址是否正确
- 用户名
- 仓库名
- yml 模板文件名(区分大小写)
Q3: 样式错位?
解决方案: 只替换教程里对应的代码块,不要改动其他结构
Q4: Issue 模板不显示?
解决方案: 确保文件路径正确:.github/ISSUE_TEMPLATE/friend-request.yml
Q5: 如何自定义表单字段?
解决方案: 参考 GitHub Issue 表单文档 修改 yml 文件
十、总结
本教程通过修改 2 个文件,为 Firefly Astro 博客添加了友链自助申请功能:
| 文件 | 修改内容 |
|---|---|
src/pages/friends.astro | 添加申请按钮 |
src/content/spec/friends.mdx | 添加文字链接 |
.github/ISSUE_TEMPLATE/friend-request.yml | 新增 Issue 模板 |
功能特点:
- 不破坏原有布局
- 适配明暗主题
- 支持 GitHub Issue 自动表单
- 访客一键提交,方便管理
现在你的访友链页面更加完善了!🎉
支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!