@songmu/mdhq 0.0.5 → 0.0.6
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 +2 -2
- package/dist/cli.js +18 -2
- package/docs/specification.md +7 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,8 +30,8 @@ mdhq root
|
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
`mdhq get` accepts multiple URLs as arguments or one URL per line on standard
|
|
33
|
-
input; both sources are merged. It prints one
|
|
34
|
-
to stdout by default. Warnings are written to stderr. `--json` writes one
|
|
33
|
+
input; both sources are merged. It prints one root-relative Markdown path per
|
|
34
|
+
URL to stdout by default. Warnings are written to stderr. `--json` writes one
|
|
35
35
|
compact JSON result object per URL as JSON Lines. Results are written as soon
|
|
36
36
|
as each URL finishes, so parallel requests can produce output in completion
|
|
37
37
|
order rather than input order. If a later request fails, results already
|
package/dist/cli.js
CHANGED
|
@@ -26,6 +26,13 @@ function parseHeaders(values) {
|
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
function toRootRelative(root, target) {
|
|
30
|
+
const relative = path.relative(root, target);
|
|
31
|
+
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
32
|
+
return target;
|
|
33
|
+
}
|
|
34
|
+
return relative;
|
|
35
|
+
}
|
|
29
36
|
async function readStdinUrls(stdin) {
|
|
30
37
|
if (!stdin || stdin.isTTY) {
|
|
31
38
|
return [];
|
|
@@ -79,6 +86,8 @@ export function createProgram(io = process) {
|
|
|
79
86
|
if (requestedUrls.length === 0) {
|
|
80
87
|
throw new MdhqError("INVALID_URL", "At least one URL is required");
|
|
81
88
|
}
|
|
89
|
+
const loaded = await loadConfig();
|
|
90
|
+
const root = resolveRoot(options.root, loaded.config);
|
|
82
91
|
const scheduler = new RequestScheduler();
|
|
83
92
|
let nextIndex = 0;
|
|
84
93
|
const worker = async () => {
|
|
@@ -91,7 +100,7 @@ export function createProgram(io = process) {
|
|
|
91
100
|
}
|
|
92
101
|
const result = await getPage({
|
|
93
102
|
url,
|
|
94
|
-
|
|
103
|
+
root,
|
|
95
104
|
...(options.assets !== undefined ? { assets: options.assets } : {}),
|
|
96
105
|
update: options.update ?? false,
|
|
97
106
|
...(options.userAgent ? { userAgent: options.userAgent } : {}),
|
|
@@ -99,7 +108,14 @@ export function createProgram(io = process) {
|
|
|
99
108
|
scheduler,
|
|
100
109
|
onWarning: (warning) => io.stderr.write(`warning: ${warning.message}\n`)
|
|
101
110
|
});
|
|
102
|
-
|
|
111
|
+
const relativeResult = {
|
|
112
|
+
...result,
|
|
113
|
+
path: toRootRelative(root, result.path),
|
|
114
|
+
assets: result.assets.map((asset) => asset.path === undefined
|
|
115
|
+
? asset
|
|
116
|
+
: { ...asset, path: toRootRelative(root, asset.path) })
|
|
117
|
+
};
|
|
118
|
+
io.stdout.write(`${options.json ? JSON.stringify(relativeResult) : relativeResult.path}\n`);
|
|
103
119
|
}
|
|
104
120
|
};
|
|
105
121
|
const failures = [];
|
package/docs/specification.md
CHANGED
|
@@ -39,17 +39,18 @@ input. Both sources are merged, and up to eight URLs are processed in parallel.
|
|
|
39
39
|
| `--header <header>` | Add an HTTP header. The option is repeatable and uses `Name: value` syntax. |
|
|
40
40
|
| `--json` | Write one result per line as JSON Lines instead of only the Markdown path. |
|
|
41
41
|
|
|
42
|
-
Without `--json`, stdout receives one
|
|
43
|
-
with each path followed by a newline. Each
|
|
44
|
-
URL finishes, so parallel requests can
|
|
45
|
-
rather than input order.
|
|
42
|
+
Without `--json`, stdout receives one Markdown path per requested URL, relative
|
|
43
|
+
to the effective storage root, with each path followed by a newline. Each
|
|
44
|
+
result is written as soon as that URL finishes, so parallel requests can
|
|
45
|
+
produce output in completion order rather than input order.
|
|
46
46
|
Warnings are written to stderr.
|
|
47
47
|
|
|
48
48
|
With `--json`, stdout contains one compact JSON object per requested URL,
|
|
49
|
-
also written as soon as the URL finishes.
|
|
49
|
+
also written as soon as the URL finishes. Markdown and asset paths are relative
|
|
50
|
+
to the effective storage root. Each line has this shape:
|
|
50
51
|
|
|
51
52
|
```jsonl
|
|
52
|
-
{"requestedUrl":"https://example.com/start","sourceUrl":"https://example.com/article","path":"
|
|
53
|
+
{"requestedUrl":"https://example.com/start","sourceUrl":"https://example.com/article","path":"example.com/article.md","status":"saved","assets":[],"warnings":[]}
|
|
53
54
|
```
|
|
54
55
|
|
|
55
56
|
`status` is one of:
|