Skip to content

utils/wp-api/converters

function ConvertToPageContent(pageData: {
authorId: null | string;
categories: unknown;
contentLang: string;
contributorIds: unknown;
description: string;
draft: null | boolean;
heroImage: string;
id: string;
package: string;
parentFolder: null | string;
publishedAt: Date;
showAuthor: null | boolean;
showContributors: null | boolean;
showOnNav: boolean;
slug: string;
tags: unknown;
title: string;
updatedAt: null | Date;
}, page: unknown): Promise<{
content: null | string;
contentId: string;
contentLang: string;
id: string;
}>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/converters.ts:67

Converts the provided page data and page content into a PageContent object.

The data of the page to be converted.

null | string

unknown

string

unknown

string

null | boolean

string

string

string

null | string

Date

null | boolean

null | boolean

boolean

string

unknown

string

null | Date

unknown

The raw page content to be converted.

Promise<{ content: null | string; contentId: string; contentLang: string; id: string; }>

A promise that resolves to a PageContent object.

Will throw an error if the pageData is missing an id.


function ConvertToPageData(page: unknown, endpoint: string): Promise<{
authorId: null | string;
categories: unknown;
contentLang: string;
contributorIds: unknown;
description: string;
draft: null | boolean;
heroImage: string;
id: string;
package: string;
parentFolder: null | string;
publishedAt: Date;
showAuthor: null | boolean;
showContributors: null | boolean;
showOnNav: boolean;
slug: string;
tags: unknown;
title: string;
updatedAt: null | Date;
}>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/converters.ts:31

Converts a given page object to a PageData object.

unknown

The page object to convert. This is expected to be of an unknown type.

string

The API endpoint to fetch additional data, such as media.

Promise<{ authorId: null | string; categories: unknown; contentLang: string; contributorIds: unknown; description: string; draft: null | boolean; heroImage: string; id: string; package: string; parentFolder: null | string; publishedAt: Date; showAuthor: null | boolean; showContributors: null | boolean; showOnNav: boolean; slug: string; tags: unknown; title: string; updatedAt: null | Date; }>

A promise that resolves to a PageData object containing the converted page data.

Will throw an error if fetching the title image fails.


function ConvertToPostContent(pageData: {
authorId: null | string;
categories: unknown;
contentLang: string;
contributorIds: unknown;
description: string;
draft: null | boolean;
heroImage: string;
id: string;
package: string;
parentFolder: null | string;
publishedAt: Date;
showAuthor: null | boolean;
showContributors: null | boolean;
showOnNav: boolean;
slug: string;
tags: unknown;
title: string;
updatedAt: null | Date;
}, post: unknown): Promise<{
content: null | string;
contentId: string;
contentLang: string;
id: string;
}>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/converters.ts:275

Converts the given post data to a PageContent object.

The data of the page to which the post content belongs.

null | string

unknown

string

unknown

string

null | boolean

string

string

string

null | string

Date

null | boolean

null | boolean

boolean

string

unknown

string

null | Date

unknown

The post data to be converted.

Promise<{ content: null | string; contentId: string; contentLang: string; id: string; }>

A promise that resolves to a PageContent object.

Will throw an error if the pageData is missing an id.


function ConvertToPostData(
post: unknown,
useBlogPkg: boolean,
endpoint: string): Promise<{
authorId: null | string;
categories: unknown;
contentLang: string;
contributorIds: unknown;
description: string;
draft: null | boolean;
heroImage: string;
id: string;
package: string;
parentFolder: null | string;
publishedAt: Date;
showAuthor: null | boolean;
showContributors: null | boolean;
showOnNav: boolean;
slug: string;
tags: unknown;
title: string;
updatedAt: null | Date;
}>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/converters.ts:228

Converts a given post object to PageData format.

unknown

The post object to be converted.

boolean

A boolean indicating whether to use the blog package.

string

The API endpoint to fetch additional data.

Promise<{ authorId: null | string; categories: unknown; contentLang: string; contributorIds: unknown; description: string; draft: null | boolean; heroImage: string; id: string; package: string; parentFolder: null | string; publishedAt: Date; showAuthor: null | boolean; showContributors: null | boolean; showOnNav: boolean; slug: string; tags: unknown; title: string; updatedAt: null | Date; }>

A promise that resolves to the converted PageData object.

Will throw an error if fetching the title image or downloading the post image fails.


function generateCategories(categories: number[], endpoint: string): Promise<void>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/converters.ts:113

Generates and inserts categories into the database if they do not already exist.

number[]

An array of category IDs to be processed.

string

The API endpoint to fetch category data from.

Promise<void>

A promise that resolves when the categories have been processed and inserted into the database.

This function performs the following steps:

  1. Iterates over the provided category IDs.
  2. Checks if each category already exists in the database.
  3. If a category does not exist, fetches the category data from the specified API endpoint.
  4. Collects the new category data.
  5. Maps the new category data to the database schema.
  6. Inserts the new categories into the database.

function generateTags(tags: number[], endpoint: string): Promise<void>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/converters.ts:176

Generates and inserts tags into the database if they do not already exist.

number[]

An array of tag IDs to be processed.

string

The API endpoint to fetch tag data from.

Promise<void>

A promise that resolves when the operation is complete.

const tags = [1, 2, 3];
const endpoint = 'https://example.com/wp-json/wp/v2';
await generateTags(tags, endpoint);

This function checks if each tag ID already exists in the database. If a tag does not exist, it fetches the tag data from the specified API endpoint and inserts it into the database. The function logs messages to the console for each tag that is processed.