Source

admin-bro-blog/src/types/blog-options.type.ts

import { UploadOptions } from '@admin-bro/upload'

type UploadOptionsProvider = UploadOptions['provider']

/**
 * Configuration options for @softwarebrothers/admin-bro-blog feature
 *
 * @alias BlogOptions
 * @memberof module:@softwarebrothers/admin-bro-blog
 */
export type BlogOptions = {
  properties: {
    /**
     * Database property holding post title: should be a string type
     */
    title: string;

    /**
     * Database property holding html body: should allow to save long texts
     */
    body: string;

    /**
     * Property holding post status
     */
    status: string;

    /**
     * URL of the post - so called slug. It is optional but highly recommended.
     */
    postUrl?: string;

    /**
     * A brief information regarding the Blog post. Blog excerpts give your readers a taste or
     * teaser of a full blog post. When visitors see an excerpt that grabs their attention,
     * they can click the title, image, or Read More link to open the full post.
     */
    excerpt?: string;

    /**
     * OpenGraph Tags which should be placed in the head of the page.
     * @softwarebrothers/admin-bro-blog assumes that this property will be of type 'mixed', because
     * we will have to store there both `title` and `description`. In order to achieve that set
     * type to `jsonb` in SQL or define schema containing title and description in MongoDB.
     */
    ogTags?: string,

    /**
     * Similar to ogTags - facebook meta also has to be of type `mixed` which allows to add title
     * and description sub-properties
     */
    facebookMeta?: string,

    /**
     * Similar to ogTags - twitter meta also has to be of type `mixed` which allows to add title
     * and description sub-properties
     */
    twitterMeta?: string,

    /**
     * Post image holds the main image which will be assigned to the post. You should use here
     * a `mixed` type which will hold: 'key', 'mimeType', 'bucket', 'size' sub-properties, required
     * by @admin-bro/upload. To use postImage you have to fill `uploadProvider` options as well.
     */
    postImage?: string;

    /**
     * Inline images holds the images uploaded by the editor. Property selected here should be
     * a `mixed` type which will hold: 'key', 'mimeType', 'bucket', 'size' sub-properties as arrays.
     * This is required by @admin-bro/upload.
     * To use inlineImages you have to fill `uploadProvider` options as well.
     */
    inlineImages?: string;

    /**
     * updatedAt column which is used to hold the information about the update date.
     * @softwarebrothers/blog doesn't update this field - it should be updated by the ORM
     */
    updatedAt?: string;
  }
  /**
   * Set in case blog should have tags. Tags are implemented as one to many
   */
  tags?: {
    property: string;
    resourceId: string;
    nameColumn?: string;
  },
  /**
   * {@link UploadOptions Upload provider options} passed to @admin-bro/upload peerDependency.
   * If you use either postImage or inlineImages you have to make sure that this is set.
   */
  uploadProvider?: UploadOptionsProvider;
}

export type BlogOptionsWithDefault = {
  tags: Required<BlogOptions['tags']>;
  properties: BlogOptions['properties'];
  uploadProvider?: BlogOptions['uploadProvider'];
}

export const AVAILABLE_PROPERTIES = [
  'title',
  'body',
  'status',
  'postUrl',
  'excerpt',
  'ogTags',
  'facebookMeta',
  'twitterMeta',
  'postImage',
  'inlineImages',
  'updatedAt',
] as const

// Following code is used as a TypeScript check that variable availableProperties has all the
// keys from BlogOptions['properties']. So in case someone adds new property and forgets to do this
// here - build will fail.
export type AvailableProperties = typeof AVAILABLE_PROPERTIES[number]
type MissingKeys = Required<Omit<BlogOptions['properties'], AvailableProperties>>

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const hasMissingKeys: MissingKeys = {} as const
SoftwareBrothers

Proudly built and maintained by SoftwareBrothers

Software House with a passion for both JavaScript and TypeScript.

See what we do See what we believe in

Proudly built and maintained by

SoftwareBrothers