同步插件源代码并补齐标准项目文件

This commit is contained in:
XIGE
2026-11-26 15:04:07 +08:00
parent 5118a6df75
commit 5b735af44f
8 changed files with 2689 additions and 0 deletions

29
.gitignore vendored Normal file
View File

@@ -0,0 +1,29 @@
# Dependencies and build output
node_modules/
vendor/
dist/
build/
out/
main.js
*.apk
# Build tools and IDE
.gradle/
.idea/
*.iml
gradle/
gradlew
gradlew.bat
# Environment and secrets
.env
.env.*
keystore.properties
*.jks
credentials*.json
# Runtime data and backups
data/
备份/
*.log
.DS_Store

48
CHANGELOG.md Normal file
View File

@@ -0,0 +1,48 @@
# ArticleToObsidian 更新日志
> 本文件记录本插件的所有修改与变化。本次整理(2026-11-22)为规范化记录起点。
## 插件信息
- 名称:ArticleToObsidian
- 版本:2.2.1
- 作者:三股水
- 说明:文章自动同步到七牛云(支持标题变更追踪 + 分类目录)
## 记录格式约定
每次修改按如下格式在**最上方**追加一条记录(新的在上):
```
## YYYY-MM-DD · 版本号 —— 一句话概述
- 改动点 1
- 改动点 2
- 影响范围 / 注意事项(若有)
- 对应备份:备份/YYYY-MM-DD-修改内容简短说明修改前/
```
## 2026-11-22 · 2.2.1 —— 修复 PHP 8.5 兼容:curl_close 废弃告警
- `Plugin.php`(同步上传函数收尾处):裸调用 `curl_close($ch)` 改为 `if (PHP_VERSION_ID < 80000)` 包裹
- 原因:`curl_close()` 自 PHP 8.0 起为空操作并标记废弃,PHP 8.5 下每次调用产生 E_DEPRECATED,污染 error_log / AJAX JSON 响应
- 影响范围:仅同步请求收尾逻辑,请求行为、返回值与功能完全不变
- 验证:PHP 8.3 / 8.0 `php -l` 通过
- 对应备份:`备份/2026-11-22-PHP85兼容修复修改前/`
---
## 2026-11-22 · 2.2.0 —— 统一作者与链接
- `Plugin.php` 头部 `@author` 统一为「石头厝」
- `@link` 统一为 `https://www.shitoucuo.com/`
- 影响范围:仅头部元信息,不涉及功能代码
- 对应备份:`备份/2026-11-22-统一作者和链接修改前/`
---
## 2026-11-22 · 2.2.0 —— 建立规范化备份与更新日志
- 建立 `备份/` 文件夹并生成本次整理前全量备份 `备份/2026-11-22-规范化整理修改前/`
- 创建本更新日志,作为后续所有修改的记录起点
- 说明:本次仅做规范化整理,未改动插件功能代码

19
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,19 @@
# 贡献指南
欢迎对本插件提出改进建议或提交代码。
## 提交前检查
- 仅提交插件实现代码、资源与必要文档,不提交依赖目录、编译产物、运行时数据或备份文件。
- 保持现有目录结构;如新增平台适配代码,请在 `README.md` 的目录结构中说明。
- 涉及对外服务或凭据的配置不要写入代码或文档。
## 提交流程
1. Fork 仓库并创建功能分支。
2. 完成修改后提交 Pull Request,说明改动目的与影响范围。
3. 重要功能变更请同步更新 `CHANGELOG.md`。
## 问题反馈
请通过仓库 Issue 反馈问题,并尽可能提供插件类型、版本与复现步骤。

92
ExportAction.php Normal file
View File

@@ -0,0 +1,92 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 单篇文章 Markdown 导出
*
* 路由:/action/article_to_obsidian_export?cid=1&_nonce=xxxxxxxx
* 由 ArticleToObsidian_Plugin::renderExportBtn() 生成链接,
* 直接返回 Content-Disposition: attachment,浏览器另存为 .md,不需要 JS。
*/
class ArticleToObsidian_ExportAction extends Typecho_Widget implements Widget_Interface_Do
{
public function action()
{
$this->export();
}
private function export()
{
$cid = (int) $this->request->get('cid');
$nonce = (string) $this->request->get('_nonce');
if ($cid <= 0 || !$this->nonceValid($cid, $nonce)) {
$this->fail('导出链接已失效,刷新文章页后重新点击即可。', 403);
}
$db = Typecho_Db::get();
$post = $db->fetchRow($db->select('cid', 'title', 'text', 'created', 'modified', 'slug', 'status')
->from('table.contents')
->where('cid = ?', $cid)
->where('type = ?', 'post')
->limit(1));
if (!$post) {
$this->fail('文章不存在。', 404);
}
if ($post['status'] !== 'publish') {
$this->fail('文章尚未发布,不能导出。', 403);
}
$markdown = ArticleToObsidian_Plugin::buildMarkdown($post);
$filename = ArticleToObsidian_Plugin::exportFilename($post['title'], $cid);
// 中文文件名:给老浏览器一个纯 ASCII 兜底名,再按 RFC 5987 补上真实文件名
$fallback = 'post-' . $cid . '.md';
$this->response->setStatus(200);
$this->response->setHeader(
'Content-Disposition',
'attachment; filename="' . $fallback . '"; filename*=UTF-8\'\'' . rawurlencode($filename)
);
$this->response->setHeader('X-Content-Type-Options', 'nosniff');
$this->response->setHeader('Cache-Control', 'private, max-age=0, must-revalidate');
$this->response->throwContent($markdown, 'text/markdown');
}
/**
* 校验串:当前小时或上一小时都算有效
*
* @param int $cid
* @param string $nonce
* @return bool
*/
private function nonceValid($cid, $nonce)
{
if ($nonce === '') {
return false;
}
$now = time();
foreach (array($now, $now - 3600) as $time) {
if (hash_equals(ArticleToObsidian_Plugin::exportNonce($cid, $time), $nonce)) {
return true;
}
}
return false;
}
/**
* @param string $message
* @param int $status
*/
private function fail($message, $status = 400)
{
// 状态码必须走 Response 对象:Typecho 最后会用它自己的 status 覆盖 header(),
// 直接 http_response_code() 是无效的(试过,永远 200)。
$this->response->setStatus($status);
$this->response->throwContent($message, 'text/plain');
}
}

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 三股水
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

1611
Plugin.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,2 +1,30 @@
# ArticleToObsidian
> 仓库:`ArticleToObsidian` · 类型:Typecho 插件 · 版本:`2.2.1` · 作者:三股水
文章自动同步到七牛云,支持标题变更追踪与分类目录。
本仓库同步自本地插件源码,**仅包含插件实现代码与必要资源**;不包含依赖、构建工具、编译产物、环境配置或备份数据。
## 目录结构
- `ExportAction.php`
- `Plugin.php`
- `manage.php`
## 安装与使用
1. 将本仓库目录复制到 Typecho 站点的 `usr/plugins/<仓库名>/`。
2. 在 Typecho 后台「插件」管理中启用并按站点配置。
## 开发与贡献
详见 [CONTRIBUTING.md](CONTRIBUTING.md)。
## 授权
授权条款见 [LICENSE](LICENSE)(MIT License)。第三方组件版权归各自作者所有。
## 变更记录
详见 [CHANGELOG.md](CHANGELOG.md)。

841
manage.php Normal file

File diff suppressed because it is too large Load Diff