示例#1
0
export default (petition = {}) => {
  const petitionImage = getPetitionImage(petition);
  const petitionImageObject = petition.images && petition.images[0];
  const petitionImageSrc = petitionImage && petitionImage.src;

  return assign({}, {
    '@context': 'http://schema.org',
    '@type': 'Question',
    'name': petition.title,
    'upvoteCount': petition.supporters.amount,
    'text': petition.description,
    'dateCreated': getPetitionStartDate(petition.dc || {}),
    'author': getPetitionOwner(petition),
    'suggestedAnswer': {
      '@type': 'Answer',
      'upvoteCount': petition.supporters.amount,
      'text': petition.suggested_solution,
      'dateCreated': getPetitionStartDate(petition.dc || {}),
      'author': getPetitionOwner(petition)
    }
  }, petitionImageSrc ? {
    image: {
      '@type': 'ImageObject',
      'url': createSignedImageUrl(petitionImageSrc, { w: 800 }),
      ...imageDimensionsForWidth(petitionImageObject, 800)
    }
  } : {});
};
  it('rounds image dimensions', () => {
    const info = {
      width: 400,
      height: 273
    };

    const actual = imageDimensionsForWidth({ data: { info } }, 300);
    const expected = {
      width: 300,
      height: 205
    };

    assert.deepEqual(actual, expected);
  });
      it('returns correct dimensions', () => {
        const info = {
          width: 1200,
          height: 720
        };

        const actual = imageDimensionsForWidth({ data: { info } }, 800);
        const expected = {
          width: 800,
          height: 480
        };

        assert.deepEqual(actual, expected);
      });
export default (petition = {}) => {
  const petitionImage = getPetitionImage(petition);
  const petitionImageObject = petition.images && petition.images[0];
  const petitionImageSrc = petitionImage ? petitionImage.src : '';
  const twitterCardImage = createSignedImageUrl(petitionImageSrc, { w: 800 });
  const imageDimensions = twitterCardImage ? imageDimensionsForWidth(petitionImageObject, 800) : {};

  return [
    {
      name: 'twitter:card',
      content: 'summary'
    },
    {
      name: 'twitter:site',
      content: settings.twitterAccount
        ? '@' + settings.twitterAccount
        : ''
    },
    {
      name: 'twitter:title',
      content: petition.title
    },
    {
      name: 'twitter:image',
      content: twitterCardImage
    },
    {
      name: 'twitter:image:width',
      content: imageDimensions.width
    },
    {
      name: 'twitter:image:height',
      content: imageDimensions.height
    },
    {
      name: 'twitter:description',
      content: petition.description &&
        petition.description.replace(/\n/g, ' ')
    }
  ].filter(meta => meta.content);
};