-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SALAD-22312] WebApp - Add og meta tags for store and rewards (#1212)
- Loading branch information
Showing
5 changed files
with
104 additions
and
49 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,27 @@ | ||
import { useEffect } from 'react' | ||
|
||
const defaultOgMetaTags: Record<string, string> = { | ||
url: window.location.href, | ||
type: 'website', | ||
image: `${window.location.origin}/og-official-store.png`, | ||
'image:alt': 'Salad', | ||
} | ||
|
||
export const useAddOgMetaTags = (ogMetaTags: Record<string, string>) => { | ||
useEffect(() => { | ||
const combinedOgMetaTags = { ...defaultOgMetaTags, ...ogMetaTags } | ||
Object.keys(combinedOgMetaTags).forEach((ogMetaTagPropertyName) => { | ||
const ogMetaTag = document.querySelector(`meta[property='og:${ogMetaTagPropertyName}']`) | ||
const ogMetaTagContent = combinedOgMetaTags[ogMetaTagPropertyName] as string | ||
|
||
if (ogMetaTag) { | ||
ogMetaTag.setAttribute('content', ogMetaTagContent) | ||
} else { | ||
const newOgMetaTag = document.createElement('meta') | ||
newOgMetaTag.setAttribute('property', `og:${ogMetaTagPropertyName}`) | ||
newOgMetaTag.setAttribute('content', ogMetaTagContent) | ||
document.head.appendChild(newOgMetaTag) | ||
} | ||
}) | ||
}, [ogMetaTags]) | ||
} |
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