From fd6f81d5008b46beaa268bfb62643ea335fd8693 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 7 Jul 2023 13:09:44 +0200 Subject: [PATCH] Uploads to same folder --- common/path.test.ts | 11 ++++++++++ common/path.ts | 23 +++++++++++++++++++++ deno.jsonc | 37 +++++++++++----------------------- scripts/release.sh | 2 +- web/cm_plugins/editor_paste.ts | 4 ++++ 5 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 common/path.test.ts create mode 100644 common/path.ts diff --git a/common/path.test.ts b/common/path.test.ts new file mode 100644 index 0000000..b446657 --- /dev/null +++ b/common/path.test.ts @@ -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"); +}); diff --git a/common/path.ts b/common/path.ts new file mode 100644 index 0000000..e779cfb --- /dev/null +++ b/common/path.ts @@ -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; + } +} diff --git a/deno.jsonc b/deno.jsonc index aae60de..4aea8e0 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -31,35 +31,22 @@ }, "importMap": "import_map.json", "lint": { - "files": { - "exclude": [ - "dist", - "dist_bundle" - ] - }, + "exclude": [ + "dist", + "dist_bundle" + ], "rules": { "exclude": ["no-explicit-any"] } }, - "test": { - "files": { - "exclude": ["plugos/forked", "plugos/sqlite/deno-sqlite"] - } - }, "fmt": { - "files": { - "exclude": [ - "dist", - "dist_bundle", - "desktop", - "mobile", - "pages", - "website", - "website_build", - "test_space", - "plugos/environments/worker_bundle.json", - "README.md" - ] - } + "exclude": [ + "dist", + "dist_bundle", + "website", + "website_build", + "test_space", + "README.md" + ] } } diff --git a/scripts/release.sh b/scripts/release.sh index efb99d1..551d7e1 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,7 +1,7 @@ #!/bin/bash -e VERSION=$1 -echo "export const version = '$VERSION';" > version.ts +echo "export const version = \"$VERSION\";" > version.ts git commit -am $VERSION git tag $VERSION git push && git push --tags diff --git a/web/cm_plugins/editor_paste.ts b/web/cm_plugins/editor_paste.ts index 3a6feb3..fffdd7a 100644 --- a/web/cm_plugins/editor_paste.ts +++ b/web/cm_plugins/editor_paste.ts @@ -17,6 +17,8 @@ import { findParentMatching, nodeAtPos, } from "../../plug-api/lib/tree.ts"; +import { folderName, resolve } from "../../common/path.ts"; + const turndownService = new TurndownService({ hr: "---", codeBlockStyle: "fenced", @@ -202,6 +204,8 @@ export function attachmentExtension(editor: Editor) { return; } + suggestedName = resolve(folderName(editor.currentPage!), suggestedName); + const finalFileName = await editor.prompt( "File name for pasted attachment", suggestedName,