reactjs - 带有动态标题和描述的 Whatsapp 共享
问题描述
我有一个使用 React 构建的网站,该网站托管在 www.url.com 域下,我在 index.html 上设置了以下元
<meta name="description" content="My description">
<meta property="og:title" content="My title" />
<meta property="og:url" content="https://www.url.com" />
<meta property="og:description" content="My description">
<meta property="og:image" content="https://www.myimage.com">
<meta property="og:type" content="website" />
我的网站中包含帖子,其中每个帖子都有其唯一的 URL(如 www.url.com/post/thispost)、标题、描述和图像。我使用 ShareThis reactjs 插件(https://github.com/sharethis-github/sharethis-reactjs)为每个帖子创建共享按钮,并具有以下设置
<InlineShareButtons
config={{
alignment: 'center', // alignment of buttons (left, center, right)
color: 'social', // set the color of buttons (social, white)
enabled: true, // show/hide buttons (true, false)
font_size: 14, // font size for the buttons
labels: 'cta', // button labels (cta, counts, null)
language: 'en', // which language to use (see LANGUAGES)
networks: [ // which networks to include (see SHARING NETWORKS)
'whatsapp',
'facebook'
],
padding: 12, // padding within buttons (INTEGER)
radius: 4, // the corner radius on each button (INTEGER)
show_total: false,
size: 40, // the size of each button (INTEGER)
// OPTIONAL PARAMETERS
url: window.location.href, // (defaults to current url)
description: {description}, // (defaults to og:description or twitter:description)
title: {title}, // (defaults to og:title or twitter:title)
}}
/>
其中 description 和 title 是每个帖子的内容和标题。由于每个帖子都是一个弹出窗口,并且标题和描述只有在打开弹出窗口时才可用,所以我设计它只在弹出窗口打开时初始化 InlineShareButtons。
但这里的问题是,当我分享帖子时,它没有以我想要的方式显示描述和标题。相反,每当我尝试分享每个帖子时,它都会显示 index.html 上元标记的描述和标题。
有没有办法让我分享任何帖子时,它会使用帖子上的标题和描述?
解决方案
推荐阅读
- python - 一旦遇到异常,我可以忽略下面的所有行并转到 for 循环中的另一个项目吗?
- amazon-web-services - 从 lambda 推送到 S3 或从 lambda 推送到 Kinesis Firehose 到 S3
- sql-server - SSIS 多行
- airflow - 如何读取传递给气流回填的值 --conf {"key": "value"}
- julia - 在 Julia 中将向量作为行添加到矩阵
- javascript - 满足条件后删除对象
- typescript - 无法使用赛普拉斯上传 png 图像(徽标)
- sql - 在两种不同条件 SQL 下插入表
- html - 为什么浏览器打开时会修改原始html内容?
- hive - Hive - 列式扫描是否适用于 CSV 外部表