@bbc/psammead-social-embed

中文文档
3.3.13发布于 2022/03/30Apache-2.0ESM + CJS近 30 天下载 2852

使丰富的社交媒体嵌入或倒置的组件.

中文使用文档
文档目录19 节
  1. 说明
  2. 支助提供者
  3. 安装
  4. 道具
  5. 光学
  6. fallback
  7. skipLink
  8. caption
  9. 使用量
  10. 光学
  11. 打开
  12. AMP 计划
  13. 何时使用此组件
  14. 不使用此组件时
  15. 无障碍说明
  16. 杂项
  17. 捐款
  18. 行为守则
  19. 许可证

{\fn黑体\fs22\bord1\shad0\3ahbe\4ah00\fscx67\fscy66\2chffffff\3ch808080}我.. Known Vulnerabilities Dependency Status peerDependencies Status Storybook GitHub license npm version PRs Welcome

说明

这个 SocialEmbed 组件将丰富的社交媒体嵌入一些支持的提供者或包含与源内容链接的倒置.

支助提供者

名称数值
内存instagram
微博twitter
YouTube (英语)youtube

安装

npm install @bbc/psammead-social-embed --save

道具

光学

参数类型需求默认示例
provider字符串对无见 支助提供者。 。 。 .
service字符串对无'news'
oEmbed对象对无见 @bbc/psammead-oembed (英语)。 。 。 .
fallback对象对无见 倒计时。 。 。 .
skipLink对象对无见 跳过链接。 。 。 .
caption对象没有null见 标题。 。 。 .
onRender函数没有null() => console.log('rendered')
• AMP
参数类型需求默认示例
provider字符串对无见 支助提供者。 。 。 .
service字符串对无'news'
id字符串对无'1237210910835392512'
fallback对象对无见 倒计时。 。 。 .
skipLink对象对无见 跳过链接。 。 。 .
caption对象没有null见 标题。 。 。 .

fallback

参数类型需求默认示例
text字符串对无"Sorry but we're having trouble displaying this content"
linkText字符串对无'View content on %provider_name%'
linkTextSuffixVisuallyHidden字符串没有null', external'
linkHref字符串对无'https://twitter.com/MileyCyrus/status/1237210910835392512'
warningText字符串没有nullWarning: BBC is not responsible for third party content
参数类型需求默认示例
text字符串对无'Skip %provider_name% content'
endTextId字符串对无'skip-%provider%-content'
endTextVisuallyHidden字符串对无'End of %provider_name% content'

caption

参数类型需求默认示例
textPrefixVisuallyHidden字符串没有null'Video caption,'
text字符串对无'Warning: Third party content may contain adverts'

见 无障碍说明 更多信息.

注:为方便起见 %provider% 财务报告和审定财务报表 %provider_name% 内 fallback, (中文(简体) ), skipLink 财务报告和审定财务报表 caption 字符串将被替换为当前提供者,并在已知提供者的地方,替换提供者的名称. (原始内容存档于2018-09-21). E.G. youtube 财务报告和审定财务报表 YouTube 页:1.

使用量

光学

传出 a 支持提供者 和有效的 ombed 反应。 如果这两种情况都无法解决,则会提供包含与源内容链接的倒置.

示例

import { CanonicalSocialEmbed } from '@bbc/psammead-social-embed';

<CanonicalSocialEmbed
  provider="instagram"
  service="news"
  oEmbed={{ html: '...' }}
  skipLink={{
    text: 'Skip %provider_name% content',
    endTextId: 'skip-%provider%-content',
    endTextVisuallyHidden: 'End of %provider_name% content',
  }}
  fallback={{
    text: "Sorry but we're having trouble displaying this content",
    linkText: 'View content on %provider_name%',
    linkTextSuffixVisuallyHidden: ', external',
    linkHref: 'https://www.instagram.com/p/B8FPf4ZphHi/',
    warningText: 'Warning: BBC is not responsible for third party content',
  }}
/>;

本构成部分支持与难民署的整合 反应-负载 软件包,确保社交媒体的帖子在被看到时能够发布.

示例

<LazyLoad height={200}>
  <CanonicalSocialEmbed provider="instagram" .../>
</LazyLoad>

打开

此组件需要 onRender 当嵌入面完全渲染(目前仅用于twitter嵌入面)时.

示例

import React, { useState } from 'react';
import styled from '@emotion/styled';

const DEFAULT_MIN_HEIGHT = '18.75rem';

const Wrapper = styled.div`
  min-height: ${({ minHeight }) => minHeight};
`;

const SocialEmbedWithWrapper = ({
  provider,
  oEmbed,
  skipLink,
  fallback,
  service,
  }) => {

  const [wrapperMinHeight, setWrapperMinHeight] = useState(DEFAULT_MIN_HEIGHT);

  return (
    <Wrapper minHeight={wrapperMinHeight}>
      <CanonicalSocialEmbed
        provider={provider}
        oEmbed={oEmbed}
        skipLink={skipLink}
        fallback={fallback}
        service={service}
        onRender={() => {
          setMinHeight('0');
        }}
      />
    </Wrapper>
  );
};

export default SocialEmbedWithWrapper;

AMP 计划

传出 a 支持提供者。如果无法满足这种情况,则会提供包含与源内容链接的倒置.

通过一个有效的文件 id。这是指URL中唯一识别源内容的部分。 (原始内容存档于2018-09-21). E.G. 1237210910835392512 内 https://twitter.com/MileyCyrus/status/1237210910835392512。 。 。 .

import { AmpSocialEmbed } from '@bbc/psammead-social-embed';

<AmpSocialEmbed
  provider="instagram"
  service="news"
  id="B8FPf4ZphHi"
  skipLink={{
    text: 'Skip %provider_name% content',
    endTextId: 'skip-%provider%-content',
    endTextVisuallyHidden: 'End of %provider_name% content',
  }}
  fallback={{
    text: "Sorry but we're having trouble displaying this content",
    linkText: 'View content on %provider_name%',
    linkTextSuffixVisuallyHidden: ', external',
    linkHref: 'https://www.instagram.com/p/B8FPf4ZphHi/',
    warningText: 'Warning: BBC is not responsible for third party content',
  }}
/>;

何时使用此组件

本部分旨在从一些媒体中嵌入丰富的社交媒体内容 支助提供者 主要内容,例如文章.

不使用此组件时

该部分不会为外部供应商提供丰富的社交媒体 支助提供者 – 这些会使用倒置的内容取而代之.

无障碍说明

本构成部分提供: 跳过链接,允许用户识别并跳过您页面中的社交媒体内容. skipLink.endTextId 应设定为唯一识别的值 skipLink.endTextVisuallyHidden。当一个页面上有一个以上来自同一供应商的社交媒体时,这一点尤其重要.

fallback.linkTextSuffixVisuallyHidden 用于添加后缀到 fallback.text这在UI上是看不到的,但会被辅助技术所捕获.

caption.textPrefixVisuallyHidden 用于在 caption.text这在UI上是看不到的,但会被辅助技术所捕获.

杂项

内部的一些组成部分 SocialEmbed 得到同样的道具 并使用 反应. memo 防止不必要的.

捐款

Psammead完全开源. 我们感谢任何贡献,无论是新的组件、错误修正还是总体改进。 请参看我们的主要贡献指南,可查阅: psammead 仓库的根。 。 。 .

行为守则

我们欢迎对这项工作的反馈和帮助。 通过参与这个项目,你同意遵守 行为守则请稍候再读一下.

许可证

萨姆米德 Apache 2.0 许可。 。 。 .

版本与发布记录

@bbc/psammead-social-embed 共发布 61 个版本,首次发布于 2020/03/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.3.13latest2022/03/304 年前
3.3.122022/03/294 年前
3.3.112022/01/064 年前
3.3.102021/12/034 年前
3.3.92021/10/065 年前
3.3.82021/09/305 年前

其他发布通道:alpha → 2.0.0-alpha.0。

关于 @bbc/psammead-social-embed 的常见问题

@bbc/psammead-social-embed 是什么?

使丰富的社交媒体嵌入或倒置的组件.

如何安装 @bbc/psammead-social-embed?

在项目目录运行 npm install @bbc/psammead-social-embed,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.9.0)、@emotion/styled(^11.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bbc/psammead-social-embed 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bbc__psammead-social-embed 是否存在。

@bbc/psammead-social-embed 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bbc/psammead-social-embed 可以商用吗?

@bbc/psammead-social-embed 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bbc/psammead-social-embed 的下载量有多少?

根据 npm 官方下载统计,@bbc/psammead-social-embed 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,852 次,日均约 95 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bbc/psammead-social-embed 还在维护吗?

最新版本 3.3.13 发布于 2022/03/30(4 年前);至今共发布 61 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/03/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。