julienbourdeau/laravel-ghost-connector

将Ghost文章当作数据库中的Eloquent模型使用。感谢Sushi和Ghost API!

0.3.0 2020-04-05 11:03 UTC

This package is auto-updated.

Last update: 2024-09-05 21:29:00 UTC


README

Laravel Latest Version on Packagist

此包从Ghost博客检索内容,并使用Sushi使其作为常规模型可用。

内容将保存在内存中,并在调用模型构建器时重用。它不会在请求之间共享。

我编写这个包是因为我在Laravel上使用Laravel Nova构建了我的自定义博客。我喜欢用它来写长篇文章,但对我来说,日志记录的写作体验并不那么好。使用这个包,我在Ghost管理界面中写作,但内容仍然是通过Laravel发布的。🏄‍♂️

安装

您可以通过composer安装此包

composer require julienbourdeau/laravel-ghost-connector

将您的Ghost凭据添加到我们的.env文件中。

GHOST_API_URL=http://localhost:2369
GHOST_CONTENT_KEY=2b3934d798ccce67daacdc8adb

使用方法

以下是一些简单的示例,说明您通常如何使用此包。以下代码将对Ghost进行一次单一的HTTP调用。

Post::count();
Post::all()->map(function($x) {
    dump($x->title);
});
Post::where('featured', true)->get();
@foreach (Post::all() as $post)
  <h2>{{ $post->title }}</h2>
  <p>{{ nl2br($post->excerpt) }}</p>
  <hr>
@endforeach

Ghost API

当从Ghost检索文章时,包将包含标签和作者

内容也将使用常规的$casts模型功能进行转换。

示例

这是API响应,以下为Post::first()->toArray()

array:34 [
  "id" => "5e80568dc50444aef65bea46"
  "uuid" => "97f42901-6b26-4a61-9ec6-96852d05e0f3"
  "title" => "Welcome to Ghost"
  "slug" => "welcome"
  "html" => "<h2 id="a-few-things-you-should-know"><strong>A few things you should know</strong></h2><ol><li>Ghost is
 designed for ambitious ... Blah blah blah"
  "comment_id" => "5e80568dc50444aef65bea46"
  "feature_image" => "https://static.ghost.org/v3.0.0/images/welcome-to-ghost.png"
  "featured" => false
  "visibility" => "public"
  "send_email_when_published" => false
  "created_at" => "2020-03-29T08:04:29.000000Z"
  "updated_at" => "2020-03-29T08:04:29.000000Z"
  "published_at" => "2020-03-29T08:04:35.000000Z"
  "custom_excerpt" => """
    Welcome, it's great to have you here.\n
    We know that first impressions are important, so we've populated your new site with some initial getting started posts that will help you get familiar with everything in no time.
    """
  "codeinjection_head" => null
  "codeinjection_foot" => null
  "custom_template" => null
  "canonical_url" => null
  "authors" => array:1 [
    0 => array:13 [
      "id" => "5951f5fca366002ebd5dbef7"
      "name" => "Ghost"
      "slug" => "ghost"
      "profile_image" => "https://static.ghost.org/v3.0.0/images/ghost.png"
      "cover_image" => null
      "bio" => "You can delete this user to remove all the welcome posts"
      "website" => "https://ghost.org"
      "location" => "The Internet"
      "facebook" => "ghost"
      "twitter" => "ghost"
      "meta_title" => null
      "meta_description" => null
      "url" => "http://localhost:2369/author/ghost/"
    ]
  ]
  "tags" => array:1 [
    0 => array:9 [
      "id" => "5e80568cc50444aef65be9e6"
      "name" => "Getting Started"
      "slug" => "getting-started"
      "description" => null
      "feature_image" => null
      "visibility" => "public"
      "meta_title" => null
      "meta_description" => null
      "url" => "http://localhost:2369/tag/getting-started/"
    ]
  ]
  "primary_author" => array:13 [
    "id" => "5951f5fca366002ebd5dbef7"
    "name" => "Ghost"
    "slug" => "ghost"
    "profile_image" => "https://static.ghost.org/v3.0.0/images/ghost.png"
    "cover_image" => null
    "bio" => "You can delete this user to remove all the welcome posts"
    "website" => "https://ghost.org"
    "location" => "The Internet"
    "facebook" => "ghost"
    "twitter" => "ghost"
    "meta_title" => null
    "meta_description" => null
    "url" => "http://localhost:2369/author/ghost/"
  ]
  "primary_tag" => array:9 [
    "id" => "5e80568cc50444aef65be9e6"
    "name" => "Getting Started"
    "slug" => "getting-started"
    "description" => null
    "feature_image" => null
    "visibility" => "public"
    "meta_title" => null
    "meta_description" => null
    "url" => "http://localhost:2369/tag/getting-started/"
  ]
  "url" => "http://localhost:2369/welcome/"
  "excerpt" => """
    Welcome, it's great to have you here.\n
    We know that first impressions are important, so we've populated your new site with some initial getting started posts that will help you get familiar with everything in no time.
    """
  "reading_time" => 1
  "og_image" => null
  "og_title" => null
  "og_description" => null
  "twitter_image" => null
  "twitter_title" => null
  "twitter_description" => null
  "meta_title" => null
  "meta_description" => null
  "email_subject" => null
]

更新日志

请参阅更新日志了解最近的变化。

贡献

请参阅贡献指南了解详细信息。

安全性

如果您发现任何与安全相关的问题,请通过电子邮件julien@sigerr.org联系,而不是使用问题跟踪器。

鸣谢

许可协议

MIT许可协议(MIT)。请参阅许可文件以获取更多信息。

Laravel包模板

此包是用Laravel包模板生成的。