Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to force POSIX path for link to original HTML fiile #610

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
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';
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;
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