Skip to content

Commit

Permalink
Add option to force POSIX path for link to original HTML fiile (#610)
Browse files Browse the repository at this point in the history
Co-authored-by: Akos Balasko <akos0215@gmail.com>
  • Loading branch information
mezzode and akosbalasko authored Apr 11, 2024
1 parent c360437 commit 6663fc9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/YarleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface YarleOptions {
currentTemplate?: string;
outputDir?: string;
keepOriginalHtml?: boolean;
posixHtmlPath?: boolean;
isMetadataNeeded?: boolean;
isNotebookNameNeeded?: boolean;
isZettelkastenNeeded?: boolean;
Expand Down
16 changes: 15 additions & 1 deletion src/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,21 @@ <h5 class="info-text">General </h5>
<option value="true">Yes</option>
<option value="false" selected>No</option>
</select>
</div>
</div>

<div class="form-group">
<label for="posixHtmlPath" class="pure-checkbox">
POSIX HTML Path
<br>
<div style='font-size: 12px;'>
<i>(Use forward slashes in path to original HTML, even on Windows)</i>
</div>
</label>
<select class="form-control configurationItem" name="posixHtmlPath" id="posixHtmlPath">
<option value="true">Yes</option>
<option value="false" selected>No</option>
</select>
</div>

<div class="form-group">
<!--<input type="checkbox" value="false" id='addWebClips'> -->
Expand Down
4 changes: 3 additions & 1 deletion src/ui/settingsMapper.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions src/ui/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down
17 changes: 11 additions & 6 deletions src/utils/folder-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fsExtra from 'fs-extra';
import fs from 'fs';

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'getNoteFileName'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'getNoteName'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'getUniqueId'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'loggerInfo'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'getNoteFileName'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'getNoteName'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'getUniqueId'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Module '"./filename-utils"' has no exported member 'normalizeTitle'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'loggerInfo'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'getNoteFileName'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'getNoteName'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'getUniqueId'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'loggerInfo'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'getNoteFileName'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'getNoteName'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'getUniqueId'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Module '"./filename-utils"' has no exported member 'normalizeTitle'.

Check failure on line 1 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'loggerInfo'.
import * as path from 'path';
import fsExtra from 'fs-extra';
import * as path from 'path';

import { Path } from '../paths';
import { yarleOptions } from '../yarle';
Expand All @@ -9,6 +9,8 @@ import { getNoteFileName, getNoteName, getUniqueId, normalizeFilenameString } fr
import { loggerInfo } from './loggerInfo';

Check failure on line 9 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'loggerInfo'.

Check failure on line 9 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'loggerInfo'.
import { OutputFormat } from './../output-format';
import { RuntimePropertiesSingleton } from './../runtime-properties';
import { getNoteFileName, getNoteName, getUniqueId, normalizeTitle } from './filename-utils';

Check failure on line 12 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'getNoteFileName'.

Check failure on line 12 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'getNoteName'.

Check failure on line 12 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'getUniqueId'.

Check failure on line 12 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Module '"./filename-utils"' has no exported member 'normalizeTitle'.

Check failure on line 12 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'getNoteFileName'.

Check failure on line 12 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'getNoteName'.

Check failure on line 12 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'getUniqueId'.

Check failure on line 12 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Module '"./filename-utils"' has no exported member 'normalizeTitle'.
import { loggerInfo } from './loggerInfo';

Check failure on line 13 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Duplicate identifier 'loggerInfo'.

Check failure on line 13 in src/utils/folder-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Duplicate identifier 'loggerInfo'.

export const paths: Path = {};
const MAX_PATH = 249;
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions src/yarle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const defaultYarleOptions: YarleOptions = {
enexSources: ['notebook.enex'],
outputDir: './mdNotes',
keepOriginalHtml: false,
posixHtmlPath: false,
isMetadataNeeded: false,
isNotebookNameNeeded: false,
isZettelkastenNeeded: false,
Expand Down Expand Up @@ -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) {
Expand All @@ -151,7 +152,7 @@ export const parseStream = async (options: YarleOptions, enexSource: string): Pr
updatedContent = language.tagProcess(fileContent, sortedTasks, taskPlaceholder, updatedContent)

fs.writeFileSync(currentNotePath, updatedContent);

}
}
});
Expand Down

0 comments on commit 6663fc9

Please sign in to comment.