elistone/social-share-preview

生成社交分享预览

v1.0.0 2021-09-13 17:26 UTC

This package is auto-updated.

Last update: 2024-09-14 15:42:34 UTC


README

社交分享预览是一个库,设计用来传递某些内容,如标题、描述、图片URL和网页URL,然后根据某些社交媒体网站生成预览。

安装

Composer 推荐

composer require elistone/social-share-preview

手动

手动下载此包并将其添加到您的项目中

使用

// init preview library.
$preview = new Preview();

// set the common content.
$preview->setTitle("This is my example title");
$preview->setDescription("This is my example description");
$preview->setImageUrl("https://source.unsplash.com/random");
$preview->setUrl("https://example.com");

// set the type of preview.
$preview->setType("facebook"); // Facebook, LinkedIn or Twitter.

// generate and display the preview.
echo $preview->generate();

样式

此库包含一些基本样式,用于生成的输出,可以在css/social-share-preview.css中找到。

示例

本项目中有示例文件,可以通过php serve启动。

php -S localhost:8001

然后访问https://:8001/example.php将加载示例。