utils/wp-api/converters
Esta página aún no está disponible en tu idioma.
Functions
Section titled “Functions”ConvertToPageContent()
Section titled “ConvertToPageContent()”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
Section titled “Parameters”pageData
Section titled “pageData”The data of the page to be converted.
authorId?
Section titled “authorId?”null
| string
categories?
Section titled “categories?”unknown
contentLang?
Section titled “contentLang?”string
contributorIds?
Section titled “contributorIds?”unknown
description
Section titled “description”string
draft?
Section titled “draft?”null
| boolean
heroImage?
Section titled “heroImage?”string
string
package?
Section titled “package?”string
parentFolder?
Section titled “parentFolder?”null
| string
publishedAt?
Section titled “publishedAt?”Date
showAuthor?
Section titled “showAuthor?”null
| boolean
showContributors?
Section titled “showContributors?”null
| boolean
showOnNav?
Section titled “showOnNav?”boolean
string
unknown
string
updatedAt?
Section titled “updatedAt?”null
| Date
unknown
The raw page content to be converted.
Returns
Section titled “Returns”Promise
<{
content
: null
| string
;
contentId
: string
;
contentLang
: string
;
id
: string
;
}>
A promise that resolves to a PageContent object.
Throws
Section titled “Throws”Will throw an error if the pageData is missing an id.
ConvertToPageData()
Section titled “ConvertToPageData()”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
Section titled “Parameters”unknown
The page object to convert. This is expected to be of an unknown type.
endpoint
Section titled “endpoint”string
The API endpoint to fetch additional data, such as media.
Returns
Section titled “Returns”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.
Throws
Section titled “Throws”Will throw an error if fetching the title image fails.
ConvertToPostContent()
Section titled “ConvertToPostContent()”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
Section titled “Parameters”pageData
Section titled “pageData”The data of the page to which the post content belongs.
authorId?
Section titled “authorId?”null
| string
categories?
Section titled “categories?”unknown
contentLang?
Section titled “contentLang?”string
contributorIds?
Section titled “contributorIds?”unknown
description
Section titled “description”string
draft?
Section titled “draft?”null
| boolean
heroImage?
Section titled “heroImage?”string
string
package?
Section titled “package?”string
parentFolder?
Section titled “parentFolder?”null
| string
publishedAt?
Section titled “publishedAt?”Date
showAuthor?
Section titled “showAuthor?”null
| boolean
showContributors?
Section titled “showContributors?”null
| boolean
showOnNav?
Section titled “showOnNav?”boolean
string
unknown
string
updatedAt?
Section titled “updatedAt?”null
| Date
unknown
The post data to be converted.
Returns
Section titled “Returns”Promise
<{
content
: null
| string
;
contentId
: string
;
contentLang
: string
;
id
: string
;
}>
A promise that resolves to a PageContent object.
Throws
Section titled “Throws”Will throw an error if the pageData is missing an id.
ConvertToPostData()
Section titled “ConvertToPostData()”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
Section titled “Parameters”unknown
The post object to be converted.
useBlogPkg
Section titled “useBlogPkg”boolean
A boolean indicating whether to use the blog package.
endpoint
Section titled “endpoint”string
The API endpoint to fetch additional data.
Returns
Section titled “Returns”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.
Throws
Section titled “Throws”Will throw an error if fetching the title image or downloading the post image fails.
generateCategories()
Section titled “generateCategories()”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
Section titled “Parameters”categories
Section titled “categories”number
[]
An array of category IDs to be processed.
endpoint
Section titled “endpoint”string
The API endpoint to fetch category data from.
Returns
Section titled “Returns”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()
Section titled “generateTags()”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
Section titled “Parameters”number
[]
An array of tag IDs to be processed.
endpoint
Section titled “endpoint”string
The API endpoint to fetch tag data from.
Returns
Section titled “Returns”Promise
<void
>
A promise that resolves when the operation is complete.
Example
Section titled “Example”const tags = [1, 2, 3];const endpoint = 'https://example.com/wp-json/wp/v2';await generateTags(tags, endpoint);
Remarks
Section titled “Remarks”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.