utils/wp-api/converters
Functions
'Read the “', Functions, '” section'ConvertToPageContent()
'Read the “', ConvertToPageContent(), '” section'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.
Parameters
'Read the “', Parameters, '” section'The data of the page to be converted.
authorId?
'Read the “', authorId?, '” section'null
| string
categories?
'Read the “', categories?, '” section'unknown
contentLang?
'Read the “', contentLang?, '” section'string
contributorIds?
'Read the “', contributorIds?, '” section'unknown
description
'Read the “', description, '” section'string
null
| boolean
heroImage?
'Read the “', heroImage?, '” section'string
string
string
parentFolder?
'Read the “', parentFolder?, '” section'null
| string
publishedAt?
'Read the “', publishedAt?, '” section'Date
showAuthor?
'Read the “', showAuthor?, '” section'null
| boolean
showContributors?
'Read the “', showContributors?, '” section'null
| boolean
showOnNav?
'Read the “', showOnNav?, '” section'boolean
string
unknown
string
updatedAt?
'Read the “', updatedAt?, '” section'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.
ConvertToPageData()
'Read the “', ConvertToPageData(), '” section'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.
Parameters
'Read the “', Parameters, '” section'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.
ConvertToPostContent()
'Read the “', ConvertToPostContent(), '” section'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.
Parameters
'Read the “', Parameters, '” section'The data of the page to which the post content belongs.
authorId?
'Read the “', authorId?, '” section'null
| string
categories?
'Read the “', categories?, '” section'unknown
contentLang?
'Read the “', contentLang?, '” section'string
contributorIds?
'Read the “', contributorIds?, '” section'unknown
description
'Read the “', description, '” section'string
null
| boolean
heroImage?
'Read the “', heroImage?, '” section'string
string
string
parentFolder?
'Read the “', parentFolder?, '” section'null
| string
publishedAt?
'Read the “', publishedAt?, '” section'Date
showAuthor?
'Read the “', showAuthor?, '” section'null
| boolean
showContributors?
'Read the “', showContributors?, '” section'null
| boolean
showOnNav?
'Read the “', showOnNav?, '” section'boolean
string
unknown
string
updatedAt?
'Read the “', updatedAt?, '” section'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.
ConvertToPostData()
'Read the “', ConvertToPostData(), '” section'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.
Parameters
'Read the “', Parameters, '” section'unknown
The post object to be converted.
useBlogPkg
'Read the “', useBlogPkg, '” section'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.
generateCategories()
'Read the “', generateCategories(), '” section'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.
Parameters
'Read the “', Parameters, '” section'categories
'Read the “', categories, '” section'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:
- Iterates over the provided category IDs.
- Checks if each category already exists in the database.
- If a category does not exist, fetches the category data from the specified API endpoint.
- Collects the new category data.
- Maps the new category data to the database schema.
- Inserts the new categories into the database.
generateTags()
'Read the “', generateTags(), '” section'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.
Parameters
'Read the “', Parameters, '” section'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.