Git Product home page Git Product logo

nova-blog's Introduction

Nova Blog

This Laravel Nova package allows you to create a blog, manage blogposts and posts' content. The package is geared towards headless CMS's.

Installation

Install the package in a Laravel Nova project via Composer:

composer require optimistdigital/nova-blog

Publish the nova-blog configuration file and edit it to your preference:

php artisan vendor:publish --provider="OptimistDigital\NovaBlog\ToolServiceProvider" --tag="config"

Publish the database migration(s) and run migrate:

php artisan vendor:publish --provider="OptimistDigital\NovaBlog\ToolServiceProvider" --tag="migrations"
php artisan migrate

Register the tool with Nova in the tools() method of the NovaServiceProvider:

// in app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        // ...
        new \OptimistDigital\NovaBlog\NovaBlog
    ];
}

Defining locales

The config accepts a dictionary of locales.

// in /config/nova-blog.php

// ...
'locales' => [
  'en' => 'English',
  'et' => 'Estonian',
],

// OR

'locales' => function () {
  return Locale::all()->pluck('name', 'key');
},

// if you wish to cache the configuration, pass a reference instead:

'locales' => NovaBlogConfiguration::class . '::locales',

// ...

Nova Lang

This package supports optimistdigital/nova-lang for easier content localization. After installing and setting up nova-lang package, you can use nova_lang_get_all_locales helper function in nova-blog config file

'locales' => nova_lang_get_all_locales(),

Toggling page draft feature

Draft feature allows you to create previews of resources before publishing them. By default this feature is disabled but can be enabled by installing nova-drafts package.

composer require optimistdigital/nova-drafts

Add links to front-end pages

To display a link to the actual page next to the slug, add or overwrite the closure in config/nova-blog.php for the key page_url.

// in /config/nova-blog.php

// ...
'page_url' => function (Post $post) {
  return env('FRONTEND_URL') . '/' . $post->slug;
},

// if you wish to cache the configuration, pass a reference instead:

'page_url' => NovaBlogConfiguration::class . '::pageUrl',
// ...

Helper functions

nova_get_blog_structure()

The helper function nova_get_blog_structure() returns the base posts structure (titles, slugs, published at dates, content) that you can build your routes upon in the front-end.

Example response:

[
  {
    "id": 7,
    "created_at": "2019-06-19 11:58:56",
    "updated_at": "2019-06-19 11:59:23",
    "title": "Test post 1",
    "slug": "test-post-1",
    "post_content": [
      {
        "layout": "text",
        "key": "8965c7bfc0918086",
        "attributes": {
          "text-content": "Test post content."
        }
      },
      {
        "layout": "image",
        "key": "56f5bbe608b68cd6",
        "attributes": {
          "caption": "Test post image."
        }
      }
    ],
    "published_at": "2019-06-19 09:00:00",
    "seo_title": null,
    "seo_description": null,
    "seo_image": null,
    "data": null
  },
  {
    "id": 8,
    "created_at": "2019-06-19 12:00:06",
    "updated_at": "2019-06-19 12:00:06",
    "title": "Test post 2",
    "slug": "tes-post-2",
    "post_content": [
      {
        "layout": "text",
        "key": "0e340b84bc5dec28",
        "attributes": {
          "text-content": "Test post content."
        }
      },
      {
        "layout": "image",
        "key": "a4625050e49cf77c",
        "attributes": {
          "caption": "Test post image."
        }
      }
    ],
    "published_at": "2019-06-19 09:00:05",
    "seo_title": null,
    "seo_description": null,
    "seo_image": null,
    "data": null
  }
]

nova_get_post_by_id($postId)

The helper function nova_get_post_by_id($postId) finds and returns the post with the given ID.

Example response for querying page with ID 7 (nova_get_post_by_id(7)):

{
  "id": 7,
  "name": "Test post 1",
  "slug": "testpost1",
  "published_at": "2019-06-19T09:00:00.000000Z",
  "post_content": [
    {
      "layout": "text",
      "key": "8965c7bfc0918086",
      "attributes": {
        "text-content": "Test post content."
      }
    },
    {
      "layout": "image",
      "key": "56f5bbe608b68cd6",
      "attributes": {
        "caption": "Test post image."
      }
    }
  ]
}

nova_get_post_by_slug($slug)

The helper function nova_get_post_by_slug($slug) finds and returns the post with the given slug.

Example response for querying page with slug test-post-3 (nova_get_post_by_slug('test-post-3')):

{
  "id": 14,
  "name": "Test post 3",
  "slug": "test-post-3",
  "published_at": "2019-06-25T09:00:00.000000Z",
  "post_content": [
    {
      "layout": "text",
      "key": "fc64d73f1f7508c4",
      "attributes": {
        "text-content": "Test post content."
      }
    },
    {
      "layout": "image",
      "key": "f8c9cc65b23b862a",
      "attributes": {
        "caption": "Test post image."
      }
    }
  ]
}

Credits

License

Nova blog is open-sourced software licensed under the MIT license.

nova-blog's People

Contributors

eleriojavere avatar marikamustv avatar matislepik avatar tarpsvo avatar trippo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nova-blog's Issues

create_blog_posts_table rollback not working since 7.4.0

SQLSTATE[HY000]: General error: 3730 Cannot drop table 'nova_blog_posts' referenced by a foreign key constraint 'nova_blog_related_posts_post_id_foreign' on table 'nova_blog_related_posts'. (SQL: drop table if exists `nova_blog_posts`)

7.4.0 introduced related posts migration which breaks nova-blog migration rollback

Configuration file is not serializable

After installing the package, we get Your configuration files are not serializable.

This is because of the page_url function:

'page_url' => function (OptimistDigital\NovaBlog\Models\Post $post) {
        return env('APP_URL').'/blog/'.$post->slug;
},

[link] not showing

When using the editor to add a link it spits out [link](http://mylink.com). So when we show the blog content it just shows that. Shouldn't it be an <a> tag so we can just do {!! $content->attributes->text_content !!}

Bugs in flexible component

Now there is v.2.0.3 for nova-flexible component, where fix a lot of bugs.
I can't update this component, because requirements for nova-blog
"whitecube/nova-flexible-content": "^0.1.15"
Can you update composer.json file?

Nova 4.0?

When are you going support Nova 4.0 ?

installation fails

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for optimistdigital/nova-blog ^5.4 -> satisfiable by optimistdigital/nova-blog[5.4.0].
- Conclusion: remove optimistdigital/nova-locale-field 2.0.0
- Conclusion: don't install optimistdigital/nova-locale-field 2.0.0
- optimistdigital/nova-blog 5.4.0 requires optimistdigital/nova-locale-field ^1.1.1 -> satisfiable by optimistdigital/nova-locale-field[1.1.1, 1.1.2, 1.1.3, 1.1.4].
- Can only install one of: optimistdigital/nova-locale-field[1.1.1, 2.0.0].
- Can only install one of: optimistdigital/nova-locale-field[1.1.2, 2.0.0].
- Can only install one of: optimistdigital/nova-locale-field[1.1.3, 2.0.0].
- Can only install one of: optimistdigital/nova-locale-field[1.1.4, 2.0.0].
- Installation request for optimistdigital/nova-locale-field (locked at 2.0.0) -> satisfiable by optimistdigital/nova-locale-field[2.0.0].

pls help

Optional HTML Title

Great library! Love it. Blog Out Of The Box :)

Can you make the title as Text field? I really need it to be as Text field, not Title nor Trix but I do want to have Trix for content.

I can make a PR if you like.

prefix_tablenames

Please offer the functionality to prefix the table names over the config?
Categories is such a commonly used table name :)

DB::raw('NOW()') causes issues with sqlite

Due to the three uses of DB::raw('NOW()') within helpers.php, the site is unable to run using sqlite. Is there a specific reason these couldn't be replaced with now() instead?

No Image uploader on fresh install

Latest Version of Everything:
Laravel: v7.6.2
Nova: v3.4.0
nova-blog: v9.0.2
nova-drafts: v1.1.0
nova-lang: v1.2 (which was required to even get the Nova-Blog to work at all)

Steps to reproduce:

  • Install latest version of laravel
  • Install latest version of Nova
  • Install nova-blog, nova-drafts, nova-lang
  • Make a category
  • Try to make an image in post content

This is what I see on my screen. And when I inspect the code that field is completely empty.
nova-blog-no-image-uploader

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.