Skip to content

Commit

Permalink
修复缩略图问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ziofat committed Jun 21, 2024
1 parent f6e7d39 commit 26bda42
Show file tree
Hide file tree
Showing 3 changed files with 591 additions and 225 deletions.
25 changes: 15 additions & 10 deletions apps/website/.vuepress/scan.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sync } from 'fast-glob';
import { resolve } from 'path';
import sharp from 'sharp';
import { writeFileSync } from 'fs';
import Jimp from "jimp";
import { CATEGORIES } from './categories';

Object.entries(sync('./recipes/**/*.md').reduce((acc, file) => {
Expand All @@ -21,12 +21,17 @@ Object.entries(sync('./recipes/**/*.md').reduce((acc, file) => {

writeFileSync(resolve(__dirname, '../recipes/README.md'), `---\nfinder: all\n---`, 'utf-8');

// Promise.all(sync('./.vuepress/public/recipe-static/*.jpg').map((file) => new Promise((r) => {
// const path = resolve(__dirname, `.${file}`);
// sharp(path)
// .resize(320)
// .toFile(path.replace('recipe-static', 'thumbnail'))
// .then(r);
// }))).then(() => {
// console.log('files generated');
// });
Promise.all(sync('./.vuepress/public/recipe-static/*.jpg').map((file) => new Promise((r) => {
const path = resolve(__dirname, `.${file}`);
Jimp.read(path).then((image) => {
image
.resize(320, 320)
.quality(60)
.write(path.replace('recipe-static', 'thumbnail'));
r(true);
}).catch(e => {
console.error(e);
})
}))).then(() => {
console.log('files generated');
});
3 changes: 1 addition & 2 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"vuepress": "2.0.0-rc.9",
"vue": "^3.2.31",
"sass-loader": "^14.2.1",
"sharp": "^0.33.4"

"jimp": "^0.22.12"
},
"devDependencies": {
"@vuepress/bundler-webpack": "2.0.0-rc.9",
Expand Down
Loading

0 comments on commit 26bda42

Please # to comment.