import React, { Fragment } from 'react'
import PropTypes from 'prop-types'
import Head from 'next/head'

const SITE_NAME = 'geo.data.gouv.fr'

const Meta = ({ title, description, images }) => (
  <Head>
    <title>{title} | {SITE_NAME}</title>
    <meta name='twitter:title' content={title} />
    <meta property='og:title' content={title} />

    {description && (
      <Fragment>
        <meta name='description' content={description} />
        <meta name='twitter:description' content={description} />
        <meta name='og:description' content={description} />
      </Fragment>
    )}

    {images && images.length > 0 && images.map((image, idx) => (
      <Fragment key={idx}>
        <meta name='twitter:image' content={image} />
        <meta name='og:image' content={image} />
      </Fragment>
    ))}
  </Head>
)

Meta.propTypes = {
  title: PropTypes.string.isRequired,
  description: PropTypes.string,
  images: PropTypes.arrayOf(PropTypes.string)
}

export default Meta

@@ -96,16 +96,60 @@
 xt/head'
+%0Aimport prune from 'underscore.string/prune'
 %0A%0Aconst 
@@ -454,32 +454,38 @@
 ption' content=%7B
+prune(
 description%7D /%3E%0A
@@ -471,32 +471,43 @@
 rune(description
+, 160, '%E2%80%A6')
 %7D /%3E%0A        %3Cme
@@ -537,32 +537,38 @@
 ption' content=%7B
+prune(
 description%7D /%3E%0A
@@ -554,32 +554,43 @@
 rune(description
+, 300, '%E2%80%A6')
 %7D /%3E%0A        %3Cme
@@ -623,16 +623,22 @@
 ontent=%7B
+prune(
 descript
@@ -640,16 +640,27 @@
 cription
+, 160, '%E2%80%A6')
 %7D /%3E%0A   

Truncate meta descriptions