This repository has been archived by the owner on Apr 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: integrate open graph tags with helmet (#52)
Also, some of the tags can be rendered immediately. All others are updated or enriched with Helmet.
- Loading branch information
Showing
4 changed files
with
45 additions
and
39 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,16 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
export const propTypes = { | ||
/** The full name of the person who is displayed. */ | ||
name: PropTypes.string.isRequired, | ||
/** The username of the person who is displayed. */ | ||
username: PropTypes.string.isRequired, | ||
/** The absolute URL of the person's avatar. */ | ||
avatarUrl: PropTypes.string.isRequired, | ||
/** An optional description of this person. */ | ||
description: PropTypes.string, | ||
}; | ||
|
||
export const defaultProps = { | ||
description: '', | ||
}; |
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,36 +1,35 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Helmet from 'react-helmet'; | ||
import { findMentions } from 'src/providers/github'; | ||
import { propTypes, defaultProps } from './prop-type'; | ||
|
||
export default function UserMoleculeMeta(props) { | ||
const title = props.description | ||
? `${props.title} – ${props.description}` | ||
: props.title; | ||
? `${props.name} (${props.username}) – ${props.description}` | ||
: `${props.name} (${props.username})`; | ||
|
||
const keywords = props.description | ||
? props.keywords.concat(findMentions(props.description)) | ||
: props.keywords; | ||
? [props.name, props.username].concat(findMentions(props.description)) | ||
: [props.name, props.username]; | ||
|
||
const nameSegments = props.name.split(' '); | ||
const nameFirst = nameSegments.shift(); | ||
const nameLast = nameSegments.join(' '); | ||
|
||
return ( | ||
<Helmet> | ||
<title>{title}</title> | ||
<meta name="description" content={props.description} /> | ||
<meta name="keywords" content={keywords.join(', ')} /> | ||
<meta property="og:title" content={title} /> | ||
<meta property="og:description" content={props.description} /> | ||
<meta property="og:image" content={props.avatarUrl} /> | ||
<meta property="profile:username" content={props.username} /> | ||
<meta property="profile:first_name" content={nameFirst} /> | ||
<meta property="profile:last_name" content={nameLast} /> | ||
</Helmet> | ||
); | ||
} | ||
|
||
UserMoleculeMeta.propTypes = { | ||
/** The full page title to use. */ | ||
title: PropTypes.string.isRequired, | ||
/** A list of all keywords of this person, in relevant order. */ | ||
keywords: PropTypes.arrayOf(PropTypes.string), | ||
/** An optional description of this person. */ | ||
description: PropTypes.string, | ||
}; | ||
|
||
UserMoleculeMeta.defaultProps = { | ||
keywords: [], | ||
description: '', | ||
}; | ||
UserMoleculeMeta.propTypes = propTypes; | ||
UserMoleculeMeta.defaultProps = defaultProps; |
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