Skip to main content

Sluggable

sluggable is a custom-cast function that generates a slug from model's value i.e name field.

It works with strings and localized values as well.

Usage

In your post model, add the following:

src/app/posts/models/post.ts
import { Model, Casts } from "@warlock.js/cascade";
import { sluggable } from "@warlock.js/core";

export class Post extends Model {
/**
* {@inheritDoc}
*/
protected casts: Casts = {
title: "localized",
description: "localized",
shortDescription: "localized",
isActive: "boolean",
};

/**
* {@inheritdoc}
*/
protected customCasts = {
slug: sluggable("title"),
};
}

This will generate slug value every time the post is saved.

If the title field is localized, the slug will be generated from the english locale code (en).