Uploads to same folder
This commit is contained in:
parent
04d6de18e6
commit
fd6f81d500
11
common/path.test.ts
Normal file
11
common/path.test.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { assertEquals } from "../test_deps.ts";
|
||||||
|
import { folderName, resolve } from "./path.ts";
|
||||||
|
|
||||||
|
Deno.test("Path functions", () => {
|
||||||
|
assertEquals(folderName(""), "");
|
||||||
|
assertEquals(folderName("page"), "");
|
||||||
|
assertEquals(folderName("folder/page"), "folder");
|
||||||
|
|
||||||
|
assertEquals(resolve("", "page"), "page");
|
||||||
|
assertEquals(resolve("folder", "page"), "folder/page");
|
||||||
|
});
|
23
common/path.ts
Normal file
23
common/path.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
export function folderName(path: string) {
|
||||||
|
return path.split("/").slice(0, -1).join("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolve(...paths: string[]) {
|
||||||
|
const parts = paths.reduce((acc, path) => {
|
||||||
|
return acc.concat(path.split("/"));
|
||||||
|
}, [] as string[]);
|
||||||
|
const resolvedParts = [];
|
||||||
|
for (const part of parts) {
|
||||||
|
if (part === "..") {
|
||||||
|
resolvedParts.pop();
|
||||||
|
} else if (part !== ".") {
|
||||||
|
resolvedParts.push(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const result = resolvedParts.join("/");
|
||||||
|
if (result[0] === "/") {
|
||||||
|
return result.substring(1);
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
37
deno.jsonc
37
deno.jsonc
@ -31,35 +31,22 @@
|
|||||||
},
|
},
|
||||||
"importMap": "import_map.json",
|
"importMap": "import_map.json",
|
||||||
"lint": {
|
"lint": {
|
||||||
"files": {
|
"exclude": [
|
||||||
"exclude": [
|
"dist",
|
||||||
"dist",
|
"dist_bundle"
|
||||||
"dist_bundle"
|
],
|
||||||
]
|
|
||||||
},
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"exclude": ["no-explicit-any"]
|
"exclude": ["no-explicit-any"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test": {
|
|
||||||
"files": {
|
|
||||||
"exclude": ["plugos/forked", "plugos/sqlite/deno-sqlite"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"fmt": {
|
"fmt": {
|
||||||
"files": {
|
"exclude": [
|
||||||
"exclude": [
|
"dist",
|
||||||
"dist",
|
"dist_bundle",
|
||||||
"dist_bundle",
|
"website",
|
||||||
"desktop",
|
"website_build",
|
||||||
"mobile",
|
"test_space",
|
||||||
"pages",
|
"README.md"
|
||||||
"website",
|
]
|
||||||
"website_build",
|
|
||||||
"test_space",
|
|
||||||
"plugos/environments/worker_bundle.json",
|
|
||||||
"README.md"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
VERSION=$1
|
VERSION=$1
|
||||||
echo "export const version = '$VERSION';" > version.ts
|
echo "export const version = \"$VERSION\";" > version.ts
|
||||||
git commit -am $VERSION
|
git commit -am $VERSION
|
||||||
git tag $VERSION
|
git tag $VERSION
|
||||||
git push && git push --tags
|
git push && git push --tags
|
||||||
|
@ -17,6 +17,8 @@ import {
|
|||||||
findParentMatching,
|
findParentMatching,
|
||||||
nodeAtPos,
|
nodeAtPos,
|
||||||
} from "../../plug-api/lib/tree.ts";
|
} from "../../plug-api/lib/tree.ts";
|
||||||
|
import { folderName, resolve } from "../../common/path.ts";
|
||||||
|
|
||||||
const turndownService = new TurndownService({
|
const turndownService = new TurndownService({
|
||||||
hr: "---",
|
hr: "---",
|
||||||
codeBlockStyle: "fenced",
|
codeBlockStyle: "fenced",
|
||||||
@ -202,6 +204,8 @@ export function attachmentExtension(editor: Editor) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suggestedName = resolve(folderName(editor.currentPage!), suggestedName);
|
||||||
|
|
||||||
const finalFileName = await editor.prompt(
|
const finalFileName = await editor.prompt(
|
||||||
"File name for pasted attachment",
|
"File name for pasted attachment",
|
||||||
suggestedName,
|
suggestedName,
|
||||||
|
Loading…
Reference in New Issue
Block a user