Skip to content

Commit

Permalink
feat: 迁移图片功能支持开关 #2
Browse files Browse the repository at this point in the history
- 完善使用说明文档
  • Loading branch information
mohuishou committed Oct 28, 2022
1 parent 1af8d60 commit dd7fcd7
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 18 deletions.
26 changes: 20 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,34 @@ description: |
支持自动将图片迁移到 aliyun oss
inputs:
token: # id of input
description: 'notion api token'
description: notion app token,建议最好放到 Action Secret 中
required: true
database_id:
required: true
description: |
notion 中的数据库 id
- 假设你的数据库页面链接是 `https://www.notion.so/you-name/0f3d856498ca4db3b457c5b4eeaxxxxx`
- 那么 `database_id=0f3d856498ca4db3b457c5b4eeaxxxxx`
status_name:
description: 'notion page prop status name'
description: notion database 状态字段的字段名,支持自定义
default: "status"
status_published:
description: 'notion page prop published status value'
description: notion database 文章已发布状态的字段值
default: "已发布"
status_unpublish:
description: 'notion page prop unpublish status value'
description: |
notion database 文章待发布状态的字段值
触发 action 后会自动拉去所有该状态的文章,成功导出之后会把这篇文章的状态修改为上面设置的已发布状态
default: "待发布"
migrate_image:
description: |
是否迁移图片到 aliyun oss
注意: 如果不迁移图片默认导出图片链接是 notion 的自带链接,有访问时效
目前支持迁移图片到 aliyun oss 中
default: "true"
output:
required: false
description: 输出的文件夹路径
access_key_id:
description: aliyun access_key_id
required: true
Expand All @@ -32,8 +47,7 @@ inputs:
default: oss-cn-hangzhou
prefix:
description: "file dir, e.g. image/"
output:
required: false

runs:
using: 'node16'
main: 'dist/index.js'
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216519,6 +216519,7 @@ const { format } = __nccwpck_require__(89653);
let config = {
notion_secret: "",
database_id: "",
migrate_image: true,
aliyun: {
accessKeyId: "",
accessKeySecret: "",
Expand Down Expand Up @@ -216570,7 +216571,7 @@ async function sync() {

console.log(`[${i + 1}]: ${page.properties.title.title[0].plain_text}`);
let file = await download(page);
await migrateImages(file);
if(config.migrate_image) await migrateImages(file);
published(page);
}
if (pages.length == 0)
Expand Down Expand Up @@ -230640,6 +230641,7 @@ const core = __nccwpck_require__(95127);
let config = {
notion_secret: core.getInput("notion_secret"),
database_id: core.getInput("database_id"),
migrate_image: core.getInput("migrate_image") === "true",
aliyun: {
accessKeyId: core.getInput("access_key_id"),
accessKeySecret: core.getInput("access_key_secret"),
Expand Down
Binary file added docs/app-sec.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/database_tpl.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 59 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,69 @@
- 使用 notion 导出接口,支持图片、表格、callout 等格式
- 支持迁移图片到置顶文件夹

## 说明
## 使用说明

database template: https://mohuishou.notion.site/3999b0ae72364a4b99a87f7d9d0a52be?v=1df90fd8110541679dc48866b80031ee
### Notion

### notion
- 使用 [database 模板](https://mohuishou.notion.site/3999b0ae72364a4b99a87f7d9d0a52be?v=1df90fd8110541679dc48866b80031ee) 创建一个数据库
![](docs/database_tpl.jpg)
- 参考 [Notion 官方教程](https://developers.notion.com/docs/getting-started#step-1-create-an-integration) 创建一个应用,并获取到 token
![](./docs/app-sec.jpg)
- 将之前创建好的页面分享给刚刚创建的应用,[教程](https://developers.notion.com/docs/getting-started#step-2-share-a-database-with-your-integration)

通过 notion 导出 markdown 文件 api 下载 md 文件
### Github Action

### migrate
#### 参数说明

使用 notion-to-md 导出 markdown 文件,并且支持了 `callout`,以及 front matter
迁移导出 md 文件中的图片资源到指定文件夹,支持属性字段含有图片的情况

## 使用示例
```yaml
inputs:
token: # id of input
description: notion app token,建议最好放到 Action Secret 中
required: true
database_id:
required: true
description: |
notion 中的数据库 id
- 假设你的数据库页面链接是 `https://www.notion.so/you-name/0f3d856498ca4db3b457c5b4eeaxxxxx`
- 那么 `database_id=0f3d856498ca4db3b457c5b4eeaxxxxx`
status_name:
description: notion database 状态字段的字段名,支持自定义
default: "status"
status_published:
description: notion database 文章已发布状态的字段值
default: "已发布"
status_unpublish:
description: |
notion database 文章待发布状态的字段值
触发 action 后会自动拉去所有该状态的文章,成功导出之后会把这篇文章的状态修改为上面设置的已发布状态
default: "待发布"
migrate_image:
description: |
是否迁移图片到 aliyun oss
注意: 如果不迁移图片默认导出图片链接是 notion 的自带链接,有访问时效
目前支持迁移图片到 aliyun oss 中
default: "true"
output:
required: false
description: 输出的文件夹路径
access_key_id:
description: aliyun access_key_id
required: true
access_key_secret:
description: aliyun access_key_secret
required: true
bucket:
description: aliyun bucket
required: true
area:
description: "aliyun area: oss-cn-hangzhou"
required: true
default: oss-cn-hangzhou
prefix:
description: "file dir, e.g. image/"
```
#### 配置示例
```yaml
on: [repository_dispatch, watch]
Expand Down Expand Up @@ -48,7 +97,7 @@ jobs:
run: |
git config --global user.email "[email protected]"
git config --global user.name "mohuishou"
- name: update blog
run: |
git add source
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const core = require("@actions/core");
let config = {
notion_secret: core.getInput("notion_secret"),
database_id: core.getInput("database_id"),
migrate_image: core.getInput("migrate_image") === "true",
aliyun: {
accessKeyId: core.getInput("access_key_id"),
accessKeySecret: core.getInput("access_key_secret"),
Expand Down
3 changes: 2 additions & 1 deletion src/notion.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { format } = require("prettier");
let config = {
notion_secret: "",
database_id: "",
migrate_image: true,
aliyun: {
accessKeyId: "",
accessKeySecret: "",
Expand Down Expand Up @@ -64,7 +65,7 @@ async function sync() {

console.log(`[${i + 1}]: ${page.properties.title.title[0].plain_text}`);
let file = await download(page);
await migrateImages(file);
if(config.migrate_image) await migrateImages(file);
published(page);
}
if (pages.length == 0)
Expand Down

0 comments on commit dd7fcd7

Please sign in to comment.