Updating deps and adding buildbase64.

This commit is contained in:
Bradley Shellnut 2022-01-27 20:59:21 -08:00
parent e979a83dca
commit 8200c102cd
2 changed files with 50 additions and 12 deletions

View file

@ -15,14 +15,14 @@
"babel-core": "^6.26.3",
"babel-plugin-styled-components": "^2.0.2",
"bcryptjs": "^2.4.3",
"cloudinary-build-url": "^0.2.1",
"dotenv": "^10.0.0",
"cloudinary-build-url": "^0.2.4",
"dotenv": "^14.3.2",
"escape-html": "^1.0.3",
"iron-session": "^6.0.5",
"jsonwebtoken": "^8.5.1",
"mongodb": "^4.3.0",
"mongoose": "^6.1.5",
"next": "^12.0.7",
"mongodb": "^4.3.1",
"mongoose": "^6.1.8",
"next": "^12.0.9",
"next-with-apollo": "^5.2.1",
"normalize.css": "^8.0.1",
"nprogress": "^0.2.0",
@ -31,16 +31,16 @@
"react-dom": "^17.0.2",
"react-icons": "^4.3.1",
"styled-components": "^5.3.3",
"swr": "^0.5.6",
"swr": "^1.2.0",
"waait": "^1.0.5"
},
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.7",
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@typescript-eslint/parser": "^5.9.0",
"@babel/core": "^7.16.12",
"@babel/preset-env": "^7.16.11",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"babel-eslint": "^10.1.0",
"eslint": "^8.6.0",
"eslint": "^8.7.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.3.0",
"eslint-config-wesbos": "^3.0.2",
@ -51,7 +51,7 @@
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"prettier": "^2.5.1",
"typescript": "^4.5.4"
"typescript": "^4.5.5"
},
"eslintConfig": {
"extends": [

38
utils/buildBase64Data.js Normal file
View file

@ -0,0 +1,38 @@
import { getPlaiceholder } from 'plaiceholder';
import { buildUrl } from 'cloudinary-build-url';
export default async function buildBase64Data(
imageName,
alt,
additionalProps = {}
) {
const folderName = process.env.PUBLIC_FOLDER_NAME;
const cloudName = process.env.PUBLIC_CLOUD_NAME;
let imagePath;
if (imageName && alt && additionalProps) {
imagePath = buildUrl(`${folderName}/${imageName}`, {
cloud: {
cloudName,
},
});
}
if (imagePath) {
try {
const { base64, img } = await getPlaiceholder(imagePath, { size: 10 });
return {
imageProps: {
...img,
blurDataURL: base64,
},
alt,
...additionalProps,
};
} catch (e) {
// Error getting plaiceholder
// throw new Error('Error creating plaiceholder base64 image');
}
}
return {};
}