aerni / apple-news
Statamic 插件,用于发布您的集合条目至 Apple News。
Requires
- php: ^7.4 | ^8.0
- chapter-three/apple-news-api: ^0.3.11
- spatie/laravel-ray: ^1.24
- statamic/cms: ^3.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.19
- nunomaduro/collision: ^5.4
- orchestra/testbench: ^6.17
- phpunit/phpunit: ^9.5
README
Apple News
本 Statamic 插件提供了强大的 Apple News 集成,使您能够将集合条目发布到全球的 iPhone、iPad 和 Mac 用户。
先决条件
您首先需要申请新闻发布者并创建一个频道,然后才能开始发布您的内容。请注意,新频道在使用前必须经过审批流程。
接下来,您需要获取您的频道 ID 和 API 凭证。您可以在“新闻发布者”的“设置 -> 连接 CMS -> API 密钥”中获取这些信息。
安装
使用 Composer 安装插件
composer require aerni/apple-news
发布包的配置
php please vendor:publish --tag=apple-news-config
以下配置将发布到 config/apple-news.php
return [ /* |-------------------------------------------------------------------------- | Apple News API |-------------------------------------------------------------------------- | | The Apple News API credentials of your channel. | */ 'id' => env('APPLE_NEWS_CHANNEL_ID'), 'key' => env('APPLE_NEWS_KEY'), 'secret' => env('APPLE_NEWS_SECRET'), /* |-------------------------------------------------------------------------- | Site |-------------------------------------------------------------------------- | | The handle of the site you want to use to publish on Apple News. | */ 'site' => 'default', /* |-------------------------------------------------------------------------- | Collections |-------------------------------------------------------------------------- | | The handles of the collections whose entries you want to publish. | */ 'collections' => [ // 'articles', ], /* |-------------------------------------------------------------------------- | Templates |-------------------------------------------------------------------------- | | The templates for your Apple News articles. | */ 'templates' => [ // \App\AppleNews\DefaultTemplate::class, ], ];
配置
Apple News API
将您的 Apple News API 凭证添加到您的 .env
文件中
APPLE_NEWS_CHANNEL_ID=************************************ APPLE_NEWS_KEY=************************************ APPLE_NEWS_SECRET=********************************************
站点
添加您要在 Apple News 上发布的站点的处理程序
'site' => 'default'
集合
添加您希望在其上发布条目的集合的处理程序
'collections' => [ 'articles', 'interviews' ]
模板
添加您的文章模板类
'templates' => [ \App\AppleNews\DefaultTemplate::class, \App\AppleNews\InterviewTemplate::class, ]
文章模板
创建模板
创建您的第一个文章模板
php please apple-news:template {name}
这将将在 app/AppleNews/{name}.php
中发布一个新模板。
自定义模板
每个模板都由一组配置文章的方法组成。它们由出色的 AppleNewsAPI 库提供支持,允许您定义文章的布局、组件、样式等。确保查看源代码以了解您可用的类和方法。
预览文章
新闻预览 是 Apple 提供的应用程序,允许您在新闻应用程序中预览您的文章。这在构建模板时非常有用。
使用以下命令并提供您要用于预览的 Statamic 条目的 id
php please apple-news:preview {entryId}
这将创建 storage/statamic/addons/apple-news/preview/
中的条目的 article.json
文件。
打开 News Preview
应用程序,选择 article.json
文件,并选择您想要用于预览文章的设备。
发布流程
发布
打开您想要在 Apple News 上发布的 Statamic 控制面板中的条目。转到“Apple News”选项卡并按您的喜好自定义选项。准备好发布后,切换 Published
开关并保存条目。文章现在正在由 Apple News 处理。刷新页面以查看当前的 Publish State
。
更新
每次您保存 Statamic 条目时,文章都会更新。
注意:每次触发
Statamic\Events\EntrySaving
事件时,都会更新文章。
取消发布/删除
取消切换 Published
开关以从 Apple News 中删除文章。删除 Statamic 条目将执行相同的操作。
注意:Apple News 不支持取消发布文章。文章只能被删除。或者,您可以使用
Hidden
开关将文章从 Apple News 文章中隐藏。
许可证
苹果新闻是 商业软件,但具有开源代码库。如果您想在生产中使用它,则需要从 Statamic 市场购买许可证。
苹果新闻 不是 免费软件。
致谢
由 Michael Aerni 开发
特别感谢
感谢 Duo Security 和 思科 对此插件的赞助。