@riebeckite/plugin-source-files 0.0.32 → 0.0.33
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/README.md +25 -3
- package/README_ja.md +25 -3
- package/dist/client.js +0 -14
- package/dist/index.d.ts +0 -1
- package/dist/index.js +4 -5
- package/package.json +2 -2
- package/style.css +38 -5
package/README.md
CHANGED
|
@@ -30,11 +30,33 @@ export default defineConfig({
|
|
|
30
30
|
|
|
31
31
|
## Links and embeds
|
|
32
32
|
|
|
33
|
-
- `[src/main.ts](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/src/main.ts.md)` links to `/source/src/main.ts
|
|
33
|
+
- `[src/main.ts](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/src/main.ts.md)` links to `/source/src/main.ts/`.
|
|
34
34
|
- `` renders the source in the existing code-block path.
|
|
35
35
|
- `#L10` and `#L10-L20` select lines in an embed. With Code Enhance enabled, those source-page fragments scroll to and highlight the matching line or range.
|
|
36
36
|
|
|
37
|
-
Each source page includes its vault-relative path, detected language, size,
|
|
37
|
+
Each source page includes its vault-relative path, detected language, size, and a download link.
|
|
38
|
+
|
|
39
|
+
## Live examples
|
|
40
|
+
|
|
41
|
+
The following source is rendered on this page as a source-page link, a full-file embed, and a line-range embed.
|
|
42
|
+
|
|
43
|
+
#### Source
|
|
44
|
+
|
|
45
|
+
````md
|
|
46
|
+
[[source-file-example.ts]]
|
|
47
|
+
|
|
48
|
+
![[source-file-example.ts]]
|
|
49
|
+
|
|
50
|
+
![[source-file-example.ts#L3-L5]]
|
|
51
|
+
````
|
|
52
|
+
|
|
53
|
+
#### Rendered
|
|
54
|
+
|
|
55
|
+
[source-file-example.ts](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/source-file-example.ts.md)
|
|
56
|
+
|
|
57
|
+

|
|
58
|
+
|
|
59
|
+

|
|
38
60
|
|
|
39
61
|
## Safety and publication
|
|
40
62
|
|
|
@@ -50,7 +72,7 @@ Only files matching `include` and not matching `exclude` are eligible. The plugi
|
|
|
50
72
|
|
|
51
73
|
## Exports
|
|
52
74
|
|
|
53
|
-
- `sourceFiles(options)` / `
|
|
75
|
+
- `sourceFiles(options)` / `sourceFiles`
|
|
54
76
|
- `sourceFilePath(path)`
|
|
55
77
|
- `SourceFilesOptions`
|
|
56
78
|
|
package/README_ja.md
CHANGED
|
@@ -30,11 +30,33 @@ export default defineConfig({
|
|
|
30
30
|
|
|
31
31
|
## リンクと埋め込み
|
|
32
32
|
|
|
33
|
-
- `[src/main.ts](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/src/main.ts.ja.md)` は `/source/src/main.ts
|
|
33
|
+
- `[src/main.ts](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/src/main.ts.ja.md)` は `/source/src/main.ts/` のページへリンクします。
|
|
34
34
|
- `` は既存のコードブロック表示経路でソースを表示します。
|
|
35
35
|
- `#L10` と `#L10-L20` は埋め込みの行範囲を選びます。Code Enhance を有効にすると、ソースページでも該当の行または範囲へスクロールし、強調表示します。
|
|
36
36
|
|
|
37
|
-
ソースページには Vault
|
|
37
|
+
ソースページには Vault 相対パス、検出した言語、サイズとダウンロードリンクを表示します。
|
|
38
|
+
|
|
39
|
+
## 実行例
|
|
40
|
+
|
|
41
|
+
以下のソースは、このページ上でソースページへのリンク、ファイル全体の埋め込み、行範囲の埋め込みとして実際に描画されます。
|
|
42
|
+
|
|
43
|
+
#### ソース
|
|
44
|
+
|
|
45
|
+
````md
|
|
46
|
+
[[source-file-example.ts]]
|
|
47
|
+
|
|
48
|
+
![[source-file-example.ts]]
|
|
49
|
+
|
|
50
|
+
![[source-file-example.ts#L3-L5]]
|
|
51
|
+
````
|
|
52
|
+
|
|
53
|
+
#### 実行例
|
|
54
|
+
|
|
55
|
+
[source-file-example.ts](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/source-file-example.ts.ja.md)
|
|
56
|
+
|
|
57
|
+

|
|
58
|
+
|
|
59
|
+

|
|
38
60
|
|
|
39
61
|
## 安全性と公開境界
|
|
40
62
|
|
|
@@ -50,7 +72,7 @@ export default defineConfig({
|
|
|
50
72
|
|
|
51
73
|
## 公開 API
|
|
52
74
|
|
|
53
|
-
- `sourceFiles(options)` / `
|
|
75
|
+
- `sourceFiles(options)` / `sourceFiles`
|
|
54
76
|
- `sourceFilePath(path)`
|
|
55
77
|
- `SourceFilesOptions`
|
|
56
78
|
|
package/dist/client.js
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
// client.ts
|
|
2
2
|
function initSourceFiles() {
|
|
3
|
-
const onClick = async (event) => {
|
|
4
|
-
const target = event.target;
|
|
5
|
-
if (!(target instanceof Element)) return;
|
|
6
|
-
const button = target.closest("[data-source-file-copy]");
|
|
7
|
-
if (!button) return;
|
|
8
|
-
const code = document.querySelector(
|
|
9
|
-
".rr-source-file .rr-code__code, .rr-source-file pre code"
|
|
10
|
-
);
|
|
11
|
-
if (!code?.textContent) return;
|
|
12
|
-
await navigator.clipboard?.writeText(code.textContent);
|
|
13
|
-
button.dataset.sourceFileCopied = "true";
|
|
14
|
-
};
|
|
15
3
|
const updateLineTarget = () => {
|
|
16
4
|
const match = decodeURIComponent(window.location.hash.slice(1)).match(
|
|
17
5
|
/^L(\d+)(?:-L(\d+))?$/i
|
|
@@ -38,12 +26,10 @@ function initSourceFiles() {
|
|
|
38
26
|
target.scrollIntoView({ block: "center" });
|
|
39
27
|
target.focus({ preventScroll: true });
|
|
40
28
|
};
|
|
41
|
-
document.addEventListener("click", onClick);
|
|
42
29
|
window.addEventListener("hashchange", updateLineTarget);
|
|
43
30
|
document.addEventListener("riebeckite:navigation", updateLineTarget);
|
|
44
31
|
updateLineTarget();
|
|
45
32
|
return () => {
|
|
46
|
-
document.removeEventListener("click", onClick);
|
|
47
33
|
window.removeEventListener("hashchange", updateLineTarget);
|
|
48
34
|
document.removeEventListener("riebeckite:navigation", updateLineTarget);
|
|
49
35
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,4 @@ export type SourceFilesOptions = {
|
|
|
5
5
|
maxBytes?: number;
|
|
6
6
|
};
|
|
7
7
|
export declare function sourceFiles(options: SourceFilesOptions): import("@riebeckite/core").RiebeckitePlugin<SourceFilesOptions>;
|
|
8
|
-
export declare const sourceFilesPlugin: typeof sourceFiles;
|
|
9
8
|
export { sourceFilePath };
|
package/dist/index.js
CHANGED
|
@@ -64,11 +64,11 @@ ${source.text}
|
|
|
64
64
|
type: "source-file",
|
|
65
65
|
pathname: context.pathname,
|
|
66
66
|
title,
|
|
67
|
-
body: `<main class="rr-source-file" data-source-file="${escapeHtmlAttribute(sourcePath)}"><header class="rr-source-file__header"><h1>${escapeHtml(title)}</h1><
|
|
67
|
+
body: `<main class="rr-source-file" data-source-file="${escapeHtmlAttribute(sourcePath)}"><header class="rr-source-file__header"><h1>${escapeHtml(title)}</h1><p class="rr-source-file__path">${escapeHtml(sourcePath)}</p><dl class="rr-source-file__metadata"><div><dt>Language</dt><dd>${escapeHtml(languageFor(sourcePath))}</dd></div><div><dt>Size</dt><dd>${escapeHtml(formatBytes(source.bytes))}</dd></div></dl><a class="rr-source-file__download" href="${escapeHtmlAttribute(attachmentUrl(sourcePath))}" download>Download source file</a></header>${code}</main>`
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
function sourceFilePath(path) {
|
|
71
|
-
return `/source/${path.split("/").map(encodeURIComponent).join("/")}
|
|
71
|
+
return `/source/${path.split("/").map(encodeURIComponent).join("/")}/`;
|
|
72
72
|
}
|
|
73
73
|
function resolveSourcePath(pathname, manifest, options) {
|
|
74
74
|
for (const entry of manifest.publicEntries) {
|
|
@@ -160,6 +160,7 @@ function sourceFiles(options) {
|
|
|
160
160
|
pageTypes: [
|
|
161
161
|
{
|
|
162
162
|
id: "source-file",
|
|
163
|
+
directoryIndex: true,
|
|
163
164
|
paths: (context) => listSourceFiles(context.manifest, context.contentSource, options),
|
|
164
165
|
outputDependencies: (context) => {
|
|
165
166
|
const path = resolveSourcePath(
|
|
@@ -187,7 +188,6 @@ function sourceFiles(options) {
|
|
|
187
188
|
]
|
|
188
189
|
});
|
|
189
190
|
}
|
|
190
|
-
var sourceFilesPlugin = sourceFiles;
|
|
191
191
|
function validateOptions(options) {
|
|
192
192
|
if (!options || !Array.isArray(options.include) || options.include.length === 0) {
|
|
193
193
|
return [
|
|
@@ -213,6 +213,5 @@ function validateOptions(options) {
|
|
|
213
213
|
}
|
|
214
214
|
export {
|
|
215
215
|
sourceFilePath,
|
|
216
|
-
sourceFiles
|
|
217
|
-
sourceFilesPlugin
|
|
216
|
+
sourceFiles
|
|
218
217
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-source-files",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"./style.css": "./style.css"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@riebeckite/core": "0.0.
|
|
24
|
+
"@riebeckite/core": "0.0.33"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"tsx": "^4.22.4"
|
package/style.css
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
|
+
.rr-source-file {
|
|
2
|
+
width: min(100%, var(--rb-layout-article-max, 48rem));
|
|
3
|
+
margin-inline: auto;
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
.rr-source-file__header {
|
|
2
7
|
display: grid;
|
|
3
|
-
gap:
|
|
8
|
+
gap: 0.5rem;
|
|
9
|
+
margin-bottom: 1.5rem;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.rr-source-file__header h1 {
|
|
13
|
+
margin: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.rr-source-file__path {
|
|
17
|
+
margin: 0;
|
|
18
|
+
overflow-wrap: anywhere;
|
|
19
|
+
color: var(--rb-color-muted, currentColor);
|
|
4
20
|
}
|
|
5
21
|
|
|
6
22
|
.rr-source-file__metadata {
|
|
7
23
|
display: flex;
|
|
8
24
|
flex-wrap: wrap;
|
|
9
|
-
gap: 0.
|
|
25
|
+
gap: 0.25rem 1rem;
|
|
10
26
|
margin: 0;
|
|
11
27
|
}
|
|
12
28
|
|
|
@@ -17,15 +33,32 @@
|
|
|
17
33
|
|
|
18
34
|
.rr-source-file__metadata dt {
|
|
19
35
|
font-weight: 600;
|
|
36
|
+
color: var(--rb-color-muted, currentColor);
|
|
20
37
|
}
|
|
21
38
|
|
|
22
39
|
.rr-source-file__metadata dd {
|
|
23
40
|
margin: 0;
|
|
24
41
|
}
|
|
25
42
|
|
|
26
|
-
.rr-source-
|
|
27
|
-
display: flex;
|
|
28
|
-
|
|
43
|
+
.rr-source-file__download {
|
|
44
|
+
display: inline-flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
justify-self: start;
|
|
47
|
+
margin-top: 0.25rem;
|
|
48
|
+
padding: 0.4rem 0.65rem;
|
|
49
|
+
border: 1px solid currentColor;
|
|
50
|
+
color: inherit;
|
|
51
|
+
font-weight: 600;
|
|
52
|
+
text-decoration: none;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.rr-source-file__download:hover {
|
|
56
|
+
background: color-mix(in srgb, currentColor 12%, transparent);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.rr-source-file__download:focus-visible {
|
|
60
|
+
outline: 2px solid currentColor;
|
|
61
|
+
outline-offset: 2px;
|
|
29
62
|
}
|
|
30
63
|
|
|
31
64
|
.rr-source-file-embed__title {
|