Skip to content

Commit

Permalink
Setup prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master committed Aug 14, 2024
1 parent 1ac5a91 commit 70edc2f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semi: false
singleQuote: true
htmlWhitespaceSensitivity: ignore
useTabs: true
printWidth: 100
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"devDependencies": {
"@types/loader-utils": "^2.0.6",
"@types/node": "20.x",
"prettier": "^3.3.3",
"typescript": "^5.5.4"
},
"dependencies": {
Expand All @@ -37,6 +38,8 @@
"sharp": "^0.33.4",
"webpack": "^5.93.0"
},
"workspaces": ["example"],
"workspaces": [
"example"
],
"type": "module"
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type NativeIdealImageOptions = Partial<LoaderOptions>

export default function pluginNativeIdealImage(
context: LoadContext,
options: NativeIdealImageOptions
options: NativeIdealImageOptions,
): Plugin<void> {
return {
name: 'docusaurus-plugin-native-ideal-image',
Expand Down
4 changes: 2 additions & 2 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default async function loader(this: LoaderContext<LoaderOptions>, content
async function createFiles(
context: LoaderContext<LoaderOptions>,
image: sharp.Sharp,
options: { formats: SupportedOutputTypes[]; sizes: number[] }
options: { formats: SupportedOutputTypes[]; sizes: number[] },
) {
const formats: OutputDataForFormat[] = []
for (const format of options.formats) {
Expand All @@ -160,7 +160,7 @@ async function processImage(
context: LoaderContext<LoaderOptions>,
image: sharp.Sharp,
size: number,
format: SupportedOutputTypes
format: SupportedOutputTypes,
) {
const resized = image.resize(size)
let output: sharp.Sharp
Expand Down
10 changes: 5 additions & 5 deletions src/theme/NativeIdealImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function NativeIdealImage(props: NativeIdealImageProps): JSX.Elem
const sources = enabled ? data.formats.slice(0, data.formats.length - 1) : undefined
const lastFormat = enabled ? data.formats[data.formats.length - 1]! : undefined

const sizesAttr = sizes ?? enabled ? 'auto' : undefined
const sizesAttr = (sizes ?? enabled) ? 'auto' : undefined
const isSingleImage = formats[0]?.srcSet.length === 1
const largestImage = formats[0]?.srcSet[formats[0]?.srcSet.length - 1]

Expand Down Expand Up @@ -61,18 +61,18 @@ export default function NativeIdealImage(props: NativeIdealImageProps): JSX.Elem
))}
<img
loading={loading ?? 'lazy'}
src={src ?? enabled ? (isSingleImage ? getSource(lastFormat!.srcSet) : undefined) : data}
src={(src ?? enabled) ? (isSingleImage ? getSource(lastFormat!.srcSet) : undefined) : data}
srcSet={
srcSet ?? enabled
(srcSet ?? enabled)
? !isSingleImage
? getSource(lastFormat!.srcSet)
: undefined
: undefined
}
sizes={sizesAttr}
width={width ?? (isSingleImage || sizesAttr === 'auto') ? largestImage?.width : undefined}
width={(width ?? (isSingleImage || sizesAttr === 'auto')) ? largestImage?.width : undefined}
height={
height ?? (isSingleImage || sizesAttr === 'auto') ? largestImage?.height : undefined
(height ?? (isSingleImage || sizesAttr === 'auto')) ? largestImage?.height : undefined
}
ref={imageEl}
{...propsRest}
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ declare module 'ideal-img!*' {

declare module '@theme/NativeIdealImage' {
export default function NativeIdealImage(
props: import('./index.ts').NativeIdealImageProps
props: import('./index.ts').NativeIdealImageProps,
): JSX.Element
}

0 comments on commit 70edc2f

Please sign in to comment.