share-handler.js 862 Bytes
import {get, first} from 'lodash';

const getDetailShareData = (article) => {
  let shareImage = '';
  let desc = '';

  if (article.sort === 2) {
    shareImage = article.coverImage;
    desc = article.articleTitle;
  } else {
    let blockList = get(article, 'blockList', []);

    shareImage = get(first(blockList.filter(block => block.templateKey === 'image')), 'contentData', '');
    desc = get(blockList.filter(block => block.templateKey === 'text'), '[0].contentData', '');
  }

  return {
    title: `@${article.authorName} 在有货社区上发了一篇笔记,快点开看看!`,
    imgUrl: shareImage.replace('{mode}', 2).replace('{width}', 200).replace('{height}', 200),
    link: `${window ? window.location.origin : ''}/grass/article/share/${article.articleId}`,
    desc,
    hideType: ['7', '8', '9']
  };
}

export {
  getDetailShareData
};