Kirby 3 嵌入字段

安装次数: 8,256

依赖项: 0

建议者: 0

安全性: 0

星标: 74

关注者: 4

分支: 3

开放性问题: 3

类型:kirby-plugin

1.1.2 2024-03-08 14:51 UTC

This package is auto-updated.

Last update: 2024-09-08 15:55:37 UTC


README

为 Kirby 3 和 4 提供嵌入字段。通过仅提供媒体的 URL 来显示来自各种媒体网站(YouTube、Vimeo、Soundcloud、Instagram 等)的嵌入。在 oscarotero/Embed 之上构建。

embed-screenshot

概述

此插件完全免费,并采用 MIT 许可证发布。但是,如果您在商业项目中使用它并希望帮助我保持维护,请考虑 随意捐赠 或通过 我的联盟链接 购买您的许可证。

1. 安装

Kirby 3: up to 1.1.0 Kirby 4: 1.1.1+

下载并将此存储库复制到 /site/plugins/embed

或者,您可以使用 composer 安装它: composer require sylvainjule/embed


2. 蓝图使用

该插件提供了一个 embed 字段,您可以在任何蓝图中使用它

fields:
  embed:
    label: Embed
    type: embed

您可以使用 oscarotero/Embed 支持的所有提供者。请注意,我不会包含该库不支持的所有提供者。

您可以选择将允许的提供者限制为列表中的一个: youtubevimeoflickrinstagramtwittersoundcloud。如果粘贴了任何其他链接,该字段将不会请求嵌入。

embed:
  type: embed
  provider: youtube

如果您在结构字段中使用此字段,它包含一个内置的预览。您可以选择设置 icons: true(默认为 false)以在预览中显示一些提供者的标志。

embed:
  type: embed
  icons: true

embed-icons

该字段还具有所有 url 字段选项,除了那些对这样的插件没有太多意义的选项(例如 default),后台不会检索任何内容。


3. 前端使用

该插件提供了一个 ->toEmbed() 方法,这对于获取嵌入存储的所有数据(其 HTML 代码和以下详细说明的少量其他信息)非常有用。

它还允许您在尝试访问数据之前确保您的嵌入成功同步。

if($embed = $page->myfield()->toEmbed()) {
    echo $embed->code()
}

一旦您获得了结构化嵌入,以下选项您将像访问字段一样访问它们(这很有用,因为根据提供者,某些信息可能为空。因此,您可以使用常规 Kirby 字段方法(如 $embed->license()->isEmpty())来检查它们)。

$embed->title();        // The page title
$embed->description();  // The page description
$embed->url();          // The canonical url
$embed->type();         // The page type (link, video, image, rich)
$embed->tags();         // The page keywords (tags)

$embed->image();         // The main image found in the page

$embed->code();          // The code to embed the image, video, etc
$embed->width();         // The width of the embed code
$embed->height();        // The height of the embed code
$embed->aspectRatio();   // The aspect ratio (width / height)

$embed->authorName();    // The resource author
$embed->authorUrl();     // The author url

$embed->providerName();  // The provider name of the page (Youtube, Twitter, Instagram, etc)
$embed->providerUrl();   // The provider url
$embed->providerIcon();  // The main icon found in the page

$embed->publishedDate(); // The published date of the resource
$embed->license();       // The license url of the resource
$embed->feeds();         // The RSS/Atom feeds

有一个全局网站方法可以请求嵌入数据 $site->getEmbedData($url)

$url = 'https://www.youtube.com/watch?v=XXX';
$site->getEmbedData($url);

4. 许可证

MIT


5. 致谢

oscarotero/Embed 之上构建。

@tristantbg 的帮助下。 👨‍💻

@distantnative 开发的 Kirby 2 字段,我从其中复制粘贴了一些此说明的片段。 👀