Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SID="xxxxxxxxx"
SOURCE_PROJECT_NAME="xxxxxxxx"
DESTINATION_PROJECT_NAME="xxxxxxx"
# "Ttrue"にすると、デフォルトで複製するようになります。
# [private.icon]も[public.icon]も無いページを複製するかどうか
SHOULD_DUPLICATE_BY_DEFAULT="False"
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
name: ci

env:
DENO_VERSION: 2.x

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: denoland/setup-deno@v1
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: "1.18.2"
deno-version: ${{ env.DENO_VERSION }}
- name: Check fmt
run: deno fmt --check
- name: Run lint
run: deno lint
- name: Run type check
run: deno cache *.ts

21 changes: 12 additions & 9 deletions .github/workflows/duplicator.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
name: Duplicater

on:
workflow_dispatch:
schedule:
- cron: '0 21 * * *' # JST 6:00

env:
DENO_VERSION: 2.x
SID: ${{ secrets.SID }}
PROJECT_NAME: ${{ secrets.PROJECT_NAME }}
SOURCE_PROJECT_NAME: ${{ secrets.SOURCE_PROJECT_NAME }}
DESTINATION_PROJECT_NAME: ${{ secrets.DESTINATION_PROJECT_NAME }}
SHOULD_DUPLICATE_BY_DEFAULT: ${{ secrets.SHOULD_DUPLICATE_BY_DEFAULT }}

on:
workflow_dispatch:
schedule:
- cron: "0 21 * * *" # JST 6:00

jobs:
build:
permissions:
contents: 'write'
contents: "write"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@v1
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: ${{ env.DENO_VERSION }}

- name: Export from Scrapbox(/PROJECT_NAME to PROJECT_NAME.json)
run: deno run --allow-net=scrapbox.io --allow-read=./ --allow-write --allow-env index.ts
run: deno run --allow-net=scrapbox.io --allow-read=./ --allow-write --allow-env index.ts
13 changes: 8 additions & 5 deletions .github/workflows/udd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# from https://zenn.dev/kawarimidoll/articles/c68204d248c107#設定ファイル
name: update-deno-dependencies

env:
DENO_VERSION: 2.x

on:
schedule:
- cron: "0 0 * * *"
Expand All @@ -9,16 +12,16 @@ jobs:
udd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: denoland/setup-deno@v1
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: 1.21.0
deno-version: ${{ env.DENO_VERSION }}
- name: Update dependencies
run: >
deno run --allow-net --allow-read --allow-write=deps.ts
--allow-run=deno https://deno.land/x/udd@0.7.2/main.ts deps.ts
--allow-run=deno https://deno.land/x/udd@0.8.2/main.ts deps.ts
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v7
with:
commit-message: ":arrow_up: update deno dependencies"
title: Update Deno Dependencies
Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
},
"[jsonc]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,34 @@ Scrapboxの非公開・公開プロジェクトを分けて運用する際に面
2. Forkしたリポジトリに環境変数を設定する

<!-- 環境変数の設定イメージ -->

以下の画像は環境変数の設定方法を示しています。
[![Image from Gyazo](https://i.gyazo.com/cd8630a6fb125c6d7e627b290fbe79ce.png)](https://gyazo.com/cd8630a6fb125c6d7e627b290fbe79ce)

<!-- すぐに動作確認がしたい時は手動で起動できる -->

動作確認をすぐに行いたい場合は、以下の画像のように手動で起動することが可能です。
[![Image from Gyazo](https://i.gyazo.com/e4762cda8e8566bb75d20a429c2f1cb1.png)](https://gyazo.com/e4762cda8e8566bb75d20a429c2f1cb1)


## 必要なもの

1. `SID` ScrapboxのSID(詳しくは[こちら](https://scrapbox.io/nishio/Scrapbox%E3%81%AEprivate%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AEAPI%E3%82%92%E5%8F%A9%E3%81%8F))
1. `SID`
ScrapboxのSID(詳しくは[こちら](https://scrapbox.io/nishio/Scrapbox%E3%81%AEprivate%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AEAPI%E3%82%92%E5%8F%A9%E3%81%8F))
2. `SOURCE_PROJECT_NAME` 転送元のプロジェクト名
3. `DESTINATION_PROJECT_NAME` 転送先のプロジェクト名

## 注意事項

- まともにテストしていないので、**自己責任で使用してください**。使用前にプロジェクトのバックアップ取得をオススメします。
- SIDは漏れた場合にリセットする手段が無さそうなので、気をつけて扱ってください。サブアカウントのSID等を使用する事をオススメします。(詳しくは[こちら](https://scrapbox.io/nishio/Scrapbox%E3%81%AEprivate%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AEAPI%E3%82%92%E5%8F%A9%E3%81%8F))
- export APIは使用回数に制限があるので、定期実行は一日2~3回程度が良いと思います。
- export
APIは使用回数に制限があるので、定期実行は一日2~3回程度が良いと思います。

## その他

Scrapbox Duplicatorは定期実行のタイミングまで待たないと転送されません。好きなタイミングで公開したい場合は、[このUserScript](https://scrapbox.io/blu3mo-public/%E3%83%9A%E3%83%BC%E3%82%B8%E8%BB%A2%E9%80%81%E3%81%99%E3%82%8B%E6%8B%A1%E5%BC%B5script)を一緒に使う事をオススメします。
Scrapbox
Duplicatorは定期実行のタイミングまで待たないと転送されません。好きなタイミングで公開したい場合は、[このUserScript](https://scrapbox.io/blu3mo-public/%E3%83%9A%E3%83%BC%E3%82%B8%E8%BB%A2%E9%80%81%E3%81%99%E3%82%8B%E6%8B%A1%E5%BC%B5script)を一緒に使う事をオススメします。

## 謝辞

Scrapboxを開発しているNota, Inc. の皆さんに感謝します。
Scrapboxを開発しているNota, Inc. の皆さんに感謝します。
9 changes: 9 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"imports": {
"@core/unknownutil": "jsr:@core/unknownutil@^4.0.0",
"@cosense/types/rest": "jsr:@cosense/types@0.10/rest",
"@std/encoding": "jsr:@std/encoding@1",
"@takker/md5": "jsr:@takker/md5@0.1",
"option-t": "npm:option-t@^51.0.0"
}
}
97 changes: 97 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import 'https://deno.land/x/dotenv@v3.2.0/load.ts';
export { assertString } from 'https://deno.land/x/unknownutil@v2.0.0/mod.ts';
export * from 'https://raw.githubusercontent.com/takker99/scrapbox-userscript-std/0.14.1/rest/page-data.ts';
export { ensure } from "@core/unknownutil/ensure";
export { isString } from "@core/unknownutil/is/string";
export * from "https://raw.githubusercontent.com/takker99/scrapbox-userscript-std/0.29.16/rest/page-data.ts";
44 changes: 25 additions & 19 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
import { assertString, exportPages, importPages } from "./deps.ts";
import type { ExportedData } from "@cosense/types/rest";
import { ensure, exportPages, importPages, isString } from "./deps.ts";

const sid = Deno.env.get("SID");
const exportingProjectName = Deno.env.get("SOURCE_PROJECT_NAME"); //インポート元(本来はprivateプロジェクト)
const importingProjectName = Deno.env.get("DESTINATION_PROJECT_NAME"); //インポート先(publicプロジェクト)
const sid = ensure(Deno.env.get("SID"), isString);
// インポート元 (privateプロジェクト)
const exportingProjectName = ensure(
Deno.env.get("SOURCE_PROJECT_NAME"),
isString,
);
// インポート先 (publicプロジェクト)
const importingProjectName = ensure(
Deno.env.get("DESTINATION_PROJECT_NAME"),
isString,
);
// [private.icon] も [public.icon] も無いページを複製するかどうか
const shouldDuplicateByDefault =
Deno.env.get("SHOULD_DUPLICATE_BY_DEFAULT") === "True";

assertString(sid);
assertString(exportingProjectName);
assertString(importingProjectName);

console.log(`Exporting a json file from "/${exportingProjectName}"...`);
const result = await exportPages(exportingProjectName, {
sid,
metadata: true,
});
if (!result.ok) {
const error = new Error();
error.name = `${result.value.name} when exporting a json file`;
error.message = result.value.message;
error.name = `${result.err.name} when exporting a json file`;
error.message = result.err.message;
throw error;
}
const { pages } = result.value;
const { pages } = result.val as ExportedData<true>;
console.log(`Export ${pages.length}pages:`);
for (const page of pages) {
console.log(`\t${page.title}`);
Expand All @@ -43,16 +49,16 @@ if (importingPages.length === 0) {
console.log(
`Importing ${importingPages.length} pages to "/${importingProjectName}"...`,
);
const result = await importPages(importingProjectName, {
pages: importingPages,
}, {
sid,
});
const result = await importPages(
importingProjectName,
{ pages: importingPages },
{ sid },
);
if (!result.ok) {
const error = new Error();
error.name = `${result.value.name} when importing pages`;
error.message = result.value.message;
error.name = `${result.err.name} when importing pages`;
error.message = result.err.message;
throw error;
}
console.log(result.value);
console.log(result.val);
}