-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21831a7
commit 706cca6
Showing
13 changed files
with
160 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./dist/next-image"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./dist/next-image"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "basehub", | ||
"description": "The first AI-native content hub.", | ||
"author": "JB <[email protected]>", | ||
"version": "6.0.7", | ||
"version": "7.0.0", | ||
"license": "MIT", | ||
"repository": "basehub-ai/basehub", | ||
"bugs": "https://github.com/basehub-ai/basehub/issues", | ||
|
@@ -33,7 +33,9 @@ | |
"analytics.js", | ||
"analytics.d.ts", | ||
"search.js", | ||
"search.d.ts" | ||
"search.d.ts", | ||
"next-image.js", | ||
"next-image.d.ts" | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { BaseHubImage, basehubImageLoader } from "./primitive"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { ImageLoaderProps, ImageProps } from "next/image"; | ||
import Image from "next/image"; | ||
|
||
const r2URL_deprecated = `https://basehub.earth`; | ||
const assetsURL = `https://assets.basehub.com`; | ||
|
||
export const basehubImageLoader = ({ | ||
src, | ||
width, | ||
quality, | ||
}: ImageLoaderProps) => { | ||
let url; | ||
|
||
try { | ||
url = new URL(src); | ||
} catch (error) { | ||
throw new Error(`Invalid BaseHub Image URL: ${src} | ||
Expected origin to be one of: | ||
- ${r2URL_deprecated} (deprecated) | ||
- ${assetsURL} | ||
`); | ||
} | ||
|
||
const params = [`width=${width}`, `quality=${quality || 90}`]; | ||
|
||
if (url.href.includes(r2URL_deprecated)) { | ||
if (url.pathname.startsWith("/cdn-cgi/image/")) { | ||
// image has existing params. we'll append the extra ones | ||
const [_empty, _cdnThing, _imageThing, currentParams = "", ...rest] = | ||
url.pathname.split("/"); | ||
const filteredParams = currentParams.split(",").filter((param) => { | ||
return ( | ||
!param.startsWith("width=") && | ||
!param.startsWith("quality=") && | ||
!param.startsWith("w=") && | ||
!param.startsWith("q=") | ||
); | ||
}); | ||
let newParams = filteredParams.join(",") + params.join(","); | ||
if (newParams.includes("format=") === false) { | ||
newParams += ",format=auto"; | ||
} | ||
url.pathname = `/cdn-cgi/image/${newParams}/${rest.join("/")}`; | ||
} else { | ||
// image has no existing params. we'll append the extra ones | ||
params.push("format=auto"); | ||
url.pathname = `/cdn-cgi/image/${params.join(",")}${url.pathname}`; | ||
} | ||
} else if (url.href.includes(assetsURL)) { | ||
// simpler! just append the params | ||
params.forEach((param) => { | ||
const [key, value] = param.split("="); | ||
if (!key || !value) return; | ||
url.searchParams.set(key, value); | ||
}); | ||
if (url.searchParams.has("format") === false) { | ||
url.searchParams.set("format", "auto"); | ||
} | ||
} | ||
|
||
return url.toString(); | ||
}; | ||
|
||
/** | ||
* Uses `next/image` under the hood. Just passes BaseHub's `loader` so that it utilizes BaseHub's Image Optimization. | ||
* | ||
* Literally just returns: | ||
* ```tsx | ||
* <Image {...props} loader={basehubImageLoader} /> | ||
* ``` | ||
*/ | ||
export const BaseHubImage = (props: ImageProps) => { | ||
"use client"; | ||
// eslint-disable-next-line jsx-a11y/alt-text | ||
return <Image {...props} loader={basehubImageLoader} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
# playground | ||
|
||
## 0.0.107 | ||
|
||
### Patch Changes | ||
|
||
- Updated dependencies | ||
- [email protected] | ||
|
||
## 0.0.106 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters