From 68f586a427c03db75d0ef7c3ace8b3ebe84f3c75 Mon Sep 17 00:00:00 2001 From: Akos Balasko Date: Fri, 26 Mar 2021 21:25:43 +0100 Subject: [PATCH] implemented --- package-lock.json | 2 +- src/YarleOptions.ts | 1 + src/process-resources.ts | 10 +++++----- src/utils/filename-utils.ts | 14 +++++++++----- src/utils/folder-utils.ts | 13 +++++++++---- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index fd995708..06635ead 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "yarle-evernote-to-md", - "version": "3.11.1", + "version": "3.12.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/YarleOptions.ts b/src/YarleOptions.ts index ada494e6..ba3a5b8a 100644 --- a/src/YarleOptions.ts +++ b/src/YarleOptions.ts @@ -28,4 +28,5 @@ export interface YarleOptions { nestedTags?: TagSeparatorReplaceOptions; keepImageSize?: OutputFormat; keepOriginalAmountOfNewlines?: boolean; + useNoteNameAsAttachmentName?: boolean; } diff --git a/src/process-resources.ts b/src/process-resources.ts index ada5d0c2..d3541612 100644 --- a/src/process-resources.ts +++ b/src/process-resources.ts @@ -11,18 +11,18 @@ export const processResources = (note: any): string => { const relativeResourceWorkDir = utils.getRelativeResourceDir(note); const absoluteResourceWorkDir = utils.getAbsoluteResourceDir(note); - + const noteName = utils.getNoteNameByMdPath(note); utils.clearResourceDir(note); if (Array.isArray(note.resource)) { for (const resource of note.resource) { resourceHashes = { ...resourceHashes, - ...processResource(absoluteResourceWorkDir, resource)}; + ...processResource(noteName, absoluteResourceWorkDir, resource)}; } } else { resourceHashes = { ...resourceHashes, - ...processResource(absoluteResourceWorkDir, note.resource)}; + ...processResource(noteName, absoluteResourceWorkDir, note.resource)}; } for (const hash of Object.keys(resourceHashes)) { @@ -56,11 +56,11 @@ const addMediaReference = (content: string, resourceHashes: any, hash: any, work return updatedContent; }; -const processResource = (workDir: string, resource: any): any => { +const processResource = (noteName: string, workDir: string, resource: any): any => { const resourceHash: any = {}; const data = resource.data.$text; - const resourceFileProps = utils.getResourceFileProperties(workDir, resource); + const resourceFileProps = utils.getResourceFileProperties(noteName, workDir, resource); const fileName = resourceFileProps.fileName; const absFilePath = `${workDir}/${fileName}`; diff --git a/src/utils/filename-utils.ts b/src/utils/filename-utils.ts index 41d85443..c8a4f1ea 100644 --- a/src/utils/filename-utils.ts +++ b/src/utils/filename-utils.ts @@ -24,19 +24,23 @@ export const getFileIndex = (dstPath: string, fileNamePrefix: string): number | return index; }; -export const getResourceFileProperties = (workDir: string, resource: any): ResourceFileProperties => { +export const getResourceFileProperties = (noteName: string, workDir: string, resource: any): ResourceFileProperties => { const UNKNOWNFILENAME = 'unknown_filename'; const extension = getExtension(resource); let fileName = UNKNOWNFILENAME; - if (resource['resource-attributes'] && resource['resource-attributes']['file-name']) { - const fileNamePrefix = resource['resource-attributes']['file-name'].substr(0, 50); + if (yarleOptions.useNoteNameAsAttachmentName){ + fileName = noteName; + } + else{ + if (resource['resource-attributes'] && resource['resource-attributes']['file-name']) { + const fileNamePrefix = resource['resource-attributes']['file-name'].substr(0, 50); - fileName = fileNamePrefix.split('.')[0]; + fileName = fileNamePrefix.split('.')[0]; + } } - const index = getFileIndex(workDir, fileName); const fileNameWithIndex = index > 0 ? `${fileName}.${index}` : fileName; diff --git a/src/utils/folder-utils.ts b/src/utils/folder-utils.ts index ac603933..1402c790 100644 --- a/src/utils/folder-utils.ts +++ b/src/utils/folder-utils.ts @@ -5,17 +5,22 @@ import { Path } from '../paths'; import { yarleOptions } from '../yarle'; import { getNoteFileName, getNoteName } from './filename-utils'; +import { NoteData } from 'models'; export const paths: Path = {}; -export const getResourceDir = (dstPath: string, note: any): string => { - return getNoteName(dstPath, note).replace(/\s/g, '_'); +export const getResourceDir = (note: any): string => { + return getNoteName(paths.mdPath, note).replace(/\s/g, '_'); }; const getFilePath = (dstPath: string, note: any): string => { return `${dstPath}/${getNoteFileName(dstPath, note)}`; }; +export const getNoteNameByMdPath = (note: any): string => { + return getNoteName(paths.mdPath, note); +} + export const getMdFilePath = (note: any): string => { return getFilePath(paths.mdPath, note); }; @@ -38,11 +43,11 @@ const clearDistDir = (dstPath: string): void => { }; export const getRelativeResourceDir = (note: any): string => { - return yarleOptions.haveEnexLevelResources ? './_resources' : `./_resources/${getResourceDir(paths.mdPath, note)}.resources`; + return yarleOptions.haveEnexLevelResources ? './_resources' : `./_resources/${getResourceDir(note)}.resources`; }; export const getAbsoluteResourceDir = (note: any): string => { - return yarleOptions.haveEnexLevelResources ? paths.resourcePath : `${paths.resourcePath}/${getResourceDir(paths.mdPath, note)}.resources`; + return yarleOptions.haveEnexLevelResources ? paths.resourcePath : `${paths.resourcePath}/${getResourceDir(note)}.resources`; }; const resourceDirClears = new Map();