Skip to content

Commit 6663fc9

Browse files
mezzodeakosbalasko
andauthored
Add option to force POSIX path for link to original HTML fiile (#610)
Co-authored-by: Akos Balasko <[email protected]>
1 parent c360437 commit 6663fc9

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

src/YarleOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface YarleOptions {
1111
currentTemplate?: string;
1212
outputDir?: string;
1313
keepOriginalHtml?: boolean;
14+
posixHtmlPath?: boolean;
1415
isMetadataNeeded?: boolean;
1516
isNotebookNameNeeded?: boolean;
1617
isZettelkastenNeeded?: boolean;

src/ui/index.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,21 @@ <h5 class="info-text">General </h5>
216216
<option value="true">Yes</option>
217217
<option value="false" selected>No</option>
218218
</select>
219-
</div>
219+
</div>
220+
221+
<div class="form-group">
222+
<label for="posixHtmlPath" class="pure-checkbox">
223+
POSIX HTML Path
224+
<br>
225+
<div style='font-size: 12px;'>
226+
<i>(Use forward slashes in path to original HTML, even on Windows)</i>
227+
</div>
228+
</label>
229+
<select class="form-control configurationItem" name="posixHtmlPath" id="posixHtmlPath">
230+
<option value="true">Yes</option>
231+
<option value="false" selected>No</option>
232+
</select>
233+
</div>
220234

221235
<div class="form-group">
222236
<!--<input type="checkbox" value="false" id='addWebClips'> -->

src/ui/settingsMapper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ImageSizeFormat } from 'image-size-format';
22
import { CharacterMap } from './../CharacterMap';
33
import { YarleOptions } from './../YarleOptions';
4-
const store = require ('./store');
54
import { OutputFormat } from './../output-format';
65
import { TaskOutputFormat } from './../task-output-format';
76
import { SearchAndReplace } from 'models';
7+
8+
const store = require ('./store');
89
enum DefaultRootType {
910
array = 'array',
1011
object = 'object'
@@ -44,6 +45,7 @@ export const mapSettingsToYarleOptions = (): YarleOptions => {
4445
keepMDCharactersOfENNotes: store.get('keepMDCharactersOfENNotes') as boolean,
4546
monospaceIsCodeBlock: store.get('monospaceIsCodeBlock') as boolean,
4647
keepOriginalHtml: store.get('keepOriginalHtml') as boolean,
48+
posixHtmlPath: store.get('posixHtmlPath') as boolean,
4749
currentTemplate: store.get('currentTemplate') as string,
4850
resourcesDir: store.get('resourcesDir') as string,
4951
trimStartingTabs: store.get('trimStartingTabs') as boolean,

src/ui/store.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ const Store = require('electron-store');
33

44
const { OutputFormat } = require('../output-format');
55
const schema = {
6-
keepOriginalHtml: {
7-
type: 'boolean',
8-
default: true,
9-
},
6+
keepOriginalHtml: {
7+
type: 'boolean',
8+
default: true,
9+
},
10+
posixHtmlPath: { type: 'boolean', default: false },
1011
enexSources: {},
1112
// templateFile: {type: 'string'},
1213
outputDir: {type: 'string'},

src/utils/folder-utils.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import fsExtra from 'fs-extra';
21
import fs from 'fs';
3-
import * as path from 'path';
2+
import fsExtra from 'fs-extra';
3+
import * as path from 'path';
44

55
import { Path } from '../paths';
66
import { yarleOptions } from '../yarle';
@@ -9,6 +9,8 @@ import { getNoteFileName, getNoteName, getUniqueId, normalizeFilenameString } fr
99
import { loggerInfo } from './loggerInfo';
1010
import { OutputFormat } from './../output-format';
1111
import { RuntimePropertiesSingleton } from './../runtime-properties';
12+
import { getNoteFileName, getNoteName, getUniqueId, normalizeTitle } from './filename-utils';
13+
import { loggerInfo } from './loggerInfo';
1214

1315
export const paths: Path = {};
1416
const MAX_PATH = 249;
@@ -46,7 +48,7 @@ const getFilePath = (dstPath: string, note: any, extension: string): string => {
4648
const fileName = getNoteFileName(dstPath, note, extension);
4749
const fullFilePath = `${dstPath}${path.sep}${normalizeFilenameString(fileName)}`;
4850

49-
return fullFilePath.length <  MAX_PATH ? fullFilePath : truncateFilePath(note, fileName, fullFilePath);
51+
return fullFilePath.length < MAX_PATH ? fullFilePath : truncateFilePath(note, fileName, fullFilePath);
5052
};
5153

5254
export const getMdFilePath = (note: any): string => {
@@ -62,8 +64,11 @@ export const getHtmlFilePath = (note: any): string => {
6264

6365
export const getHtmlFileLink = (note: any): string => {
6466
const filePath = getHtmlFilePath(note);
65-
66-
return `.${filePath.slice(paths.resourcePath.lastIndexOf(path.sep))}`;
67+
const relativePath = `.${filePath.slice(paths.resourcePath.lastIndexOf(path.sep))}`;
68+
if (yarleOptions.posixHtmlPath && path.sep !== path.posix.sep) {
69+
return relativePath.split(path.sep).join(path.posix.sep);
70+
}
71+
return relativePath;
6772
};
6873

6974
const clearDistDir = (dstPath: string): void => {
@@ -153,7 +158,7 @@ export const setPaths = (enexSource: string): void => {
153158
}
154159

155160
fsExtra.mkdirsSync(paths.mdPath);
156-
if ((!yarleOptions.haveEnexLevelResources && !yarleOptions.haveGlobalResources) ||
161+
if ((!yarleOptions.haveEnexLevelResources && !yarleOptions.haveGlobalResources) ||
157162
yarleOptions.outputFormat === OutputFormat.LogSeqMD) {
158163
fsExtra.mkdirsSync(paths.resourcePath);
159164
}

src/yarle.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const defaultYarleOptions: YarleOptions = {
3131
enexSources: ['notebook.enex'],
3232
outputDir: './mdNotes',
3333
keepOriginalHtml: false,
34+
posixHtmlPath: false,
3435
isMetadataNeeded: false,
3536
isNotebookNameNeeded: false,
3637
isZettelkastenNeeded: false,
@@ -134,7 +135,7 @@ export const parseStream = async (options: YarleOptions, enexSource: string): Pr
134135
loggerInfo(`Notes processed: ${noteNumber}\n\n`);
135136
}
136137
noteAttributes = null;
137-
138+
138139
const runtimeProps = RuntimePropertiesSingleton.getInstance();
139140
const currentNotePath = runtimeProps.getCurrentNotePath();
140141
if (currentNotePath) {
@@ -151,7 +152,7 @@ export const parseStream = async (options: YarleOptions, enexSource: string): Pr
151152
updatedContent = language.tagProcess(fileContent, sortedTasks, taskPlaceholder, updatedContent)
152153

153154
fs.writeFileSync(currentNotePath, updatedContent);
154-
155+
155156
}
156157
}
157158
});

0 commit comments

Comments
 (0)