Skip to content

Commit

Permalink
fix: remove sharp (#18)
Browse files Browse the repository at this point in the history
* feat: Convert buffer image to PNG format

* feat: Convert buffer-formatted file to a different extension

Downloaded the 'file-type' library to determine the file extension in a buffer-formatted file

* fix: Changed the path for images

* chore: 사용하지 않는 sharp 라이브러리 삭제

* fix: sharp로 변환하는 대신 기존 fs.writeFile 을 활용

* chore : sharp 제거

* fix all script

---------

Co-authored-by: Eunjae Lee <[email protected]>
  • Loading branch information
JEM1224 and eunjae-lee authored Jan 17, 2024
1 parent bc15218 commit ae136f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"package": "ncc build --source-map --license licenses.txt",
"test": "jest",
"test:watch": "jest --watch",
"readd-sharp": "yarn remove sharp && yarn add sharp --platform=linux --arch=x64 sharp",
"all": "yarn readd-sharp && yarn build && yarn format && yarn lint && yarn package && yarn test",
"all": "yarn build && yarn format && yarn lint && yarn package && yarn test",
"deploy": "./scripts/deploy.mjs"
},
"repository": {
Expand All @@ -35,7 +34,6 @@
"file-type": "^19.0.0",
"gray-matter": "^4.0.3",
"mkdirp": "^2.1.3",
"sharp": "^0.33.2",
"yaml": "^2.2.1"
},
"devDependencies": {
Expand Down
23 changes: 4 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import download from 'download'
import dayjs from 'dayjs'
import {extractImages} from './extract-images'
import {formatFrontMatterValue} from './format'
import sharp from 'sharp'
import {fileTypeFromBuffer} from 'file-type'

async function run(): Promise<void> {
Expand Down Expand Up @@ -117,25 +116,11 @@ async function run(): Promise<void> {
if (imageExt === '') {
const buffer = fs.readFileSync(imagePath)
const imageType = await fileTypeFromBuffer(buffer)
sharp.cache(false)

if (
imageType !== undefined &&
sharp.format.hasOwnProperty(imageType?.ext)
) {
if (imageType.ext === 'gif') {
await sharp(imagePath, {
limitInputPixels: false,
animated: true,
density: 1
}).toFile(`${imagePath}.${imageType.ext}`)
} else {
await sharp(imagePath).toFile(`${imagePath}.${imageType.ext}`)
}
newImageFilename += `.${imageType.ext}`
fs.unlinkSync(imagePath)
}
newImageFilename += `.${imageType?.ext}`
fs.writeFileSync(path.join(dirname, newImageFilename), buffer)
fs.unlinkSync(imagePath)
}

bodyText = bodyText.replace(
image.match,
`![${image.alt}](./${newImageFilename}${
Expand Down

0 comments on commit ae136f3

Please sign in to comment.