Develop Mini Blog with Directus - Part 2

directus | Directus, Headless CMS NextJS | 2024-10-21

Pre-requisite

  • Basic understanding about Directus and NextJS

Mini Blog Series

We are setting up Directus

How do we setup?

On the default screen (Content tab) - we can start to create collection.

Screenshot1

We are going to create a blog collection, name blog, set type to Generated UUID

and tick all Optional Fields

Screenshot2

Collection Setup


Screenshot3

Optional Fields


For the blog fields

FieldTypeInterfaceSetting
titleStringInputRequired
typeStringDropdown (News, Campaign)Required
slugTextInput (Trim, Slugify)Required
externalTextInput

Validation

{"and":[{"external":{"regex":"^(https):\/\/([a-zA-Z0-9-]+\.)+[a-zA-Z]6(\:[0-9]+)?(\/[a-zA-Z0-9-])(\?[a-zA-Z0-9_&%=+-])?(#[a-zA-Z0-9_-])?$"}}]}

imageUUIDImage 
startDateDateTime

Default - Set true for Hide on Details Condition:

  • SHOW if TYPE = Campaign
  • {"_and":[{"type":{"_eq":"campaign"}}]}
  • Set false - Hidden on Details
  • Set true - Required
endDateDateTime

Default - Set true for Hide on Details Condition:

  • SHOW if TYPE = Campaign
  • {"_and":[{"type":{"_eq":"campaign"}}]}
  • Set false - Hidden on Details
  • Set true - Required
publishedDateDateTime

Default - Set true for Hide on Details Condition:

  • SHOW if TYPE = News
  • {"_and":[{"type":{"_eq":"news"}}]}
  • Set false - Hidden on Details
  • Set true - Required
contentTextWYSIWYG 

The editing screen looks like this

Screenshot4


Condition and Validation that setup earlier will be in place, e.g.

Required fields

Screenshot5


Select Type = News

Screenshot6

Screenshot7


Select Type = Campaign

Screenshot8


Wrong link format

Screenshot9


Setup some contents for integration with NextJS later.

Screenshot10


References