Skip to content

Commit

Permalink
Better image handling on search results
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Dec 19, 2024
1 parent dcdfc0e commit ec6d0f8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 75 deletions.
10 changes: 8 additions & 2 deletions app/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ export const metadata = {
}
const Page = async (props: {searchParams?: Promise<Record<string, string>>}) => {
const searchParams = await props.searchParams
if (searchParams) {
// Honeypot check.
if (searchParams?.search) redirect("/search")
// Bot actor adding unwanted parameters.
delete searchParams.search
delete searchParams.q
if (Object.keys(searchParams).length > 0) redirect("/search")
}

// Honeypot check.
if (searchParams?.search) redirect("/search")
const [appId, indexName, apiKey] = await getAlgoliaCredential()

const initialState: IndexUiState = {refinementList: {}}
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@heroicons/react": "^2.2.0",
"@mui/base": "5.0.0-beta.67",
"@next/third-parties": "15.1.1",
"@next/third-parties": "15.1.2",
"@tailwindcss/container-queries": "^0.1.1",
"@types/node": "22.10.2",
"@types/react": "19.0.2",
Expand All @@ -31,7 +31,7 @@
"graphql-tag": "^2.12.6",
"html-entities": "^2.5.2",
"html-react-parser": "^5.2.1",
"next": "15.1.1",
"next": "15.1.2",
"plaiceholder": "^3.0.0",
"postcss": "^8.4.49",
"qs": "^6.13.1",
Expand All @@ -57,7 +57,7 @@
"@graphql-codegen/import-types-preset": "^3.0.0",
"@graphql-codegen/typescript-graphql-request": "^6.2.0",
"@graphql-codegen/typescript-operations": "^4.4.0",
"@next/bundle-analyzer": "15.1.1",
"@next/bundle-analyzer": "15.1.2",
"@storybook/addon-essentials": "^8.4.7",
"@storybook/addon-interactions": "^8.4.7",
"@storybook/addon-links": "^8.4.7",
Expand All @@ -70,7 +70,7 @@
"concurrently": "^9.1.0",
"encoding": "^0.1.13",
"eslint": "^9.17.0",
"eslint-config-next": "15.1.1",
"eslint-config-next": "15.1.2",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-storybook": "^0.11.1",
Expand Down
13 changes: 6 additions & 7 deletions src/components/algolia/hits/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export type DefaultAlgoliaHit = {

const DefaultHit = ({hit}: {hit: HitType<DefaultAlgoliaHit>}) => {
const hitUrl = new URL(hit.url)
const imageUrl = hit.photo
?.replace(hitUrl.origin, `${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}`)
.replace(/styles\/\w+\/public\//, "")
.replace(/\?.*/, "")

return (
<article className="flex justify-between gap-20 py-12 @container">
Expand All @@ -34,14 +38,9 @@ const DefaultHit = ({hit}: {hit: HitType<DefaultAlgoliaHit>}) => {
)}
</div>

{hit.photo && (
{imageUrl && (
<div className="relative hidden aspect-1 h-[150px] w-[150px] shrink-0 @6xl:block">
<Image
className="object-cover"
src={hit.photo.replace(hitUrl.origin, `${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}`)}
alt=""
fill
/>
<Image className="object-cover" src={imageUrl} alt="" fill sizes="300px" />
</div>
)}
</article>
Expand Down
124 changes: 62 additions & 62 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3160,96 +3160,96 @@ __metadata:
languageName: node
linkType: hard

"@next/bundle-analyzer@npm:15.1.1":
version: 15.1.1
resolution: "@next/bundle-analyzer@npm:15.1.1"
"@next/bundle-analyzer@npm:15.1.2":
version: 15.1.2
resolution: "@next/bundle-analyzer@npm:15.1.2"
dependencies:
webpack-bundle-analyzer: "npm:4.10.1"
checksum: 10c0/2a85db96b1b37a6273d7ee81978ffd11181335b2017c636bcccfc6bca3fdd9a7f1b3c45fba35b4b51f5ca844da76f604d5e8568c894fbdae5a14ff27548cc0d6
checksum: 10c0/bf1a1ef6554bd7c39b26cebe9a9e3c387d5874dc33278662732a269e106aa091255524e87c0fb43546918962450fcebee25a24c7c14d76afeb6c1268907b6246
languageName: node
linkType: hard

"@next/env@npm:15.1.1":
version: 15.1.1
resolution: "@next/env@npm:15.1.1"
checksum: 10c0/464ecb345eaf1170a863fff3f5bbed081982b1c1d70d617020d336aa7bdd6160a8dbb0a9cb4ba9d8c8189ae56aa026c2fa0d3b7f8365dc6ea00d5e9fba10c2f0
"@next/env@npm:15.1.2":
version: 15.1.2
resolution: "@next/env@npm:15.1.2"
checksum: 10c0/07f2b258bd0e8937bfd33515c48b920491d9c281de5f1fa58c4c222dc8e7e0ad3745ca6035bfef788f07d9a39c583bc18cb0cdfbaa8c2177761d9c2bbdd9592f
languageName: node
linkType: hard

"@next/eslint-plugin-next@npm:15.1.1":
version: 15.1.1
resolution: "@next/eslint-plugin-next@npm:15.1.1"
"@next/eslint-plugin-next@npm:15.1.2":
version: 15.1.2
resolution: "@next/eslint-plugin-next@npm:15.1.2"
dependencies:
fast-glob: "npm:3.3.1"
checksum: 10c0/7f01fdd0cadd8e72cc29b3f3a9848445352447d6327bbb1332ec55e387603b9cb584527c227a7bab86925a4f0b9aa0416493799d786f42fb4e6aa910dd93e72d
checksum: 10c0/9caf0763247cba8925d89596b7fdb21ec5d3cd0f5251e1e3f70c19815c7439cf358c694e59f0eedf08520c3a75c063395288af92661c75781bd7441de1063dc2
languageName: node
linkType: hard

"@next/swc-darwin-arm64@npm:15.1.1":
version: 15.1.1
resolution: "@next/swc-darwin-arm64@npm:15.1.1"
"@next/swc-darwin-arm64@npm:15.1.2":
version: 15.1.2
resolution: "@next/swc-darwin-arm64@npm:15.1.2"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard

"@next/swc-darwin-x64@npm:15.1.1":
version: 15.1.1
resolution: "@next/swc-darwin-x64@npm:15.1.1"
"@next/swc-darwin-x64@npm:15.1.2":
version: 15.1.2
resolution: "@next/swc-darwin-x64@npm:15.1.2"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard

"@next/swc-linux-arm64-gnu@npm:15.1.1":
version: 15.1.1
resolution: "@next/swc-linux-arm64-gnu@npm:15.1.1"
"@next/swc-linux-arm64-gnu@npm:15.1.2":
version: 15.1.2
resolution: "@next/swc-linux-arm64-gnu@npm:15.1.2"
conditions: os=linux & cpu=arm64 & libc=glibc
languageName: node
linkType: hard

"@next/swc-linux-arm64-musl@npm:15.1.1":
version: 15.1.1
resolution: "@next/swc-linux-arm64-musl@npm:15.1.1"
"@next/swc-linux-arm64-musl@npm:15.1.2":
version: 15.1.2
resolution: "@next/swc-linux-arm64-musl@npm:15.1.2"
conditions: os=linux & cpu=arm64 & libc=musl
languageName: node
linkType: hard

"@next/swc-linux-x64-gnu@npm:15.1.1":
version: 15.1.1
resolution: "@next/swc-linux-x64-gnu@npm:15.1.1"
"@next/swc-linux-x64-gnu@npm:15.1.2":
version: 15.1.2
resolution: "@next/swc-linux-x64-gnu@npm:15.1.2"
conditions: os=linux & cpu=x64 & libc=glibc
languageName: node
linkType: hard

"@next/swc-linux-x64-musl@npm:15.1.1":
version: 15.1.1
resolution: "@next/swc-linux-x64-musl@npm:15.1.1"
"@next/swc-linux-x64-musl@npm:15.1.2":
version: 15.1.2
resolution: "@next/swc-linux-x64-musl@npm:15.1.2"
conditions: os=linux & cpu=x64 & libc=musl
languageName: node
linkType: hard

"@next/swc-win32-arm64-msvc@npm:15.1.1":
version: 15.1.1
resolution: "@next/swc-win32-arm64-msvc@npm:15.1.1"
"@next/swc-win32-arm64-msvc@npm:15.1.2":
version: 15.1.2
resolution: "@next/swc-win32-arm64-msvc@npm:15.1.2"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard

"@next/swc-win32-x64-msvc@npm:15.1.1":
version: 15.1.1
resolution: "@next/swc-win32-x64-msvc@npm:15.1.1"
"@next/swc-win32-x64-msvc@npm:15.1.2":
version: 15.1.2
resolution: "@next/swc-win32-x64-msvc@npm:15.1.2"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard

"@next/third-parties@npm:15.1.1":
version: 15.1.1
resolution: "@next/third-parties@npm:15.1.1"
"@next/third-parties@npm:15.1.2":
version: 15.1.2
resolution: "@next/third-parties@npm:15.1.2"
dependencies:
third-party-capital: "npm:1.0.20"
peerDependencies:
next: ^13.0.0 || ^14.0.0 || ^15.0.0
react: ^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0
checksum: 10c0/efe0bc157067a36712d8e8519d56fd0c550fd4376793b69b79a163a931491f673f0cf10d461dd86a24496aeda288f9e2b294860b2cb88d22e8e13780e15885aa
checksum: 10c0/0224c8a0431ff27693a4c4f47220f114c7098b923572ac31855a15265d39ceba9130cb293ff8b3ca893a5f5030d1e1b94898c5259cda6d642d45e0e809b8a066
languageName: node
linkType: hard

Expand Down Expand Up @@ -7557,8 +7557,8 @@ __metadata:
"@graphql-codegen/typescript-operations": "npm:^4.4.0"
"@heroicons/react": "npm:^2.2.0"
"@mui/base": "npm:5.0.0-beta.67"
"@next/bundle-analyzer": "npm:15.1.1"
"@next/third-parties": "npm:15.1.1"
"@next/bundle-analyzer": "npm:15.1.2"
"@next/third-parties": "npm:15.1.2"
"@storybook/addon-essentials": "npm:^8.4.7"
"@storybook/addon-interactions": "npm:^8.4.7"
"@storybook/addon-links": "npm:^8.4.7"
Expand All @@ -7580,7 +7580,7 @@ __metadata:
drupal-jsonapi-params: "npm:^2.3.2"
encoding: "npm:^0.1.13"
eslint: "npm:^9.17.0"
eslint-config-next: "npm:15.1.1"
eslint-config-next: "npm:15.1.2"
eslint-config-prettier: "npm:^9.1.0"
eslint-plugin-prettier: "npm:^5.2.1"
eslint-plugin-storybook: "npm:^0.11.1"
Expand All @@ -7589,7 +7589,7 @@ __metadata:
graphql-tag: "npm:^2.12.6"
html-entities: "npm:^2.5.2"
html-react-parser: "npm:^5.2.1"
next: "npm:15.1.1"
next: "npm:15.1.2"
plaiceholder: "npm:^3.0.0"
postcss: "npm:^8.4.49"
prettier: "npm:^3.4.2"
Expand Down Expand Up @@ -8439,11 +8439,11 @@ __metadata:
languageName: node
linkType: hard

"eslint-config-next@npm:15.1.1":
version: 15.1.1
resolution: "eslint-config-next@npm:15.1.1"
"eslint-config-next@npm:15.1.2":
version: 15.1.2
resolution: "eslint-config-next@npm:15.1.2"
dependencies:
"@next/eslint-plugin-next": "npm:15.1.1"
"@next/eslint-plugin-next": "npm:15.1.2"
"@rushstack/eslint-patch": "npm:^1.10.3"
"@typescript-eslint/eslint-plugin": "npm:^5.4.2 || ^6.0.0 || ^7.0.0 || ^8.0.0"
"@typescript-eslint/parser": "npm:^5.4.2 || ^6.0.0 || ^7.0.0 || ^8.0.0"
Expand All @@ -8459,7 +8459,7 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: 10c0/d33574dd08c0ab4607280aa1ac2111828cd0c79b69eea3393a78a56c8147a46886646c199519e952df925ba94f735e0b0c58e2df902fb5e5d6bcb8423be71d78
checksum: 10c0/570775cc12ae044d85f9a44774aa5288695ab47b937e8a97cc707455daff4281e9f61823213bf3f7da9bd4067f8e6e2373ff74781aaa52a148e1a6c4e667763e
languageName: node
linkType: hard

Expand Down Expand Up @@ -11310,19 +11310,19 @@ __metadata:
languageName: node
linkType: hard

"next@npm:15.1.1":
version: 15.1.1
resolution: "next@npm:15.1.1"
"next@npm:15.1.2":
version: 15.1.2
resolution: "next@npm:15.1.2"
dependencies:
"@next/env": "npm:15.1.1"
"@next/swc-darwin-arm64": "npm:15.1.1"
"@next/swc-darwin-x64": "npm:15.1.1"
"@next/swc-linux-arm64-gnu": "npm:15.1.1"
"@next/swc-linux-arm64-musl": "npm:15.1.1"
"@next/swc-linux-x64-gnu": "npm:15.1.1"
"@next/swc-linux-x64-musl": "npm:15.1.1"
"@next/swc-win32-arm64-msvc": "npm:15.1.1"
"@next/swc-win32-x64-msvc": "npm:15.1.1"
"@next/env": "npm:15.1.2"
"@next/swc-darwin-arm64": "npm:15.1.2"
"@next/swc-darwin-x64": "npm:15.1.2"
"@next/swc-linux-arm64-gnu": "npm:15.1.2"
"@next/swc-linux-arm64-musl": "npm:15.1.2"
"@next/swc-linux-x64-gnu": "npm:15.1.2"
"@next/swc-linux-x64-musl": "npm:15.1.2"
"@next/swc-win32-arm64-msvc": "npm:15.1.2"
"@next/swc-win32-x64-msvc": "npm:15.1.2"
"@swc/counter": "npm:0.1.3"
"@swc/helpers": "npm:0.5.15"
busboy: "npm:1.6.0"
Expand Down Expand Up @@ -11367,7 +11367,7 @@ __metadata:
optional: true
bin:
next: dist/bin/next
checksum: 10c0/2908eb539b21a7149f1a5e1cf6ff15f2de1687cc6b445af6cc8b32b33f3d3befc3971c0548bf9bcacd1237e0d06d77b0a21e13d03e5393c3e7bf47280ea1288f
checksum: 10c0/320b949336fa41210ebe5cee66fce7edb4dc3474b438898590e43f6dfe30212620b090801d6f8cc4d37bfb54cb316680f65b58110cc8885f8c2b108a80e4ecee
languageName: node
linkType: hard

Expand Down

0 comments on commit ec6d0f8

Please sign in to comment.