mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 19:41:39 +08:00
Applying Review Findings
- Changed logic to check if the image path is an assets path. - Renamed funciton. - Removed 'async' and 'await' keyword.
This commit is contained in:
parent
495ae36b48
commit
aad0a01880
@ -101,7 +101,7 @@ import Printer from '@/services/printService'
|
|||||||
import { SpellcheckerLanguageCommand } from '@/commands'
|
import { SpellcheckerLanguageCommand } from '@/commands'
|
||||||
import { SpellChecker } from '@/spellchecker'
|
import { SpellChecker } from '@/spellchecker'
|
||||||
import { isOsx, animatedScrollTo } from '@/util'
|
import { isOsx, animatedScrollTo } from '@/util'
|
||||||
import { IsIdenticalImagePath, moveImageToFolder, moveToRelativeFolder, uploadImage } from '@/util/fileSystem'
|
import { getRelativeImagePathIfIdentical, moveImageToFolder, moveToRelativeFolder, uploadImage } from '@/util/fileSystem'
|
||||||
import { guessClipboardFilePath } from '@/util/clipboard'
|
import { guessClipboardFilePath } from '@/util/clipboard'
|
||||||
import { getCssForOptions, getHtmlToc } from '@/util/pdf'
|
import { getCssForOptions, getHtmlToc } from '@/util/pdf'
|
||||||
import { addCommonStyle, setEditorWidth } from '@/util/theme'
|
import { addCommonStyle, setEditorWidth } from '@/util/theme'
|
||||||
@ -738,7 +738,7 @@ export default {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'folder': {
|
case 'folder': {
|
||||||
const { identical, relPath } = await IsIdenticalImagePath(relativeBasePath, resolvedImageRelativeDirectoryName, image)
|
const { identical, relPath } = getRelativeImagePathIfIdentical(relativeBasePath, resolvedImageRelativeDirectoryName, image)
|
||||||
if (identical && isTabSavedOnDisk && imagePreferRelativeDirectory) {
|
if (identical && isTabSavedOnDisk && imagePreferRelativeDirectory) {
|
||||||
destImagePath = relPath
|
destImagePath = relPath
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,7 +6,7 @@ import cp from 'child_process'
|
|||||||
import { tmpdir } from 'os'
|
import { tmpdir } from 'os'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { Octokit } from '@octokit/rest'
|
import { Octokit } from '@octokit/rest'
|
||||||
import { isImageFile } from 'common/filesystem/paths'
|
import { isChildOfDirectory, isImageFile } from 'common/filesystem/paths'
|
||||||
import { isWindows } from './index'
|
import { isWindows } from './index'
|
||||||
|
|
||||||
export const create = async (pathname, type) => {
|
export const create = async (pathname, type) => {
|
||||||
@ -34,14 +34,14 @@ export const getContentHash = content => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check two image paths are identical
|
* If the two paths are identical, return relative image file path
|
||||||
*
|
*
|
||||||
* @param {String} cwd The relative base path (project root or full folder path of opened file).
|
* @param {String} cwd The relative base path (project root or full folder path of opened file).
|
||||||
* @param {String} relativeName The relative directory name of image assets.
|
* @param {String} relativeName The relative directory name of image assets.
|
||||||
* @param {String} srcImagePath The source image file path.
|
* @param {String} srcImagePath The source image file path.
|
||||||
* @returns {{identical: boolean, relPath: string}} Returns the idencial or not and relativePath of image file.
|
* @returns {{identical: boolean, relPath: string}} Returns the idencial or not and relativePath of image file.
|
||||||
*/
|
*/
|
||||||
export const IsIdenticalImagePath = async (cwd, relativeName, srcImagePath) => {
|
export const getRelativeImagePathIfIdentical = (cwd, relativeName, srcImagePath) => {
|
||||||
let identical = false
|
let identical = false
|
||||||
let relPath = ''
|
let relPath = ''
|
||||||
if (typeof srcImagePath !== 'string') {
|
if (typeof srcImagePath !== 'string') {
|
||||||
@ -58,9 +58,8 @@ export const IsIdenticalImagePath = async (cwd, relativeName, srcImagePath) => {
|
|||||||
// Path combination:
|
// Path combination:
|
||||||
// - root directory + relative directory name
|
// - root directory + relative directory name
|
||||||
const absAssetsDirPath = path.resolve(cwd, relativeName)
|
const absAssetsDirPath = path.resolve(cwd, relativeName)
|
||||||
const absAssetsFilePath = path.resolve(absAssetsDirPath, path.basename(srcImagePath))
|
const absAssetsFilePath = path.resolve(cwd, srcImagePath)
|
||||||
if (absAssetsFilePath === srcImagePath) {
|
if (isChildOfDirectory(absAssetsDirPath, absAssetsFilePath)) {
|
||||||
// Find relative path between given file and saved image.
|
|
||||||
relPath = path.relative(cwd, srcImagePath)
|
relPath = path.relative(cwd, srcImagePath)
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
// Use forward slashes for better compatibility with websites.
|
// Use forward slashes for better compatibility with websites.
|
||||||
|
Loading…
Reference in New Issue
Block a user