studiothick / silverstripe-opengraph
自动为Silverstripe页面生成Open Graph数据。
Requires
This package is not auto-updated.
Last update: 2024-09-20 18:59:22 UTC
README
此模块正在开发中。欢迎提交错误报告或功能请求。
此模块向Page类添加了一个getOpenGraph方法,用于在模板中使用。在模板中调用$OpenGraph将返回一系列自动生成的标签,对应于标准的open graph属性。
-
og:title: 来自$Title -
og:type: 固定为"website" -
og:image: 绝对URL。尝试$HeroImage、$PostImage、$Image,然后是$FeaturedImage -
og:image:width: 宽度,与og:image相同 -
og:image:height: 高度,与og:image相同 -
og:url: 页面的绝对URL (Director::protocolAndHost() . $this->Link) -
og:description: 来自$MetaDescription -
og:locale: 来自i18n::get_locale() -
og:site_name: 来自$SiteConfig.Title -
og:determiner: 未使用 -
og:locale:alternate: 未使用 -
og:audio: 未使用 -
og:video: 未使用
以上所有内容都可以在Page.php或给定的子类中根据命名约定getOpenGraph_attribute进行覆盖,其中移除og,并用空格替换:。例如,getOpenGraph_image_width()。
要覆盖图像选择行为(例如,返回静态图像或返回扩展搜索列表中不存在的字段),只需实现getOpenGraphImage()以返回SilverStripe Image对象。
安装
使用composer require studiothick/silverstripe-opengraph进行安装。
用法
示例
<head> <title>$SiteConfig.Title | $Title</title> $OpenGraph </head>