Skip to content

Commit

Permalink
Extract utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecRust committed Oct 28, 2023
1 parent 99f2c1e commit 11a1f97
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const isImageFile = (filename) => {
const normalizeString = (str) =>
str.replace(/\u0027/g, '_').replace(/\u0026/g, '_')

const filenameWithoutExtension = (filename) =>
filename.split('.').slice(0, -1).join('.')

const copyFile = async (src, dest, timestamp, verbose) => {
await fse.copy(src, dest)
utimesSync(dest, timestamp, timestamp)
Expand All @@ -27,11 +30,9 @@ const copyFile = async (src, dest, timestamp, verbose) => {
}

const buildCandidates = (files, currentFile, title) => {
const titleWithoutExtension = title.split('.').slice(0, -1).join('.')
const normalizedTitle = normalizeString(titleWithoutExtension)
const normalizedTitle = normalizeString(filenameWithoutExtension(title))
return files.filter((f) => {
const fileWithoutExtension = f.split('.').slice(0, -1).join('.')
const normalizedFile = normalizeString(fileWithoutExtension)
const normalizedFile = normalizeString(filenameWithoutExtension(f))
const ext = path.extname(f).toLowerCase()
return (
f !== currentFile &&
Expand Down

0 comments on commit 11a1f97

Please sign in to comment.