From 6663fc9176df588c23b92d34ba4d9ffe88978bff Mon Sep 17 00:00:00 2001 From: Ash <6572225+mezzode@users.noreply.github.com> Date: Thu, 11 Apr 2024 04:39:00 -0700 Subject: [PATCH] Add option to force POSIX path for link to original HTML fiile (#610) Co-authored-by: Akos Balasko --- src/YarleOptions.ts | 1 + src/ui/index.html | 16 +++++++++++++++- src/ui/settingsMapper.ts | 4 +++- src/ui/store.js | 9 +++++---- src/utils/folder-utils.ts | 17 +++++++++++------ src/yarle.ts | 5 +++-- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/YarleOptions.ts b/src/YarleOptions.ts index 54ac70cb..6d90c120 100644 --- a/src/YarleOptions.ts +++ b/src/YarleOptions.ts @@ -11,6 +11,7 @@ export interface YarleOptions { currentTemplate?: string; outputDir?: string; keepOriginalHtml?: boolean; + posixHtmlPath?: boolean; isMetadataNeeded?: boolean; isNotebookNameNeeded?: boolean; isZettelkastenNeeded?: boolean; diff --git a/src/ui/index.html b/src/ui/index.html index 82b52e60..9303452d 100644 --- a/src/ui/index.html +++ b/src/ui/index.html @@ -216,7 +216,21 @@
General
- + + +
+ + +
diff --git a/src/ui/settingsMapper.ts b/src/ui/settingsMapper.ts index 29fff298..38af4836 100644 --- a/src/ui/settingsMapper.ts +++ b/src/ui/settingsMapper.ts @@ -1,10 +1,11 @@ import { ImageSizeFormat } from 'image-size-format'; import { CharacterMap } from './../CharacterMap'; import { YarleOptions } from './../YarleOptions'; -const store = require ('./store'); import { OutputFormat } from './../output-format'; import { TaskOutputFormat } from './../task-output-format'; import { SearchAndReplace } from 'models'; + +const store = require ('./store'); enum DefaultRootType { array = 'array', object = 'object' @@ -44,6 +45,7 @@ export const mapSettingsToYarleOptions = (): YarleOptions => { keepMDCharactersOfENNotes: store.get('keepMDCharactersOfENNotes') as boolean, monospaceIsCodeBlock: store.get('monospaceIsCodeBlock') as boolean, keepOriginalHtml: store.get('keepOriginalHtml') as boolean, + posixHtmlPath: store.get('posixHtmlPath') as boolean, currentTemplate: store.get('currentTemplate') as string, resourcesDir: store.get('resourcesDir') as string, trimStartingTabs: store.get('trimStartingTabs') as boolean, diff --git a/src/ui/store.js b/src/ui/store.js index 10dbd566..05d0dd0e 100644 --- a/src/ui/store.js +++ b/src/ui/store.js @@ -3,10 +3,11 @@ const Store = require('electron-store'); const { OutputFormat } = require('../output-format'); const schema = { - keepOriginalHtml: { - type: 'boolean', - default: true, - }, + keepOriginalHtml: { + type: 'boolean', + default: true, + }, + posixHtmlPath: { type: 'boolean', default: false }, enexSources: {}, // templateFile: {type: 'string'}, outputDir: {type: 'string'}, diff --git a/src/utils/folder-utils.ts b/src/utils/folder-utils.ts index 7bf5f304..cf43d98c 100644 --- a/src/utils/folder-utils.ts +++ b/src/utils/folder-utils.ts @@ -1,6 +1,6 @@ -import fsExtra from 'fs-extra'; import fs from 'fs'; -import * as path from 'path'; +import fsExtra from 'fs-extra'; +import * as path from 'path'; import { Path } from '../paths'; import { yarleOptions } from '../yarle'; @@ -9,6 +9,8 @@ import { getNoteFileName, getNoteName, getUniqueId, normalizeFilenameString } fr import { loggerInfo } from './loggerInfo'; import { OutputFormat } from './../output-format'; import { RuntimePropertiesSingleton } from './../runtime-properties'; +import { getNoteFileName, getNoteName, getUniqueId, normalizeTitle } from './filename-utils'; +import { loggerInfo } from './loggerInfo'; export const paths: Path = {}; const MAX_PATH = 249; @@ -46,7 +48,7 @@ const getFilePath = (dstPath: string, note: any, extension: string): string => { const fileName = getNoteFileName(dstPath, note, extension); const fullFilePath = `${dstPath}${path.sep}${normalizeFilenameString(fileName)}`; - return fullFilePath.length <  MAX_PATH ? fullFilePath : truncateFilePath(note, fileName, fullFilePath); + return fullFilePath.length < MAX_PATH ? fullFilePath : truncateFilePath(note, fileName, fullFilePath); }; export const getMdFilePath = (note: any): string => { @@ -62,8 +64,11 @@ export const getHtmlFilePath = (note: any): string => { export const getHtmlFileLink = (note: any): string => { const filePath = getHtmlFilePath(note); - - return `.${filePath.slice(paths.resourcePath.lastIndexOf(path.sep))}`; + const relativePath = `.${filePath.slice(paths.resourcePath.lastIndexOf(path.sep))}`; + if (yarleOptions.posixHtmlPath && path.sep !== path.posix.sep) { + return relativePath.split(path.sep).join(path.posix.sep); + } + return relativePath; }; const clearDistDir = (dstPath: string): void => { @@ -153,7 +158,7 @@ export const setPaths = (enexSource: string): void => { } fsExtra.mkdirsSync(paths.mdPath); - if ((!yarleOptions.haveEnexLevelResources && !yarleOptions.haveGlobalResources) || + if ((!yarleOptions.haveEnexLevelResources && !yarleOptions.haveGlobalResources) || yarleOptions.outputFormat === OutputFormat.LogSeqMD) { fsExtra.mkdirsSync(paths.resourcePath); } diff --git a/src/yarle.ts b/src/yarle.ts index 21d48215..3244c432 100644 --- a/src/yarle.ts +++ b/src/yarle.ts @@ -31,6 +31,7 @@ export const defaultYarleOptions: YarleOptions = { enexSources: ['notebook.enex'], outputDir: './mdNotes', keepOriginalHtml: false, + posixHtmlPath: false, isMetadataNeeded: false, isNotebookNameNeeded: false, isZettelkastenNeeded: false, @@ -134,7 +135,7 @@ export const parseStream = async (options: YarleOptions, enexSource: string): Pr loggerInfo(`Notes processed: ${noteNumber}\n\n`); } noteAttributes = null; - + const runtimeProps = RuntimePropertiesSingleton.getInstance(); const currentNotePath = runtimeProps.getCurrentNotePath(); if (currentNotePath) { @@ -151,7 +152,7 @@ export const parseStream = async (options: YarleOptions, enexSource: string): Pr updatedContent = language.tagProcess(fileContent, sortedTasks, taskPlaceholder, updatedContent) fs.writeFileSync(currentNotePath, updatedContent); - + } } });