Skip to content
Open
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
20 changes: 19 additions & 1 deletion src/common/filesystem/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import fs from 'fs'
import path from 'path'
import { isFile, isFile2, isSymbolicLink } from './index'
import { minimatch } from 'minimatch'
import { shell } from 'electron'

const isOsx = process.platform === 'darwin'
const isWindows = process.platform === 'win32'

export const MARKDOWN_EXTENSIONS = Object.freeze([
'markdown',
Expand All @@ -30,7 +32,7 @@ export const IMAGE_EXTENSIONS = Object.freeze(['jpeg', 'jpg', 'png', 'gif', 'svg
*/
export const hasMarkdownExtension = (filename) => {
if (!filename || typeof filename !== 'string') return false
return MARKDOWN_EXTENSIONS.some((ext) => filename.toLowerCase().endsWith(`.${ext}`))
return MARKDOWN_EXTENSIONS.some((ext) => resolveShortcut(filename).toLowerCase().endsWith(`.${ext}`))
}

/**
Expand Down Expand Up @@ -133,3 +135,19 @@ export const checkPathExcludePattern = (pathname, patterns) => {
}
return false
}

/**
* Returns the actual path pointed to by a shortcut file, or the original path if resolution fails.
* @param {string} The absolute path of the shortcut file.
*/
export const resolveShortcut = (shortcutPath) => {
try {
if (isWindows) {
return shell.readShortcutLink(shortcutPath)?.target || shortcutPath
} else {
return shortcutPath
}
} catch {
return shortcutPath
}
}
4 changes: 2 additions & 2 deletions src/main/filesystem/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import log from 'electron-log'
import iconv from 'iconv-lite'
import { LINE_ENDING_REG, LF_LINE_ENDING_REG, CRLF_LINE_ENDING_REG } from '../config'
import { isDirectory2 } from 'common/filesystem'
import { isMarkdownFile } from 'common/filesystem/paths'
import { isMarkdownFile, resolveShortcut } from 'common/filesystem/paths'
import { normalizeAndResolvePath, writeFile } from '../filesystem'
import { guessEncoding } from './encoding'

Expand Down Expand Up @@ -87,7 +87,7 @@ export const loadMarkdownFile = async (
// TODO: Use streams to not buffer the file multiple times and only guess
// encoding on the first 256/512 bytes.

let buffer = await fsPromises.readFile(path.resolve(pathname))
let buffer = await fsPromises.readFile(path.resolve(resolveShortcut(pathname)))

const encoding = guessEncoding(buffer, autoGuessEncoding)
const supported = iconv.encodingExists(encoding.encoding)
Expand Down