Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔍️ Add dynamic meta tags to active view #409

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"@semantic-ui-react/css-patch": "^1.1.1",
"@types/leaflet": "^1.8.0",
"@types/react": "^18.0.12",
"@types/react-helmet": "^6.1.5",
"@types/styled-components": "^5.1.24",
"dayjs": "^1.11.0",
"leaflet": "^1.9.1",
"pure-react-carousel": "^1.29.0",
"react": "^18.2.0",
"react-app-polyfill": "^3.0.0",
"react-helmet": "^6.1.0",
"react-leaflet": "^3.1.0",
"react-markdown": "^8.0.1",
"react-refresh": "^0.14.0",
Expand Down
30 changes: 30 additions & 0 deletions src/components/DynamicMetaTags.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { FC } from 'react'
import { Helmet } from 'react-helmet'
import { Ticker } from '../lib/types'

interface Props {
ticker: Ticker
}

const DynamicMetaTags: FC<Props> = ({ ticker }) => {
return (
<Helmet>
<meta content={ticker.description} name="description" />
<meta content="summary" name="twitter:card" />
<meta content={ticker.title} name="twitter:title" />
<meta content={ticker.description} name="twitter:description" />
<meta
content={
ticker.information.twitter ? `@${ticker.information.twitter}` : ''
}
name="twitter:site"
/>
<meta content={ticker.title} property="og:title" />
<meta content="website" property="og:type" />
<meta content={window.location.href} property="og:url" />
<meta content={ticker.description} property="og:description" />
</Helmet>
)
}

export default DynamicMetaTags
17 changes: 9 additions & 8 deletions src/views/ActiveView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { isMobile } from '../lib/helper'
import About from '../components/About'
import ReloadInfo from '../components/ReloadInfo'
import MessageList from '../components/MessageList'
import DynamicMetaTags from '../components/DynamicMetaTags'

const Wrapper = styled(Container)`
padding: ${spacing.normal} 0;
Expand All @@ -23,13 +24,11 @@ interface Props {

type StickyContext = Document | Window | HTMLElement | React.Ref<HTMLElement>

const ActiveView: FC<Props> = props => {
const ActiveView: FC<Props> = ({ ticker, refreshInterval }) => {
const [stickyContext, setStickyContext] = useState<StickyContext>()

const headline =
props.ticker === null || props.ticker.title == undefined
? 'Ticker'
: props.ticker.title
ticker === null || ticker.title == undefined ? 'Ticker' : ticker.title

const handleContextRef = useCallback((stickyContextValue: StickyContext) => {
setStickyContext(stickyContextValue)
Expand All @@ -38,28 +37,30 @@ const ActiveView: FC<Props> = props => {
if (isMobile()) {
return (
<Wrapper>
<About isModal ticker={props.ticker} />
<DynamicMetaTags ticker={ticker} />
<About isModal ticker={ticker} />
{headline && <HeaderWrapper content={headline} size={'large'} />}
<ReloadInfo />
<MessageList refreshInterval={props.refreshInterval} />
<MessageList refreshInterval={refreshInterval} />
</Wrapper>
)
}

return (
<Wrapper>
<DynamicMetaTags ticker={ticker} />
{headline && <HeaderWrapper content={headline} size={'large'} />}
<ReloadInfo />
<Grid divided={'vertically'}>
<Grid.Row columns={2}>
<Grid.Column computer={10} tablet={10}>
<div ref={handleContextRef}>
<MessageList refreshInterval={props.refreshInterval} />
<MessageList refreshInterval={refreshInterval} />
</div>
</Grid.Column>
<Grid.Column computer={6} tablet={6}>
<Sticky context={stickyContext} offset={30}>
<About ticker={props.ticker} />
<About ticker={ticker} />
</Sticky>
</Grid.Column>
</Grid.Row>
Expand Down
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,13 @@
dependencies:
"@types/react" "*"

"@types/react-helmet@^6.1.5":
version "6.1.5"
resolved "https://registry.yarnpkg.com/@types/react-helmet/-/react-helmet-6.1.5.tgz#35f89a6b1646ee2bc342a33a9a6c8777933f9083"
integrity sha512-/ICuy7OHZxR0YCAZLNg9r7I9aijWUWvxaPR6uTuyxe8tAj5RL4Sw1+R6NhXUtOsarkGYPmaHdBDvuXh2DIN/uA==
dependencies:
"@types/react" "*"

"@types/react@*", "@types/react@^18.0.12":
version "18.0.12"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.12.tgz#cdaa209d0a542b3fcf69cf31a03976ec4cdd8840"
Expand Down Expand Up @@ -7465,11 +7472,21 @@ react-error-overlay@^6.0.11:
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.11.tgz#92835de5841c5cf08ba00ddd2d677b6d17ff9adb"
integrity sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==

react-fast-compare@^3.0.1:
react-fast-compare@^3.0.1, react-fast-compare@^3.1.1:
version "3.2.0"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb"
integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==

react-helmet@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/react-helmet/-/react-helmet-6.1.0.tgz#a750d5165cb13cf213e44747502652e794468726"
integrity sha512-4uMzEY9nlDlgxr61NL3XbKRy1hEkXmKNXhjbAIOVw5vcFrsdYbH2FEwcNyWvWinl103nXgzYNlns9ca+8kFiWw==
dependencies:
object-assign "^4.1.1"
prop-types "^15.7.2"
react-fast-compare "^3.1.1"
react-side-effect "^2.1.0"

react-is@^16.13.1, react-is@^16.6.3, react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
Expand Down Expand Up @@ -7526,6 +7543,11 @@ react-refresh@^0.14.0:
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e"
integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==

react-side-effect@^2.1.0:
version "2.1.2"
resolved "https://registry.yarnpkg.com/react-side-effect/-/react-side-effect-2.1.2.tgz#dc6345b9e8f9906dc2eeb68700b615e0b4fe752a"
integrity sha512-PVjOcvVOyIILrYoyGEpDN3vmYNLdy1CajSFNt4TDsVQC5KpTijDvWVoR+/7Rz2xT978D8/ZtFceXxzsPwZEDvw==

react@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
Expand Down