messserli90 / laravel-ghost
Ghost内容API的Fluent Laravel封装
0.1.0
2021-04-05 22:09 UTC
Requires
- php: ^7.4|^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/contracts: ^8.0
- illuminate/http: ^7.0|^8.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- brianium/paratest: ^6.0
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- phpunit/phpunit: 9.4.3
- spatie/laravel-ray: ^1.17
- vimeo/psalm: ^4.4
This package is auto-updated.
Last update: 2024-09-07 03:59:17 UTC
README
Laravel对Ghost博客API的封装
一个对Ghost内容API的流畅封装
示例
$post = Ghost::posts()->with('authors')->fromSlug('welcome'); $tags = Ghost::tags()->all();
安装
您可以通过composer安装此包
composer require messerli90/laravel-ghost
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Messerli90\Ghost\GhostServiceProvider" --tag="ghost-config"
这是已发布配置文件的内容
return [ /** * The API version of your Ghost blog * * Read about Ghost API Versioning in their docs: * https://ghost.org/docs/faq/api-versioning/ */ 'ghost_api_version' => env("GHOST_API_VERSION", 4), /** * Your admin domain can be different to your main domain. * All Ghost(Pro) blogs have a `.ghost.io` domain * as their admin domain and require https. */ 'admin_domain' => env('GHOST_ADMIN_DOMAIN', "https://{admin_domain}"), /** * The Content API URL and key can be obtained by creating a new * Custom Integration under the Integrations screen in Ghost Admin. */ 'key' => env('GHOST_API_KEY', ''), /** * Optionally, cache records when they are returned. */ 'cache' => [ /** * Cache returned records * Set to false if you want to handle caching yourself */ 'cache_records' => false, /** * Prefix key used to save to cache * Ex. ghost_posts */ 'cache_prefix' => 'ghost_', /** * How long until cache expires * Accepts int in seconds, or DateTime instance */ 'ttl' => 60 * 60, ] ];
使用方法
// Using the facade Ghost::posts()->all(); // or $ghost = new Ghost($content_key, $domain, string $version); $ghost->posts()->all();
对于posts、authors、tags和pages的API是类似的,可以使用以下方法使用
// All resources returned as an array Ghost::posts()->all(); Ghost::authors()->all(); Ghost::tags()->all(); Ghost::pages()->all(); // Retrieve a single resource by slug Ghost::posts()->bySlug('welcome'); // Retrieve a single resource by id Ghost::posts()->find('605360bbce93e1003bd6ddd6'); // Get full response from Ghost Content API including meta & pagination Ghost::posts()->paginate(); $response = Ghost::posts()->paginate(15); $posts = $response['posts']; $meta = $response['meta'];
构建您的请求
Ghost::posts() ->with('authors', 'tags') ->fields('title', 'slug', 'html') ->limit(20) ->page(2) ->orderBy('title') ->get();
缓存
建议您在从您的Laravel应用程序提供服务时缓存返回的资源。
例如,一个可能的BlogController@index可能看起来像这样
public function index() { $posts = Cache::rememberForever('posts', fn() => Ghost::posts()->with('authors', 'tags')->all() ); return view('blog.index', compact('posts')); }
自动资源缓存(实验性且不在稳定版本中)
自动缓存定义时间内的返回记录。
包含ghost:cache artisan命令,该命令可以计划定期用新帖子重新填充缓存。
测试
composer test
路线图
- 缓存
- Ghost内容过滤器
变更日志
请参阅CHANGELOG以获取有关最近更改的更多信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全漏洞
请审查我们的安全策略,了解如何报告安全漏洞。
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。