craftcms / apple-news
将Craft CMS条目发布到Apple News
Requires
- php: ^8.2.0
- chapter-three/apple-news-api: ^0.3.9
- craftcms/cms: ^5.0.0-beta.1
- league/html-to-markdown: ^5.0
Requires (Dev)
- codeception/codeception: ^5.0.11
- codeception/module-asserts: ^3.0.0
- codeception/module-datafactory: ^3.0.0
- codeception/module-phpbrowser: ^3.0.0
- codeception/module-rest: ^3.3.2
- codeception/module-yii2: ^1.1.9
- craftcms/ckeditor: *
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- craftcms/rector: dev-main
- symfony/browser-kit: ^6.4.0
- vlucas/phpdotenv: ^5.4
README
Apple News
此插件为Craft CMS提供了Apple News集成,使您能够将内容发布到全球的iPhone、iPad和Mac用户。
开始之前
在您开始发布到Apple News之前,您需要注册News Publisher并创建您的第一个频道。确保您在选择时选择使用Apple News格式。请注意,新频道在可以使用之前必须经过审批流程。
创建频道后,您需要记下其频道ID和API凭证。您可以从News Publisher中的设置→频道信息→连接CMS→API密钥获取这些信息。
要求
此插件需要Craft CMS 5.0.0+。
安装
您可以从插件商店或使用Composer安装此插件。
从插件商店
转到您项目控制面板中的插件商店,搜索Apple News。然后在其模态窗口中点击安装按钮。
使用Composer
打开您的终端并运行以下命令
# go to the project directory cd /path/to/my-project.test # tell Composer to load the plugin composer require craftcms/apple-news # tell Craft to install the plugin ./craft install/plugin apple-news
配置
发布到Apple News有自己的配置文件,位于config/apple-news.php
。它可以有以下配置设置
channels
(array) – 列表中的频道类配置autoPublishOnSave
(bool) – 是否应在保存条目时自动将其发布到Apple News(默认为true
)
以下是一个示例
<?php return [ 'channels' => [ [ 'class' => applenewschannels\MyNewsChannel::class, 'channelId' => craft\helpers\App::env('NEWS_CHANNEL_ID'), // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 'apiKeyId' => craft\helpers\App::env('NEWS_API_KEY'), // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 'apiSecret' => craft\helpers\App::env('NEWS_API_SECRET'), // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ], ], ];
频道类
频道类告诉插件开始发布Apple News内容所需的一切。它们应扩展craft\applenews\BaseChannel。
我们建议您将频道类保存在config/apple-news-channels
中,并使用applenewschannels
命名空间。
<?php namespace applenewschannels; // ...
提供了一个示例频道类apple-news-channels/MyNewsChannel.php,它将与Happy Lager演示网站中的“新闻”部分大致兼容。
自动加载您的频道类
要使您的频道类可自动加载,请在您的频道和文章类的composer.json
中添加一个新的autoload root,然后运行composer dump-autoload
。
{ "autoload": { "psr-4": { "applenewschannels\\": "config/apple-news-channels/" } } }
用法
一旦您的频道类设置并正确包含,就会在编辑条目的详细信息面板中显示一个新的Apple News频道区域,对于至少有一个匹配频道的条目。
每个频道旁边都会显示一个操作菜单,其中包含以下一些选项,具体取决于文章的状态
- 发布到Apple News – 将文章排队以发布到Apple News。
- 复制分享URL – 显示一个提示,允许用户复制文章的分享URL。
- 新闻预览下载 – 下载条目的
article.json
(以及其他文件),这些文件可以加载到新闻预览应用中,以查看文章发布后在各种iOS设备上的确切外观。
在条目索引页面上还将新增一个 发布到苹果新闻 批量操作,这使得可以同时排队多个条目进行发布。
资源
您可以在以下资源中了解更多关于在苹果新闻上发布的信息
注意事项
请注意以下注意事项
- 设置为未来日期的发布日期的条目,在上线时不会自动发布到苹果新闻。
感谢
非常感谢Chapter Three为他们的优秀AppleNewsAPI库。