From d9f9595e72c5f0dd7fb935236b0152d612d65040 Mon Sep 17 00:00:00 2001 From: "Yangkai.Shen" <237497819@qq.com> Date: Tue, 20 Jan 2026 15:42:35 +0800 Subject: [PATCH 1/6] fix: address Copilot review suggestions for PR #28 - Add avif MIME type support in RSS feed - Add comment explaining enclosure length: 0 rationale - Add width/height attributes to Card thumbnail to prevent CLS Co-Authored-By: Claude Opus 4.5 --- src/components/Card.astro | 2 ++ src/pages/rss.xml.ts | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Card.astro b/src/components/Card.astro index 35f0af99..a08b1a81 100644 --- a/src/components/Card.astro +++ b/src/components/Card.astro @@ -97,6 +97,8 @@ const excerpt = description || (body ? getExcerpt(body) : ""); {title} Date: Tue, 20 Jan 2026 16:15:39 +0800 Subject: [PATCH 2/6] feat: add view source link and CC license declaration - Add viewSource config for raw markdown link (GitHub raw URL) - Add license config for CC BY-NC-SA 4.0 declaration - Create ViewSource.astro component with GitHub icon - Create License.astro component with official CC badge and post URL - Integrate components into PostDetails layout - Simplify BackToTopButton and move to TOC sidebar - Add tech stack info to Footer (Astro & AstroPaper) - Remove ShareLinks from post details - Update TableOfContents to support slot for BackToTopButton Co-Authored-By: Claude Opus 4.5 --- .../add-source-link-and-license/proposal.md | 23 +++++++ .../specs/post-details/spec.md | 63 +++++++++++++++++++ .../add-source-link-and-license/tasks.md | 28 +++++++++ src/components/BackToTopButton.astro | 46 +++----------- src/components/Footer.astro | 27 +++++++- src/components/License.astro | 62 ++++++++++++++++++ src/components/TableOfContents.astro | 1 + src/components/ViewSource.astro | 32 ++++++++++ src/config.ts | 10 +++ src/layouts/PostDetails.astro | 36 ++++++++--- 10 files changed, 280 insertions(+), 48 deletions(-) create mode 100644 openspec/changes/add-source-link-and-license/proposal.md create mode 100644 openspec/changes/add-source-link-and-license/specs/post-details/spec.md create mode 100644 openspec/changes/add-source-link-and-license/tasks.md create mode 100644 src/components/License.astro create mode 100644 src/components/ViewSource.astro diff --git a/openspec/changes/add-source-link-and-license/proposal.md b/openspec/changes/add-source-link-and-license/proposal.md new file mode 100644 index 00000000..6fd4ca9f --- /dev/null +++ b/openspec/changes/add-source-link-and-license/proposal.md @@ -0,0 +1,23 @@ +# Change: 新增查看原文链接和 CC 协议声明 + +## Why + +当前博客文章页面只有"编辑"链接(指向 GitHub edit 页面),缺少以下功能: +1. 读者无法快速查看文章的 Markdown 原始内容(source 模式) +2. 没有明确的版权协议声明,不利于内容保护和合规转载 + +## What Changes + +- 新增"查看原文"链接组件,跳转到 GitHub 仓库文件的 blob 页面(只读模式) +- 新增 CC BY-NC-SA 4.0 协议声明组件,显示在文章正文下方 +- 在 `config.ts` 中添加相关配置项(协议类型、仓库 URL 等) +- 修改 `PostDetails.astro` 布局,集成新组件 + +## Impact + +- Affected code: + - `src/config.ts` - 新增配置项 + - `src/components/ViewSource.astro` - 新建组件 + - `src/components/License.astro` - 新建组件 + - `src/layouts/PostDetails.astro` - 集成新组件 + - `src/assets/icons/` - 可能需要新增图标 diff --git a/openspec/changes/add-source-link-and-license/specs/post-details/spec.md b/openspec/changes/add-source-link-and-license/specs/post-details/spec.md new file mode 100644 index 00000000..8a04d8c9 --- /dev/null +++ b/openspec/changes/add-source-link-and-license/specs/post-details/spec.md @@ -0,0 +1,63 @@ +## ADDED Requirements + +### Requirement: View Source Link + +The system SHALL provide a "View Source" link on article detail pages that opens the raw Markdown file in the GitHub repository (blob view, not edit mode). + +#### Scenario: User clicks View Source link + +- **WHEN** user clicks the "View Source" link on an article page +- **THEN** a new tab opens with the GitHub blob URL for the article's Markdown file +- **AND** the URL format is `https://github.com/{owner}/{repo}/blob/{branch}/{filePath}` + +#### Scenario: View Source link visibility + +- **WHEN** `SITE.viewSource.enabled` is `true` +- **THEN** the View Source link is displayed on the article page +- **WHEN** `SITE.viewSource.enabled` is `false` +- **THEN** the View Source link is hidden + +### Requirement: CC License Declaration + +The system SHALL display a Creative Commons license declaration (CC BY-NC-SA 4.0) at the bottom of each article's content area. + +#### Scenario: License display position + +- **WHEN** an article page is rendered +- **THEN** the CC license declaration appears after the article content +- **AND** before the share links section + +#### Scenario: License content elements + +- **WHEN** the license component is rendered +- **THEN** it displays: + - The CC BY-NC-SA 4.0 license icon/badge + - A brief license description in Chinese + - A link to the full license text on Creative Commons website + +#### Scenario: License visibility control + +- **WHEN** `SITE.license.enabled` is `true` +- **THEN** the license declaration is displayed +- **WHEN** `SITE.license.enabled` is `false` +- **THEN** the license declaration is hidden + +### Requirement: Configuration Options + +The system SHALL provide configuration options in `src/config.ts` for View Source and License features. + +#### Scenario: viewSource configuration + +- **WHEN** configuring the View Source feature +- **THEN** the following options are available: + - `enabled`: boolean to show/hide the link + - `text`: display text for the link (default: "查看原文") + - `url`: base URL for the repository blob path + +#### Scenario: license configuration + +- **WHEN** configuring the License feature +- **THEN** the following options are available: + - `enabled`: boolean to show/hide the license + - `type`: license type identifier (e.g., "CC BY-NC-SA 4.0") + - `url`: URL to the full license text diff --git a/openspec/changes/add-source-link-and-license/tasks.md b/openspec/changes/add-source-link-and-license/tasks.md new file mode 100644 index 00000000..e135bedb --- /dev/null +++ b/openspec/changes/add-source-link-and-license/tasks.md @@ -0,0 +1,28 @@ +## 1. 配置扩展 + +- [x] 1.1 在 `src/config.ts` 中添加 `viewSource` 配置项(enabled、text、url) +- [x] 1.2 在 `src/config.ts` 中添加 `license` 配置项(enabled、type、url) + +## 2. 组件开发 + +- [x] 2.1 创建 `src/components/ViewSource.astro` 组件 + - 接收 `post` 参数,生成 raw URL + - 使用 GitHub 图标 + - 样式与 EditPost 保持一致 +- [x] 2.2 创建 `src/components/License.astro` 组件 + - 显示 CC BY-NC-SA 4.0 协议信息 + - 包含协议图标和链接 + - 简洁的版权声明文案 + +## 3. 布局集成 + +- [x] 3.1 修改 `src/layouts/PostDetails.astro` + - 在文章正文后、分享链接前添加 License 组件 + - 在元信息区添加 ViewSource 链接 +- [x] 3.2 确保移动端和桌面端响应式显示正常 + +## 4. 验证 + +- [x] 4.1 本地构建测试,确保无类型错误 +- [x] 4.2 验证链接跳转正确(raw 页面) +- [x] 4.3 检查暗色/亮色模式下样式正常 diff --git a/src/components/BackToTopButton.astro b/src/components/BackToTopButton.astro index 0b1e654a..cc2a466f 100644 --- a/src/components/BackToTopButton.astro +++ b/src/components/BackToTopButton.astro @@ -1,74 +1,44 @@ --- -import IconChevronLeft from "@/assets/icons/IconChevronLeft.svg"; import IconArrowNarrowUp from "@/assets/icons/IconArrowNarrowUp.svg"; ---