astrotomic/laravel-webmentions

0.6.0 2024-06-25 15:22 UTC

This package is auto-updated.

Last update: 2024-08-25 15:38:15 UTC


README

Latest Version MIT License Offset Earth Larabelles

GitHub Workflow Status StyleCI Total Downloads

一个简单的客户端,用于检索您页面的 webmention

安装

您可以通过 composer 安装此包

composer require astrotomic/laravel-webmentions

配置

首先,您需要将您的 webmention.io API 访问令牌添加到 services.php 配置文件中。

return [
    // ...
    'webmention' => [
        'token' => env('WEBMENTION_TOKEN'),
    ],
    // ...
];

使用方法

您可以通过在包客户端上调用 get() 方法来检索给定 URL 的所有 webmention。

use Astrotomic\Webmentions\Facades\Webmentions;

$records = Webmentions::get('https://gummibeer.dev/blog/2020/human-readable-intervals');

如果您省略了参数作为 URL,它将自动使用 \Illuminate\Http\Request::url() 作为默认值。返回值将是一个 \Astrotomic\Webmentions\Collections\WebmentionsCollection 实例,它为您提供了预定义的过滤方法。您还可以在客户端上使用简写方法来检索喜欢、提及、回复或重发集合。

use Astrotomic\Webmentions\Facades\Webmentions;

$likes = Webmentions::likes('https://gummibeer.dev/blog/2020/human-readable-intervals');
$mentions = Webmentions::mentions('https://gummibeer.dev/blog/2020/human-readable-intervals');
$replies = Webmentions::replies('https://gummibeer.dev/blog/2020/human-readable-intervals');
$reposts = Webmentions::reposts('https://gummibeer.dev/blog/2020/human-readable-intervals');

所有项目都将是对应的 \Astrotomic\Webmentions\Models\Like\Astrotomic\Webmentions\Models\Mention\Astrotomic\Webmentions\Models\Reply\Astrotomic\Webmentions\Models\Repost 实例。

如果您只需要项目的数量,可以使用 Webmentions::count() 方法。

use Astrotomic\Webmentions\Facades\Webmentions;

$counts = Webmentions::count('https://gummibeer.dev/blog/2020/human-readable-intervals');
[
  'count' => 52,
  'type' => [
    'like' => 23,
    'mention' => 8,
    'reply' => 16,
    'repost' => 5,
  ],
];

缓存

客户端默认使用一种简陋的缓存 - 因此每个运行时每个域名只请求一次。如果您想有更复杂的缓存行为,您应该在调用中使用 Cache::remember() 之类的函数。

Blade 组件

为了接收您页面的 webmention,您需要在您的 head 中添加两个 <link/> 标签。此包提供了一个 <x-webmention-links/> Blade 组件,使您更容易做到这一点。

<x-webmention-links />
<!-- will use the domain of current request -->
<x-webmention-links domain="gummibeer.dev" />
<!-- will use the given domain -->

<!-- RESULT -->
<link rel="webmention" href="https://webmention.io/gummibeer.dev/webmention" />
<link rel="pingback" href="https://webmention.io/gummibeer.dev/xmlrpc" />

测试

composer test

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

贡献

有关详细信息,请参阅 CONTRIBUTING。您也可能对 CODE OF CONDUCT 感兴趣。

安全

如果您发现任何安全问题,请参阅 SECURITY 了解报告步骤。

致谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件

开源

您可以免费使用此包,但如果它进入您的生产环境,我将非常感激您为世界购买一棵树。

众所周知,解决气候危机并防止温度上升超过 1.5C 的最佳工具之一是 植树。如果您为我的森林做出贡献,您将为当地家庭创造就业机会并恢复野生动物栖息地。

您可以在 offset.earth/treeware 购买树木。

有关 Treeware 的更多信息,请访问 treeware.earth