@cosense-toolbox/astro 0.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +301 -0
- package/dist/index.d.mts +117 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +581 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server.d.mts +22 -0
- package/dist/server.d.mts.map +1 -0
- package/dist/server.mjs +49 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 qaynam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# @cosense-toolbox/astro
|
|
2
|
+
|
|
3
|
+
Cosense (旧 Scrapbox) の記法で書いた `.csn` / `.csnx` を、Astro のページと content collection で使うための統合。
|
|
4
|
+
中身は [`@cosense-toolbox/cosense-x`](../cosense-x) のコンパイラ。
|
|
5
|
+
|
|
6
|
+
> **beta**:公開 API はまだ変わりうる。
|
|
7
|
+
|
|
8
|
+
動く例は [`examples/astro-blog`](../../examples/astro-blog) にある。
|
|
9
|
+
|
|
10
|
+
## 設定
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
// astro.config.mjs
|
|
14
|
+
import svelte from "@astrojs/svelte"
|
|
15
|
+
import cosense from "@cosense-toolbox/astro"
|
|
16
|
+
import { defineConfig } from "astro/config"
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
integrations: [
|
|
20
|
+
svelte(),
|
|
21
|
+
cosense({
|
|
22
|
+
components: "./src/components/cosense.ts",
|
|
23
|
+
pageUrl: (page) => `/posts/${encodeURIComponent(page.slug)}/`,
|
|
24
|
+
tagUrl: (tag) => `/tags/${encodeURIComponent(tag)}/`,
|
|
25
|
+
lint: { unresolvedLinks: "error" },
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| オプション | 内容 |
|
|
32
|
+
| :-------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `components` | すべてのページに渡すコンポーネントを default export するモジュールの、プロジェクトのルートからのパス |
|
|
34
|
+
| `pageUrl` | リンク先のページの URL。`{ id, title, slug }` を受け取る。`id` はプロジェクトのルートからのパス |
|
|
35
|
+
| `tagUrl` `projectUrl` | `compile` の同名のオプションと同じ |
|
|
36
|
+
| `unresolvedLinks` | サイトに無いページへのリンクの出し方。`'text'` (既定) はテキスト、`'link'` はタイトルから作った URL へのリンクにする |
|
|
37
|
+
| `lint` | ビルドの前にリンク切れを調べる。`{ unresolvedLinks?, frontmatter? }`。省略すると調べない。[下を参照](#リンク切れを調べる) |
|
|
38
|
+
| `parseOptions` | パースの設定。parser の `parse` のオプション (`extensions` など) がそのまま渡る |
|
|
39
|
+
| `renderOptions` | 描画の設定。parser の `toHast` のオプション (`extensions` `handlers` `classNames` `showPads` `iconImageUrl`) と `title` がそのまま渡る。色付けは `syntaxHighlight` で決める |
|
|
40
|
+
| `rehypePlugins` | `compile` の同名のオプションと同じ |
|
|
41
|
+
| `syntaxHighlight` | コードブロックの色付け。既定の `'astro'` は `markdown.shikiConfig` に従う。`false` で無効、関数で自前の色付け。[下を参照](#コードブロックの色付け) |
|
|
42
|
+
| `assets` | Cosense 上の画像とファイルを、ビルド時に取ってきてサイトの中に置く。`{ pat?, origin?, links? }`、または `false` で無効。既定は有効 |
|
|
43
|
+
|
|
44
|
+
## リンク切れを調べる
|
|
45
|
+
|
|
46
|
+
`lint` を渡すと、ビルドの前と、開発サーバーの起動時・ページを変えたときに、`srcDir` の下の `.csn` / `.csnx` を読み、サイトに無いページへの `[リンク]` を調べる。開発中は `'error'` でも止めず、ログに出すだけにする。
|
|
47
|
+
判定はエディタの診断 ([`@cosense-toolbox/lsp`](../lsp)) と `csn-lsp check` と同じ関数で、パースにはこの統合の
|
|
48
|
+
`parseOptions` を使う。エディタで警告されるものと、ビルドで止まるものが一致する。
|
|
49
|
+
|
|
50
|
+
| `lint` のオプション | 内容 | 既定 |
|
|
51
|
+
| :------------------ | :--------------------------------------------------------------------------------------------------------------- | :---------- |
|
|
52
|
+
| `unresolvedLinks` | `'off'` / `'hint'` / `'information'` / `'warning'` / `'error'`。`'error'` ならビルドを止め、それ以外はログに出す | `'warning'` |
|
|
53
|
+
| `frontmatter` | 1 行目の `---` を frontmatter (YAML) として飛ばすか | `true` |
|
|
54
|
+
|
|
55
|
+
ページの題名はファイルの 1 行目で、大文字小文字と、空白と `_` の違いは無視して比べる。`#タグ` と
|
|
56
|
+
`[/別プロジェクト/ページ]` は調べない。
|
|
57
|
+
|
|
58
|
+
## Cosense 上の画像とファイル
|
|
59
|
+
|
|
60
|
+
Cosense にアップロードした画像やファイル (`https://scrapbox.io/files/…`) とアイコン (`/api/pages/…/icon`) は、ビルド時に取ってきて `{base}/_cosense/` に置き、HTML の URL をそこに差し替える。
|
|
61
|
+
|
|
62
|
+
- これらのファイルは別のサイトの `<img>` からは読めない (`Cross-Origin-Resource-Policy: same-origin`)
|
|
63
|
+
- リダイレクト先の URL は数分で切れる
|
|
64
|
+
- そのため、静的なサイトで表示するにはサイトの中に置くしかない
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
cosense({
|
|
68
|
+
// 非公開プロジェクトの画像を取るときは PAT を渡す。Cosense への要求にだけ付ける
|
|
69
|
+
assets: { pat: process.env.COSENSE_PAT },
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- `.csn` / `.csnx` の中の画像は自動で差し替える
|
|
74
|
+
- ファイル名は `{元の URL のハッシュ}.{拡張子}`。アイコンは `{ハッシュ}_{ユーザー名}.{拡張子}`
|
|
75
|
+
- 同じ URL は何度ビルドしても同じ名前になる
|
|
76
|
+
- ハッシュから元の URL は分からないので、非公開プロジェクトのファイル ID は出ない
|
|
77
|
+
- 取ってきたファイルは Astro のキャッシュのディレクトリに残す
|
|
78
|
+
- アップロードしたファイルは中身が変わらないので、次のビルドでは取り直さない
|
|
79
|
+
- アイコンは差し替えられることがあるので、ビルドのたびに取り直す
|
|
80
|
+
- 出力先には、そのビルドで使ったファイルだけを写す
|
|
81
|
+
- 取れなかったファイルは警告を出し、元の URL のまま出す
|
|
82
|
+
- dev サーバーでは、同じパスで配信する
|
|
83
|
+
- **非公開プロジェクトの画像も、公開するサイトに置かれる**。公開してよいものだけを書くこと
|
|
84
|
+
|
|
85
|
+
リンクした Cosense のファイル (`[https://scrapbox.io/files/x.zip]` など、`<a href>` になるもの) は、既定では元の URL のまま出す。
|
|
86
|
+
公開プロジェクトならクリックして開ける (Cross-Origin-Resource-Policy は画面の遷移には効かない)。
|
|
87
|
+
非公開プロジェクトのファイルは見に来た人が開けないので、`links: 'download'` で画像と同じくサイトに置く。
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
cosense({
|
|
91
|
+
assets: { pat: process.env.COSENSE_PAT, links: "download" },
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`toHtml` などで自分で描画するページは、`virtual:cosense-x/assets` の `localizeCosenseAssets` に HTML を通す。
|
|
96
|
+
アイコンの URL は `cosenseIconUrl` で作る。
|
|
97
|
+
|
|
98
|
+
```astro
|
|
99
|
+
---
|
|
100
|
+
import { cosenseIconUrl, fetchPageText } from "@cosense-toolbox/cosense-x/fetch"
|
|
101
|
+
import { parse } from "@cosense-toolbox/parser"
|
|
102
|
+
import { toHtml } from "@cosense-toolbox/parser/html"
|
|
103
|
+
import { localizeCosenseAssets } from "virtual:cosense-x/assets"
|
|
104
|
+
|
|
105
|
+
const project = "help-jp"
|
|
106
|
+
const text = await fetchPageText(project, "ブラケティング")
|
|
107
|
+
const html = await localizeCosenseAssets(
|
|
108
|
+
toHtml(parse(text), { iconImageUrl: (icon) => cosenseIconUrl(project, icon.user) }),
|
|
109
|
+
)
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
<article class="cosense" set:html={html} />
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
差し替えられるのは、ページをビルド時に描画するとき (静的なページと prerender) と dev サーバーだけ。実行時に描画する SSR では元の URL のまま返す。
|
|
116
|
+
|
|
117
|
+
## コードブロックの色付け
|
|
118
|
+
|
|
119
|
+
`.csn` / `.csnx` のコードブロック (`code:hello.js`) は、`.md` / `.mdx` と同じく Astro の `markdown.syntaxHighlight` と `markdown.shikiConfig` の設定で shiki が色付けする。
|
|
120
|
+
`components` に登録しなくてよい。
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
export default defineConfig({
|
|
124
|
+
markdown: { shikiConfig: { theme: "github-light" } },
|
|
125
|
+
integrations: [cosense()],
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- 言語はファイル名の拡張子から決める。`code:hello.js` なら `js`、`code:python` なら `python`
|
|
130
|
+
- shiki が知らない言語と `excludeLangs` の言語は、色付けせずに出す
|
|
131
|
+
- `theme` / `themes` / `defaultColor` / `langs` / `langAlias` / `transformers` を使う。`wrap` は使わない。長い行は `@cosense-toolbox/style` が折り返す
|
|
132
|
+
- `markdown.syntaxHighlight` が `'prism'` のときは色付けしない (相当するものが無い)
|
|
133
|
+
|
|
134
|
+
`syntaxHighlight: false` で色付けをやめる。関数を渡すと、shiki の代わりにそれで色付けする。形は `compile` の `renderOptions.highlight` と同じ。
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
cosense({
|
|
138
|
+
syntaxHighlight: (code, language) => myHighlighter(code, language), // hast か null を返す
|
|
139
|
+
})
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`toHtml` で自分で描画するページは、`toHtml` の `highlight` に shiki を直接渡す。
|
|
143
|
+
テーマなどの設定を 1 つのファイルにまとめ、`astro.config.mjs` とページの両方から読むと、`.md` / `.csn` と見た目が揃う。
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
// src/shiki.ts
|
|
147
|
+
import type { HastHighlighter } from "@cosense-toolbox/parser/html"
|
|
148
|
+
import type { ShikiConfig } from "astro"
|
|
149
|
+
import { createHighlighter } from "shiki"
|
|
150
|
+
|
|
151
|
+
export const shikiConfig = { theme: "github-light" } satisfies Partial<ShikiConfig>
|
|
152
|
+
|
|
153
|
+
/** toHtml は highlight を同期で呼ぶので、使う言語は先に読み込んでおく */
|
|
154
|
+
export const createCodeHighlight = async (langs: string[]): Promise<HastHighlighter> => {
|
|
155
|
+
const shiki = await createHighlighter({ themes: [shikiConfig.theme], langs })
|
|
156
|
+
// shiki の hast はそのまま返してよい。<pre><code> は剥がされ、テーマの色はコードブロックに移る
|
|
157
|
+
return (code, lang) =>
|
|
158
|
+
shiki.getLoadedLanguages().includes(lang)
|
|
159
|
+
? shiki.codeToHast(code, { lang, theme: shikiConfig.theme })
|
|
160
|
+
: null // 読み込んでいない言語は色付けしない
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
// astro.config.mjs
|
|
166
|
+
import { shikiConfig } from "./src/shiki.ts"
|
|
167
|
+
|
|
168
|
+
export default defineConfig({
|
|
169
|
+
markdown: { shikiConfig },
|
|
170
|
+
integrations: [cosense()],
|
|
171
|
+
})
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```astro
|
|
175
|
+
---
|
|
176
|
+
import { parse } from "@cosense-toolbox/parser"
|
|
177
|
+
import { toHtml } from "@cosense-toolbox/parser/html"
|
|
178
|
+
import { createCodeHighlight } from "../shiki"
|
|
179
|
+
|
|
180
|
+
const highlight = await createCodeHighlight(["js", "ts"])
|
|
181
|
+
const html = toHtml(parse(text), { highlight })
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
<article class="cosense" set:html={html} />
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 行番号
|
|
188
|
+
|
|
189
|
+
`@cosense-toolbox/parser/html` の `codeLineNumbers()` を描画の拡張 (`renderOptions.extensions`) に渡すと、コードブロックの本体行に行番号 (`data-line`) が付く。
|
|
190
|
+
番号の表示は `@cosense-toolbox/style` と `@cosense-toolbox/tailwind` が持っていて、行の左の余白に出す。本文の位置は変わらず、コピーしたときに番号は入らない。
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
// astro.config.mjs
|
|
194
|
+
import { codeLineNumbers } from "@cosense-toolbox/parser/html"
|
|
195
|
+
|
|
196
|
+
cosense({ renderOptions: { extensions: [codeLineNumbers()] } })
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`toHtml` で描画するページは、`toHtml(page, { extensions: [codeLineNumbers()] })` のように渡す。
|
|
200
|
+
|
|
201
|
+
- 番号の色は `--cosense-line-number` で変えられる
|
|
202
|
+
- エディタと同じく、本文の左に番号の欄を取る。欄の幅はブロックの最後の番号の桁数で決まり、同じブロックの行はそろう
|
|
203
|
+
- shiki で色付けしたブロックも、色付けしないブロックと同じく 1 行ずつの要素になるので番号が付く
|
|
204
|
+
- 行をまたぐ出力を返すハイライタ (highlight.js など) でひと塊になったブロックには付かない
|
|
205
|
+
|
|
206
|
+
### テーブルのセル
|
|
207
|
+
|
|
208
|
+
セルの中は Cosense Web と同じく、リンクの記法だけを読む。行と同じく記法を読みたいときはパースの拡張 `tableCellNotation()` を、セルの中の `\n` のような文字の並びを改行にしたいときは描画の拡張 `tableCellLineBreaks()` を渡す。
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
// astro.config.mjs
|
|
212
|
+
import { tableCellLineBreaks } from "@cosense-toolbox/parser/html"
|
|
213
|
+
import { tableCellNotation } from "@cosense-toolbox/parser/extensions"
|
|
214
|
+
|
|
215
|
+
cosense({
|
|
216
|
+
parseOptions: { extensions: [tableCellNotation()] },
|
|
217
|
+
renderOptions: { extensions: [tableCellLineBreaks("\\n")] },
|
|
218
|
+
})
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## content collection
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
// src/content.config.ts
|
|
225
|
+
import { defineCollection } from "astro:content"
|
|
226
|
+
import { glob } from "astro/loaders"
|
|
227
|
+
|
|
228
|
+
const posts = defineCollection({
|
|
229
|
+
loader: glob({ pattern: "**/*.{csn,csnx}", base: "./src/content/posts" }),
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
export const collections = { posts }
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
`data` には frontmatter に加えて `title` / `slug` / `description` / `image` / `tags` / `draft` が入る。
|
|
236
|
+
Cosense では 1 行目がタイトルなので、frontmatter に書かなくても `title` がある。
|
|
237
|
+
`slug` が entry の id になる。
|
|
238
|
+
|
|
239
|
+
```astro
|
|
240
|
+
---
|
|
241
|
+
import { render } from "astro:content"
|
|
242
|
+
const { Content } = await render(post)
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
<Content />
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## ページ
|
|
249
|
+
|
|
250
|
+
`src/pages` に `.csn` / `.csnx` を置くと、そのままページになる。
|
|
251
|
+
frontmatter の `layout` にレイアウトの `.astro` を指定すると、本文をその default のスロットに入れる。
|
|
252
|
+
レイアウトには `frontmatter` と `metadata` が props で渡る。
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
---
|
|
256
|
+
layout: ../layouts/Page.astro
|
|
257
|
+
---
|
|
258
|
+
このサイトについて
|
|
259
|
+
本文
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## リンクグラフ
|
|
263
|
+
|
|
264
|
+
`virtual:cosense-x/graph` から、`src` の下のすべての `.csn` / `.csnx` のリンクグラフを読める。
|
|
265
|
+
グラフの id は、content collection の entry の `filePath` と同じ形 (プロジェクトのルートからのパス)。
|
|
266
|
+
|
|
267
|
+
```astro
|
|
268
|
+
---
|
|
269
|
+
import graph from "virtual:cosense-x/graph"
|
|
270
|
+
const backlinks = graph.backlinks[post.filePath]
|
|
271
|
+
const twoHop = graph.twoHop[post.filePath]
|
|
272
|
+
---
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## コンポーネント
|
|
276
|
+
|
|
277
|
+
`.csnx` の `<Name />` の行には、`components` に指定したモジュールか、`<Content components={...} />` で渡したものが使われる。
|
|
278
|
+
Astro の中で描画されるので、Svelte などのコンポーネントも渡せる。
|
|
279
|
+
|
|
280
|
+
ブラウザで動かすための `client:*` ディレクティブは `.astro` の中でしか付けられない。
|
|
281
|
+
`.astro` のコンポーネントで包んでから渡す。
|
|
282
|
+
|
|
283
|
+
```astro
|
|
284
|
+
---
|
|
285
|
+
// CounterIsland.astro
|
|
286
|
+
import Counter from "./Counter.svelte"
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
<Counter client:load {...Astro.props} />
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## 仕組み
|
|
293
|
+
|
|
294
|
+
- `.csn` / `.csnx` を Vite のプラグインで JS にする。`jsxImportSource` は `astro`
|
|
295
|
+
- リンクの解決には全ページのタイトルが要る。そのため、ビルドの最初に `src` の下を全部読んで索引を作る。dev サーバーでは、どれか 1 ページが変わると索引を作り直して再読み込みする
|
|
296
|
+
- 描画には `astro:jsx` レンダラを使う。`@astrojs/mdx` と同じものなので、両方入れてもぶつからない
|
|
297
|
+
- ページの拡張子と content collection の形式の登録には、`@astrojs/mdx` も使っている Astro の非公開のフック (`addPageExtension` / `addContentEntryType`) を使っている。Astro の更新で動かなくなる可能性がある
|
|
298
|
+
|
|
299
|
+
## ライセンス
|
|
300
|
+
|
|
301
|
+
MIT。
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Graph, GraphPage, TwoHopGroup } from "@cosense-toolbox/cosense-x/graph";
|
|
2
|
+
import { Effect, Option } from "effect";
|
|
3
|
+
import "@cosense-toolbox/cosense-x/fetch";
|
|
4
|
+
import { CheckSiteOptions } from "@cosense-toolbox/lsp/check";
|
|
5
|
+
import { CompileOptions, HastHighlighter, RenderOptions } from "@cosense-toolbox/cosense-x";
|
|
6
|
+
import { AstroIntegration } from "astro";
|
|
7
|
+
import "@cosense-toolbox/parser";
|
|
8
|
+
import "vite";
|
|
9
|
+
//#region src/highlight.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* `.csn` / `.csnx` のコードブロックの色付け。
|
|
12
|
+
* `'astro'` は `markdown.syntaxHighlight` / `markdown.shikiConfig` に従い、関数なら自分で色付けする。
|
|
13
|
+
*/
|
|
14
|
+
type SyntaxHighlightOption = "astro" | false | HastHighlighter;
|
|
15
|
+
/**
|
|
16
|
+
* 利用者が統合に渡す描画の設定。色付けは統合が `syntaxHighlight` から作って渡すので含めない。
|
|
17
|
+
*/
|
|
18
|
+
type AstroRenderOptions = Omit<RenderOptions, "highlight">;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/lint.d.ts
|
|
21
|
+
interface CosenseLintOptions {
|
|
22
|
+
/**
|
|
23
|
+
* サイトに無いページへのリンクの知らせ方。`'error'` ならビルドを止める。
|
|
24
|
+
* `'off'` / `'hint'` / `'information'` / `'warning'` / `'error'`。
|
|
25
|
+
*
|
|
26
|
+
* @defaultValue `'warning'`
|
|
27
|
+
*/
|
|
28
|
+
readonly unresolvedLinks?: CheckSiteOptions["unresolvedLinks"];
|
|
29
|
+
/**
|
|
30
|
+
* 1 行目の `---` を frontmatter (YAML) として飛ばすか。
|
|
31
|
+
*
|
|
32
|
+
* @defaultValue `true`
|
|
33
|
+
*/
|
|
34
|
+
readonly frontmatter?: boolean;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/vite-plugin.d.ts
|
|
38
|
+
interface AstroCompileOptions extends Omit<CompileOptions, "filePath" | "format" | "index" | "jsxImportSource" | "elementAttributeNameCase" | "renderOptions" | "unresolved"> {
|
|
39
|
+
/**
|
|
40
|
+
* サイトに無いページへのリンクの出し方。`'text'` はテキストにする (非公開のページの名前が
|
|
41
|
+
* URL に漏れない)。`'link'` はタイトルから作った URL へのリンクにする。
|
|
42
|
+
* リンク切れを知らせるのは `lint` の役目。
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue `'text'`
|
|
45
|
+
*/
|
|
46
|
+
readonly unresolvedLinks?: "text" | "link";
|
|
47
|
+
/**
|
|
48
|
+
* 描画の設定。parser の `toHast` のオプションがそのまま渡る
|
|
49
|
+
* (`extensions` / `handlers` / `classNames` / `showPads` / `iconImageUrl` / `title`)。
|
|
50
|
+
* コードブロックの色付けは `syntaxHighlight` で決める。
|
|
51
|
+
*/
|
|
52
|
+
readonly renderOptions?: AstroRenderOptions;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/index.d.ts
|
|
56
|
+
interface CosenseAssetsOptions {
|
|
57
|
+
/**
|
|
58
|
+
* Cosense の Personal Access Token。非公開プロジェクトの画像を取ってくるときに渡す。
|
|
59
|
+
* Cosense への要求にだけ付け、リダイレクト先 (Google Cloud Storage や Gyazo) には送らない。
|
|
60
|
+
*
|
|
61
|
+
* @example `process.env.COSENSE_PAT`
|
|
62
|
+
*/
|
|
63
|
+
readonly pat?: string;
|
|
64
|
+
/** Cosense の origin。 @defaultValue `https://scrapbox.io` */
|
|
65
|
+
readonly origin?: string;
|
|
66
|
+
/**
|
|
67
|
+
* リンクした Cosense のファイル (`[https://scrapbox.io/files/x.zip]` など) の扱い。画像は常に取ってくる。
|
|
68
|
+
* `'keep'` は元の URL のまま (公開プロジェクトならクリックで開ける)、`'download'` は取ってきてサイトに置く。
|
|
69
|
+
* 非公開プロジェクトのファイルは `'download'` でないと、見に来た人が開けない。
|
|
70
|
+
*
|
|
71
|
+
* @defaultValue `'keep'`
|
|
72
|
+
*/
|
|
73
|
+
readonly links?: "keep" | "download";
|
|
74
|
+
}
|
|
75
|
+
interface CosenseIntegrationOptions extends AstroCompileOptions {
|
|
76
|
+
/**
|
|
77
|
+
* すべてのページに渡すコンポーネントを default export するモジュール (プロジェクトのルートからのパス)。
|
|
78
|
+
* `.csnx` の `<Name />` や、`a` などの要素の差し替えに使う。
|
|
79
|
+
* `<Content components={...} />` で渡したものがあれば、そちらが優先する。
|
|
80
|
+
*
|
|
81
|
+
* @example `'./src/components/cosense.ts'`
|
|
82
|
+
*/
|
|
83
|
+
readonly components?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Cosense 上の画像やファイル (`/files/…` とアイコン) を、ビルド時に取ってきてサイトの中
|
|
86
|
+
* (`{base}/_cosense/`) に置く。`false` なら元の URL のまま出す。
|
|
87
|
+
*
|
|
88
|
+
* Cosense のファイルは別のサイトからは読めず、リダイレクト先の URL も数分で切れるので、
|
|
89
|
+
* 静的なサイトで表示するにはこうするしかない。非公開プロジェクトの画像も公開されることになる点に注意。
|
|
90
|
+
*
|
|
91
|
+
* @defaultValue `{}` (有効)
|
|
92
|
+
*/
|
|
93
|
+
readonly assets?: CosenseAssetsOptions | false;
|
|
94
|
+
/**
|
|
95
|
+
* コードブロックの色付け。
|
|
96
|
+
*
|
|
97
|
+
* - `'astro'`: `.md` / `.mdx` と同じく、Astro の `markdown.syntaxHighlight` と `markdown.shikiConfig` に従う。
|
|
98
|
+
* shiki のときだけ色付けし、prism には対応していない
|
|
99
|
+
* - `false`: 色付けしない
|
|
100
|
+
* - 関数: `(code, language) => hast | null` で自分で色付けする
|
|
101
|
+
*
|
|
102
|
+
* @defaultValue `'astro'`
|
|
103
|
+
*/
|
|
104
|
+
readonly syntaxHighlight?: SyntaxHighlightOption;
|
|
105
|
+
/**
|
|
106
|
+
* ビルドの前に、`srcDir` の下のページのリンク切れを調べる。エディタの診断
|
|
107
|
+
* (`@cosense-toolbox/lsp`) と同じ判定で、`unresolvedLinks: 'error'` ならビルドを止める。
|
|
108
|
+
* 省略すると調べない。
|
|
109
|
+
*
|
|
110
|
+
* @example `{ unresolvedLinks: 'error' }`
|
|
111
|
+
*/
|
|
112
|
+
readonly lint?: CosenseLintOptions;
|
|
113
|
+
}
|
|
114
|
+
declare function cosense(options?: CosenseIntegrationOptions): AstroIntegration;
|
|
115
|
+
//#endregion
|
|
116
|
+
export { CosenseAssetsOptions, CosenseIntegrationOptions, type Graph, type GraphPage, type TwoHopGroup, cosense as default };
|
|
117
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/highlight.ts","../src/lint.ts","../src/vite-plugin.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;KAkBY,0CAA0C;;;;KAkG1C,qBAAqB,KAAK;;;UCxGrB;;;;;;;WAON,kBAAkB;;;;;;WAMlB;;;;UCqBM,4BAA4B,KAC3C;;;;;;;;WAgBS;;;;;;WAMA,gBAAgB;;;;UC9BV;;;;;;;WAON;;WAEA;;;;;;;;WAQA;;UAGM,kCAAkC;;;;;;;;WAQxC;;;;;;;;;;WAUA,SAAS;;;;;;;;;;;WAWT,kBAAkB;;;;;;;;WAQlB,OAAO;;iBA4FM,QAAQ,UAAS,4BAAiC"}
|