@onozaty/growi-uploader 1.2.0 → 1.3.0
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 +14 -0
- package/dist/index.mjs +11 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# growi-uploader
|
|
2
2
|
|
|
3
|
+
[](https://github.com/onozaty/growi-uploader/actions/workflows/test.yaml)
|
|
4
|
+
[](https://codecov.io/gh/onozaty/growi-uploader)
|
|
3
5
|
[](https://www.npmjs.com/package/@onozaty/growi-uploader)
|
|
4
6
|
[](https://opensource.org/licenses/MIT)
|
|
5
7
|
|
|
@@ -178,10 +180,22 @@ images/
|
|
|
178
180
|
All referenced files (`logo.png`, `screenshot.png`, and `banner.png`) will be uploaded as attachments to the `/guide` page, even though they don't follow the `_attachment_` naming convention.
|
|
179
181
|
|
|
180
182
|
**Path resolution:**
|
|
183
|
+
- Markdown escape sequences are unescaped (`\(` → `(`)
|
|
184
|
+
- URL encoding (percent-encoding) is decoded (`%20` → space, `%E7%94%BB%E5%83%8F` → `画像`)
|
|
181
185
|
- Relative paths (`./`, `../`, or no prefix): Resolved from the Markdown file's directory
|
|
182
186
|
- Absolute paths (starting with `/`): Resolved from the source directory root
|
|
183
187
|
- Example: `/assets/banner.png` → `<source-dir>/assets/banner.png`
|
|
184
188
|
|
|
189
|
+
**Supported link formats:**
|
|
190
|
+
```markdown
|
|
191
|
+
 # Standard relative path
|
|
192
|
+
 # Relative path without ./
|
|
193
|
+
 # URL-encoded Japanese filename
|
|
194
|
+
[File](./docs/my%20file.pdf) # URL-encoded space
|
|
195
|
+
[File](<./path/file (1).png>) # Special chars with angle brackets
|
|
196
|
+
.png) # Special chars with escaping
|
|
197
|
+
```
|
|
198
|
+
|
|
185
199
|
**Excluded from detection:**
|
|
186
200
|
- `.md` files (treated as page links)
|
|
187
201
|
- External URLs (`http://`, `https://`)
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { lookup } from "mime-types";
|
|
|
8
8
|
import { glob } from "glob";
|
|
9
9
|
|
|
10
10
|
//#region package.json
|
|
11
|
-
var version = "1.
|
|
11
|
+
var version = "1.3.0";
|
|
12
12
|
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/config.ts
|
|
@@ -247,9 +247,15 @@ const extractLinkedAttachments = (content, markdownFilePath, sourceDir) => {
|
|
|
247
247
|
if (linkPath.startsWith("http://") || linkPath.startsWith("https://")) continue;
|
|
248
248
|
if (linkPath.endsWith(".md")) continue;
|
|
249
249
|
const unescapedPath = linkPath.replace(/\\([\\`*_{}[\]()#+\-.!])/g, "$1");
|
|
250
|
+
let decodedPath;
|
|
251
|
+
try {
|
|
252
|
+
decodedPath = decodeURIComponent(unescapedPath);
|
|
253
|
+
} catch {
|
|
254
|
+
decodedPath = unescapedPath;
|
|
255
|
+
}
|
|
250
256
|
let absolutePath;
|
|
251
|
-
if (linkPath.startsWith("/")) absolutePath = resolve(sourceDir,
|
|
252
|
-
else absolutePath = resolve(dirname(join(sourceDir, markdownFilePath)),
|
|
257
|
+
if (linkPath.startsWith("/")) absolutePath = resolve(sourceDir, decodedPath.slice(1));
|
|
258
|
+
else absolutePath = resolve(dirname(join(sourceDir, markdownFilePath)), decodedPath);
|
|
253
259
|
if (!existsSync(absolutePath)) continue;
|
|
254
260
|
const normalizedPath = relative(sourceDir, absolutePath).replace(/\\/g, "/");
|
|
255
261
|
attachments.push({
|
|
@@ -343,13 +349,13 @@ const replaceAttachmentLinks = (markdown, attachments, pageName) => {
|
|
|
343
349
|
const escapedFileName = escapeRegex(`${pageName}_attachment_${attachment.fileName}`);
|
|
344
350
|
patterns.push(escapedFileName, `\\./${escapedFileName}`);
|
|
345
351
|
}
|
|
346
|
-
if (attachment.
|
|
352
|
+
if (attachment.originalLinkPaths) for (const linkPath of attachment.originalLinkPaths) {
|
|
347
353
|
const escapedPath = escapeRegex(linkPath);
|
|
348
354
|
patterns.push(escapedPath);
|
|
349
355
|
if (linkPath.startsWith("./")) {
|
|
350
356
|
const escapedWithoutDot = escapeRegex(linkPath.substring(2));
|
|
351
357
|
patterns.push(escapedWithoutDot);
|
|
352
|
-
} else if (!linkPath.startsWith("../")) patterns.push(`\\./${escapedPath}`);
|
|
358
|
+
} else if (!linkPath.startsWith("../") && !linkPath.startsWith("<")) patterns.push(`\\./${escapedPath}`);
|
|
353
359
|
}
|
|
354
360
|
for (const pattern of patterns) {
|
|
355
361
|
const imgRegex = new RegExp(`!\\[([^\\]]*)\\]\\(${pattern}\\)`, "g");
|