Skip to content

Commit

Permalink
folders working right
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktau committed Feb 10, 2024
1 parent 1400096 commit 9c8a52e
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/debouncedProcessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,39 @@ export class DebouncedProcessors implements Processor {
.setIcon('image-file')
.onClick(async () => {

const getFilePath = async (type: string) => {
const exportPath = this.plugin.settings.exportPath
let path = ''
if (exportPath.trim().length > 0) {
try {
await this.plugin.app.vault.createFolder(exportPath)
} catch (error) {
console.error(error)
}

path = exportPath;
if (path[-1] != '/') {
path = `${path}/`;
}
const getFilename = () => {
// try extract the title of the diagram
const startuml = source.match(/@startuml (.+)/i);
if (startuml?.length >= 2) {
return `${startuml[1].trim()}`;
}

const now = (new Date()).toISOString().replace(/[:T]+/g, '-');
let name = `${ctx.sourcePath.substring(0, ctx.sourcePath.lastIndexOf('.'))}-${now.substring(0, now.lastIndexOf('.'))}`;
return `${ctx.sourcePath.substring(0, ctx.sourcePath.lastIndexOf('.'))}-${now.substring(0, now.lastIndexOf('.'))}`;
}

// try extract the title of the diagram
const found = source.match(/@startuml (.+)/i);
if (found?.length >= 2) {
name = `${found[1].trim()}`;
const getFolder = async () => {
let exportPath = this.plugin.settings.exportPath
if (!exportPath.startsWith('/')) {
// relative to the document
const documentPath = this.plugin.app.vault.getAbstractFileByPath(ctx.sourcePath).parent;
exportPath = `${documentPath.path}/${exportPath}`
}

return `${path}${name}.${type}`;
const exists = await this.plugin.app.vault.adapter.exists(exportPath)
if (!exists) {
this.plugin.app.vault.createFolder(exportPath);
}

return exportPath;
}

const getFilePath = async (type: string) => {

const filename = getFilename();
const path = await getFolder();

return `${path}${filename}.${type}`;
}

const getFile = (fileName: string) => {
Expand Down

0 comments on commit 9c8a52e

Please sign in to comment.