mirror of
https://github.com/kremalicious/portfolio.git
synced 2025-01-03 10:25:00 +01:00
truncate meta description
This commit is contained in:
parent
03b39e3d1d
commit
ca1810392b
@ -2,11 +2,23 @@ import React from 'react'
|
|||||||
import Helmet from 'react-helmet'
|
import Helmet from 'react-helmet'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
function truncate(n, useWordBoundary) {
|
||||||
|
if (this.length <= n) {
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
const subString = this.substr(0, n - 1)
|
||||||
|
return (
|
||||||
|
(useWordBoundary
|
||||||
|
? subString.substr(0, subString.lastIndexOf(' '))
|
||||||
|
: subString) + '...'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const SEO = ({ project, meta }) => {
|
const SEO = ({ project, meta }) => {
|
||||||
const title = project.title ? project.title : meta.title
|
const title = project.title ? project.title : meta.title
|
||||||
const description = project.description
|
const description = project.description
|
||||||
? project.description
|
? truncate.apply(project.description, [320, true])
|
||||||
: meta.description
|
: truncate.apply(meta.description, [320, true])
|
||||||
const image = project.img
|
const image = project.img
|
||||||
? project.img.childImageSharp.twitterImage.src
|
? project.img.childImageSharp.twitterImage.src
|
||||||
: meta.img.childImageSharp.resize.src
|
: meta.img.childImageSharp.resize.src
|
||||||
|
Loading…
Reference in New Issue
Block a user