Skip to content

Commit ec4f8c2

Browse files
committed
finished v1
1 parent 7780c1c commit ec4f8c2

File tree

15 files changed

+3255
-1
lines changed

15 files changed

+3255
-1
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@delicious-simplicity/eslint-config"]
3+
}

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
publish:
10+
name: Publish to the NPM registry
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v2
15+
with:
16+
node-version: 14.x
17+
registry-url: https://registry.npmjs.org/
18+
19+
- name: Publish
20+
run: |
21+
yarn install --ignore-scripts
22+
yarn publish
23+
env:
24+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
cjs/
107+
esm/
108+
dist/
109+
types/

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.github
2+
.vscode
3+
.eslintrc
4+
.prettierrc

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"aaron-bond.better-comments",
4+
"dbaeumer.vscode-eslint",
5+
"esbenp.prettier-vscode"
6+
]
7+
}

.vscode/settings.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": true
4+
},
5+
"editor.defaultFormatter": "esbenp.prettier-vscode",
6+
"editor.formatOnSave": true,
7+
"eslint.alwaysShowStatus": true,
8+
"eslint.codeAction.showDocumentation": {
9+
"enable": true
10+
},
11+
"[javascript]": {
12+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
13+
},
14+
"[javascriptreact]": {
15+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
16+
},
17+
"[typescript]": {
18+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
19+
},
20+
"[typescriptreact]": {
21+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
22+
}
23+
}

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
# next-image-contentful-loader
1+
# @delicious-simplicity/next-image-contentful-loader
2+
3+
A comprehensive [Contentful](https://www.contentful.com/developers/docs/references/images-api) image loader for the [Next.js Image component](https://nextjs.org/docs/api-reference/next/image).
4+
5+
### Features
6+
7+
- Allows for native Contentful image params/options
8+
- Similar error boundaries as `next/image`
9+
- Additional options for managing the aspect ratio of requested images
10+
11+
### Usage
12+
13+
```tsx
14+
import Image from "next/image";
15+
import { contentfulLoader } from "@delicious-simplicity/next-image-contentful-loader";
16+
17+
const Component = ({ image }) => {
18+
return (
19+
<>
20+
<Image
21+
loader={(props) => contentfulLoader(props, { fit: "crop", ar: "1:1" })}
22+
src={image.url}
23+
alt={image.title}
24+
width={image.width}
25+
height={image.height}
26+
/>
27+
</>
28+
);
29+
};
30+
```
31+
32+
### Required packages
33+
34+
- [`next`](https://www.npmjs.com/package/next)

lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './parseAspectRatio';

lib/parseAspectRatio.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const parseAspectRatio = (ar: string) => {
2+
if (!ar.includes(':')) {
3+
throw new Error('Syntax not recognized for aspect ratio argument (ex: 4:3, 16:9)');
4+
}
5+
6+
const [w, h] = ar.split(':');
7+
return Number(h) / Number(w);
8+
};

0 commit comments

Comments
 (0)