Module: @headstartwp/core
Namespaces
Enumerations
Classes
- AbstractFetchStrategy
- AppSettingsStrategy
- AuthorArchiveFetchStrategy
- Comment
- ConfigError
- Element
- EndpointError
- FetchError
- FrameworkError
- NotFoundError
- PostOrPostsFetchStrategy
- PostsArchiveFetchStrategy
- ProcessingInstruction
- SearchFetchStrategy
- SearchNativeFetchStrategy
- SinglePostFetchStrategy
- TaxonomyTermsStrategy
- Text
- VerifyTokenFetchStrategy
Interfaces
- AppEntity
- AttachmentEntity
- AuthorEntity
- AvatarUrls
- CommentEntity
- EndpointParams
- Entity
- FetchOptions
- FetchResponse
- FilterDataOptions
- HTMLReactParserOptions
- Integration
- MenuItemEntity
- PageEntity
- PageInfo
- PolylangIntegration
- PostEntity
- PostOrPostsParams
- PostParams
- PostSearchEntity
- PostTypeEntity
- PostsArchiveParams
- Rendered
- RevisionEntity
- SearchEntity
- SearchObjectEntity
- SearchParams
- TaxonomyArchiveParams
- TaxonomyEntity
- TermEntity
- TermSearchEntity
- TypeEntity
- VerifyTokenParams
- YoastSEOIntegration
DOM Helpers
isAnchorTag
▸ isAnchorTag(node
, options?
, site?
): node is Element
Checks if the provided node is an valid anchor tag
This function expects to be used with DOMNode
objects from html-react-parser
, which is
the underlying parser used by BlocksRenderer.
Usage
import { isAnchorTag } from '@headstartwp/core';
import { LinkBlock } from '@10up/headless-next';
<BlocksRenderer html={html}>
<LinkBlock test={(node) => isAnchorTag(node, { isInternalLink: true})} />
</BlocksRenderer>
Parameters
Name | Type | Default value | Description |
---|---|---|---|
node | DOMNode | undefined | The node to test |
options | isAnchorTagOptions | {} | Supported options |
site | undefined | HeadlessConfig | undefined |
Returns
node is Element
Whether it's an anchor tag according to the options passed
Defined in
packages/core/src/dom/index.ts:77
isBlock
▸ isBlock(node
, _options
): boolean
Tests a node by tagName and/or className
This function expects to be used with DOMNode
objects from html-react-parser
, which is
the underlying parser used by BlocksRenderer.
Usage
import { isBlock } from '@headstartwp/core';
<BlocksRenderer html={html}>
<MyCustomBlock
test={(node) => isBlock(node, { tagName: 'div', classList: ['block-class-name'] })}
/>
</BlocksRenderer>
Parameters
Name | Type | Description |
---|---|---|
node | DOMNode | The node to test |
_options | isBlockOptions |
Returns
boolean
true if the node passes the test
Defined in
packages/core/src/dom/index.ts:278
isBlockByName
▸ isBlockByName(node
, name
): boolean
Tests a node by block name. This requires the Headless WP Plugin to be installed.
The Headless WP Plugin will append data-wp-block-name
and data-wp-block
to every block,
this function relies on those attributes to determine if the node is a block.
This function expects to be used with DOMNode
objects from html-react-parser
, which is
the underlying parser used by BlocksRenderer.
Usage
import { isBlockByName } from '@headstartwp/core';
<BlocksRenderer html={html}>
<MyCustomBlock
test={(node) => isBlock(node, 'core/paragraph')}
/>
</BlocksRenderer>
Parameters
Name | Type | Description |
---|---|---|
node | DOMNode | The node to test |
name | string | The block name |
Returns
boolean
true if the node passes the test
Defined in
packages/core/src/dom/index.ts:334
isImageTag
▸ isImageTag(node
, options?
): string
| boolean
Checks if the provided node is an valid image tag
This function expects to be used with DOMNode
objects from html-react-parser
, which is
the underlying parser used by BlocksRenderer.
Usage
import { isImageTag, ImageBlock } from '@headstartwp/core';
import { ImageComponent } from '@10up/headless-next';
<BlocksRenderer html={html}>
<ImageBlock
test={(node) => isImageTag(node, { hasDimensions: true})}
component={ImageComponent}
/>
</BlocksRenderer>
Parameters
Name | Type | Description |
---|---|---|
node | DOMNode | The node to test |
options | isImageTagOptions | Supported options. |
Returns
string
| boolean
Whether it's an image tag or not according to the options passed
Defined in
packages/core/src/dom/index.ts:141
isTwitterEmbed
▸ isTwitterEmbed(node
): boolean
Checks if the node is an twitter embed
This function expects to be used with DOMNode
objects from html-react-parser
, which is
the underlying parser used by BlocksRenderer.
Usage
import { isTwitterEmbed } from '@headstartwp/core';
<BlocksRenderer html={html}>
<MyTwitterBlock
test={isTwitterEmbed}
/>
</BlocksRenderer>
Parameters
Name | Type | Description |
---|---|---|
node | DOMNode | The node to test |
Returns
boolean
true if the node is a twitter embed
Defined in
packages/core/src/dom/index.ts:227
isYoutubeEmbed
▸ isYoutubeEmbed(node
): boolean
Checks if the node is an youtube embed
This function expects to be used with DOMNode
objects from html-react-parser
, which is
the underlying parser used by BlocksRenderer.
Usage
import { isYoutubeEmbed } from '@headstartwp/core';
<BlocksRenderer html={html}>
<MyYoutubeBlock
test={isYoutubeEmbed}
/>
</BlocksRenderer>
Parameters
Name | Type | Description |
---|---|---|
node | DOMNode | The node to test |
Returns
boolean
true if the node is a youtube embed
Defined in
packages/core/src/dom/index.ts:187
wpKsesPost
▸ wpKsesPost(content
, allowList?
, options?
): string
Sanitize HTML content by the wp_kses_post() requirements
Usage
import { wpKsesPost } from '@headstartwp/core';
wpKsesPost(html);
See
https://codex.wordpress.org/Function_Reference/wp_kses_post
Parameters
Name | Type | Description |
---|---|---|
content | string | The content to sanitize. |
allowList? | IWhiteList | Optional. The list of allowed HTML tags and attributes. If not set, the default allow list will be used. |
options? | IWpKsesPostOptions | Optional. IWpKsesPostOptions. |
Returns
string
Sanitized string of HTML.
Defined in
packages/core/src/dom/wpKsesPost.ts:32
Data Fetching
apiGet
▸ apiGet(url
, args?
, burstCache?
): Promise
<{ headers
: { [index: string]
: any
; } = receivedHeaders; json
: any
}>
Fetch Wrapper to handle GET requests.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
url | string | undefined | The URL where to make the request to |
args | Object | {} | The arguments |
burstCache | boolean | false | Whether it should burst cache |
Returns
Promise
<{ headers
: { [index: string]
: any
; } = receivedHeaders; json
: any
}>
Defined in
packages/core/src/data/api/fetch-utils.ts:46
apiPost
▸ apiPost(url
, args?
): Promise
<any
>
Fetch Wrapper to handle POST requests
Parameters
Name | Type | Description |
---|---|---|
url | string | The URL where to make the request to |
args | Object | The arguments |
Returns
Promise
<any
>
Defined in
packages/core/src/data/api/fetch-utils.ts:17
Data Handling
getPostAuthor
▸ getPostAuthor(post
): AuthorEntity
[]
Returns the author object from the post object if it exists
Parameters
Name | Type | Description |
---|---|---|
post | PostEntity | PostSearchEntity | The Post object |
Returns
Defined in
packages/core/src/data/utils/postHandling.ts:11
getPostTerms
▸ getPostTerms(post
): Record
<string
, TermEntity
[]>
Returns the terms associated with the post
Parameters
Name | Type | Description |
---|---|---|
post | PostEntity | PostSearchEntity | The Post object |
Returns
Record
<string
, TermEntity
[]>
Defined in
packages/core/src/data/utils/postHandling.ts:22
Other
CustomPostType
Ƭ CustomPostType: Object
Type declaration
Name | Type | Description |
---|---|---|
archive? | string | - |
endpoint | string | - |
matchSinglePath? | boolean | Whether this custom post type should match the archive path If set to true, then when querying a post type archive page such as /[post-type]/[post-name] the post.link property should match the current path. This will avoid matching nested posts/pages that doesn't exist for instance: /[post-type]/fake-parent-page/[post-name] will not match if this option is set to true even though post-name exists. It is strongly recommended to set this option to true, otherwise hierarchical post types (such as pages) will not work properly. Default true |
single? | string | - |
slug | string | - |
Defined in
CustomPostTypes
Ƭ CustomPostTypes: CustomPostType
[]
Defined in
CustomTaxonomies
Ƭ CustomTaxonomies: CustomTaxonomy
[]
Defined in
CustomTaxonomy
Ƭ CustomTaxonomy: Object
Type declaration
Name | Type | Description |
---|---|---|
endpoint | string | - |
matchArchivePath? | boolean | Whether this custom taxonomy should match the archive path If set to true, then when querying a taxonomy archive page such as /[taxonmy-slug]/[term-slug] the term.link property should match the current path. This will avoid matching nested categories that doesn't exist for instance: /[taxonmy-slug]/fake-parent-term/[term-slug] will not match if this option is set to true even though term-slug exists. Default false |
restParam? | string | - |
rewrite? | string | - |
slug | string | - |
Defined in
DOMNode
Ƭ DOMNode: Comment
| Element
| Node
| ProcessingInstruction
| Text
Defined in
node_modules/html-react-parser/index.d.ts:21
FetchStrategyCacheConfig
Ƭ FetchStrategyCacheConfig: Object
Type declaration
Name | Type | Description |
---|---|---|
afterGet? | <E, P, R>(options : FetchStrategyCacheHandlerOptions <E , P , R >, data : FetchResponse <R >) => Promise <FetchResponse <R >> | If set, this function will be executed after restoring data from cache (cache.get) and can be used to reconstruct things that were removed in beforeSet. |
beforeSet? | <E, P, R>(options : FetchStrategyCacheHandlerOptions <E , P , R >, data : FetchResponse <R >) => Promise <FetchResponse <R >> | If set, this function will be executed before calling the cache.set method It's useful if you want to remove things from the data before caching. |
cacheHandler? | FetchStrategyCacheHandler | A custom cache handler implementation If set will override the default in-memory cache handler |
enabled? | boolean | <E, P, R>(options : FetchStrategyCacheHandlerOptions <E , P , R >) => boolean | Whether the cache should be enable globably or for a given fetchStrategy |
ttl? | number | <E, P, R>(options : FetchStrategyCacheHandlerOptions <E , P , R >) => number | TTL in seconds |
Defined in
FetchStrategyCacheHandler
Ƭ FetchStrategyCacheHandler: Object
Type declaration
Name | Type |
---|---|
get | <T>(key : string ) => Promise <T > |
set | <T>(key : string , data : T , ttl : number ) => Promise <void > |
Defined in
FetchStrategyCacheHandlerOptions
Ƭ FetchStrategyCacheHandlerOptions<E
, P
, R
>: Object
Type parameters
Name | Type |
---|---|
E | E |
P | extends EndpointParams |
R | R |
Type declaration
Name | Type |
---|---|
cacheHandler | FetchStrategyCacheHandler |
fetchStrategy | AbstractFetchStrategy <E , P , R > |
fetchStrategyOptions? | Partial <FetchOptions > |
params | Partial <P > |
path | string |
Defined in
HTMLParser2Options
Ƭ HTMLParser2Options: ParserOptions
& DomHandlerOptions
Defined in
node_modules/html-react-parser/index.d.ts:19
HeadlessConfig
Ƭ HeadlessConfig: Object
Type declaration
Name | Type |
---|---|
cache? | FetchStrategyCacheConfig |
customPostTypes? | CustomPostTypes | (defaultPostTypes : CustomPostTypes ) => CustomPostTypes |
customTaxonomies? | CustomTaxonomies | (defaultTaxonomies : CustomTaxonomies ) => CustomTaxonomies |
debug? | { devMode? : boolean ; redirects? : boolean ; requests? : boolean } |
debug.devMode? | boolean |
debug.redirects? | boolean |
debug.requests? | boolean |
host? | string |
hostUrl? | string |
integrations? | Integrations |
locale? | string |
preview? | PreviewConfig |
redirectStrategy? | RedirectStrategy |
sites? | HeadlessConfig [] |
sourceUrl? | string |
useWordPressPlugin? | boolean |
Defined in
packages/core/src/types.ts:140
Integrations
Ƭ Integrations: Object
Type declaration
Name | Type |
---|---|
polylang? | PolylangIntegration |
yoastSEO? | YoastSEOIntegration |
Defined in
Matcher
Ƭ Matcher: Object
Type declaration
Name | Type |
---|---|
name | string |
pattern | string |
priority | number |
Defined in
packages/core/src/data/utils/matchers.ts:1
NormalizedDataForCache
Ƭ NormalizedDataForCache<T
, P
>: Object
Type parameters
Name |
---|
T |
P |
Type declaration
Name | Type |
---|---|
additionalCacheObjects? | NormalizedDataForCache <T , P >[] |
data | FetchResponse <T > |
key | { args : Partial <P > ; url : string } |
key.args | Partial <P > |
key.url | string |
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:99
PostOrPostsFetchStrategyResult
Ƭ PostOrPostsFetchStrategyResult<T
>: Object
Type parameters
Name |
---|
T |
Type declaration
Name | Type |
---|---|
data | T | T [] |
isArchive | boolean |
isSingle | boolean |
Defined in
packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:42
PreviewConfig
Ƭ PreviewConfig: Object
Type declaration
Name | Type | Description |
---|---|---|
alternativeAuthorizationHeader? | boolean | Flag to enable using the alternative authorization header. This can be useful if you have separate JWT-based authentication on your project. |
usePostLinkForRedirect? | boolean | If enabled, it will use the post.link property of the REST response to redirect to the appropriate route for previewing |
Defined in
QueriedObject
Ƭ QueriedObject: Object
The QueriedObject represents the object that the current requests is subjected to.
Querying by taxonomy and/or author will set the queried object.
Type declaration
Name | Type | Description |
---|---|---|
author? | AuthorEntity | If the request is an author query, this will be populated with the author object |
search? | SearchEntity | If the request is a search query, this will be populated with the search entity object |
term? | TermEntity | If the request is a term query, this will be populated with the term object |
Defined in
packages/core/src/data/types/entities.ts:765
Redirect
Ƭ Redirect: Object
Type declaration
Name | Type |
---|---|
ID | number |
enable_regex | boolean |
post_status | string |
redirect_from | string |
redirect_to | string |
status_code | number |
Defined in
packages/core/src/data/types/entities.ts:705
RedirectData
Ƭ RedirectData: Object
Type declaration
Name | Type | Description |
---|---|---|
location | string | undefined | null | The redirect new location will be null if no redirect is found |
status | number | The status number of the redirect Will be 0 if the redirect is not found |
Defined in
packages/core/src/utils/fetchRedirect.ts:5
RedirectStrategy
Ƭ RedirectStrategy: "404"
| "none"
| "always"
Defined in
isAnchorTagOptions
Ƭ isAnchorTagOptions: Object
Type declaration
Name | Type | Description |
---|---|---|
isInternalLink? | boolean | If true, will check if the anchor tag contains a valid internal link. if target="_blank" then this option is not taken into account |
Defined in
packages/core/src/dom/index.ts:5
isBlockOptions
Ƭ isBlockOptions: Object
Type declaration
Name | Type | Description |
---|---|---|
className? | string | string [] | A single or array of classNames to check for If an array of class names is passed, the block will be considered valid if all of the class names are found |
tagName? | string | The tagName to check for |
Defined in
packages/core/src/dom/index.ts:238
isImageTagOptions
Ƭ isImageTagOptions: Object
Type declaration
Name | Type | Description |
---|---|---|
hasDimensions? | boolean | If true, will check if the image tag contains width and height attributes |
Defined in
packages/core/src/dom/index.ts:107
removeSourceUrlType
Ƭ removeSourceUrlType: Object
Type declaration
Name | Type | Description |
---|---|---|
backendUrl | string | The backend url. |
link | string | The link url, possibly with the source url. |
nonEmptyLink? | boolean | If the removal of source url from link leads to a empty string, this setting control whether a '/' should be returned or the empty string |
publicUrl? | string | The public url. Defaults to '/'. |
Defined in
packages/core/src/utils/removeSourceUrl.ts:3
authorArchivesMatchers
• Const
authorArchivesMatchers: Matcher
[]
Defined in
packages/core/src/data/utils/matchers.ts:43
endpoints
• Const
endpoints: Object
Type declaration
Name | Type |
---|---|
appSettings | string |
category | string |
pages | string |
posts | string |
search | string |
tags | string |
tokenVerify | string |
yoast | string |
Defined in
packages/core/src/utils/endpoints.ts:1
ksesAllowedList
• Const
ksesAllowedList: IWhiteList
Default Allowed HTML Attributes
See
https://codex.wordpress.org/Function_Reference/wp_kses_post
Defined in
packages/core/src/dom/wpKsesPost.ts:269
postMatchers
• Const
postMatchers: Matcher
[]
Defined in
packages/core/src/data/utils/matchers.ts:7
postsMatchers
• Const
postsMatchers: Matcher
[]
Defined in
packages/core/src/data/utils/matchers.ts:20
searchMatchers
• Const
searchMatchers: Matcher
[]
Defined in
packages/core/src/data/utils/matchers.ts:56
youtubeEmbedRegex
• Const
youtubeEmbedRegex: RegExp
Defined in
packages/core/src/dom/index.ts:160
HTMLReactParser
▸ HTMLReactParser(html
, options?
): ReturnType
<typeof domToReact
>
Converts HTML string to JSX element(s).
Parameters
Name | Type | Description |
---|---|---|
html | string | HTML string. |
options? | HTMLReactParserOptions | Parser options. |
Returns
ReturnType
<typeof domToReact
>
- JSX element(s), empty array, or string.
Defined in
node_modules/html-react-parser/index.d.ts:51
addQueryArgs
▸ addQueryArgs(url
, args
): string
Parameters
Name | Type |
---|---|
url | string |
args | Record <string , any > |
Returns
string
Defined in
packages/core/src/utils/url.ts:167
asyncForEach
▸ asyncForEach(array
, callback
): Promise
<void
>
Parameters
Name | Type |
---|---|
array | any [] |
callback | (el : any , index : number , array : any []) => void |
Returns
Promise
<void
>
Defined in
packages/core/src/utils/asyncForEach.ts:1
attributesToProps
▸ attributesToProps(attributes
, nodeName?
): Props
Converts HTML/SVG DOM attributes to React props.
Parameters
Name | Type | Description |
---|---|---|
attributes | Attributes | HTML/SVG DOM attributes. |
nodeName? | string | DOM node name. |
Returns
Props
- React props.
Defined in
node_modules/html-react-parser/lib/attributes-to-props.d.ts:17
buildQueryString
▸ buildQueryString(data
): string
Generates URL-encoded query string using input query data.
It is intended to behave equivalent as PHP's http_build_query
, configured
with encoding type PHP_QUERY_RFC3986 (spaces as %20
).
Example
const queryString = buildQueryString( {
simple: 'is ok',
arrays: [ 'are', 'fine', 'too' ],
objects: {
evenNested: {
ok: 'yes',
},
},
} );
// "simple=is%20ok&arrays%5B0%5D=are&arrays%5B1%5D=fine&arrays%5B2%5D=too&objects%5BevenNested%5D%5Bok%5D=yes"
Parameters
Name | Type | Description |
---|---|---|
data | Record <string , any > | Data to encode. |
Returns
string
Query string.
Defined in
packages/core/src/utils/url.ts:129
decodeHtmlSpeciaChars
▸ decodeHtmlSpeciaChars(text
): string
Decodes HTML special chars entities
Parameters
Name | Type | Description |
---|---|---|
text | string | The text we want to decode |
Returns
string
text with decoded html entities
Defined in
packages/core/src/utils/decodeHtmlSpeciaChars.ts:8
domToReact
▸ domToReact(nodes
, options?
): string
| JSX.Element
| JSX.Element
[]
Converts DOM nodes to JSX element(s).
Parameters
Name | Type | Description |
---|---|---|
nodes | DOMNode [] | DOM nodes. |
options? | HTMLReactParserOptions | Parser options. |
Returns
string
| JSX.Element
| JSX.Element
[]
- JSX element(s).
Defined in
node_modules/html-react-parser/lib/dom-to-react.d.ts:15
fetchRedirect
▸ fetchRedirect(pathname
, sourceUrl
): Promise
<RedirectData
>
Fetches a redirect from the WordPress origin by making a HEAD request and checking the response
Parameters
Name | Type | Description |
---|---|---|
pathname | string | The path to the page to fetch the redirect for |
sourceUrl | string | The source url |
Returns
Promise
<RedirectData
>
The redirect data
Defined in
packages/core/src/utils/fetchRedirect.ts:51
getAuthHeader
▸ getAuthHeader(): null
Returns
null
Defined in
packages/core/src/data/api/fetch-utils.ts:3
getCustomPostType
▸ getCustomPostType(slug
, sourceUrl?
): undefined
| CustomPostType
Returns a single post type by slug if defined
Parameters
Name | Type | Description |
---|---|---|
slug | string | post type slug |
sourceUrl? | string |
Returns
undefined
| CustomPostType
Defined in
packages/core/src/utils/config.ts:254
getCustomPostTypes
▸ getCustomPostTypes(sourceUrl?
): CustomPostTypes
Returns the available post types
Parameters
Name | Type |
---|---|
sourceUrl? | string |
Returns
Defined in
packages/core/src/utils/config.ts:231
getCustomPostTypesSlugs
▸ getCustomPostTypesSlugs(sourceUrl?
): string
[]
Returns the available post type slugs
Parameters
Name | Type |
---|---|
sourceUrl? | string |
Returns
string
[]
Defined in
packages/core/src/utils/config.ts:242
getCustomTaxonomies
▸ getCustomTaxonomies(sourceUrl?
): CustomTaxonomies
Returns the available taxonomies
Parameters
Name | Type |
---|---|
sourceUrl? | string |
Returns
Defined in
packages/core/src/utils/config.ts:191
getCustomTaxonomy
▸ getCustomTaxonomy(slug
, sourceUrl?
): undefined
| CustomTaxonomy
Returns a single post type by slug if defined
Parameters
Name | Type | Description |
---|---|---|
slug | string | post type slug |
sourceUrl? | string |
Returns
undefined
| CustomTaxonomy
Defined in
packages/core/src/utils/config.ts:220
getCustomTaxonomySlugs
▸ getCustomTaxonomySlugs(sourceUrl?
): string
[]
Returns the available taxonomy slugs
Parameters
Name | Type |
---|---|
sourceUrl? | string |
Returns
string
[]
Defined in
packages/core/src/utils/config.ts:203
getHeadlessConfig
▸ getHeadlessConfig(): Object
Returns the contents of headless.config.js
This function requires framework integration in order to work. The contents of headless.config.js
needs to be injected at build time into a global variable.
Make sure you are using one of the framework's integration (such as next) before using this function.
Returns
Object
The contents of headless.config.js
Name | Type |
---|---|
cache | undefined | FetchStrategyCacheConfig |
customPostTypes | CustomPostTypes |
customTaxonomies | CustomTaxonomies |
debug | undefined | { devMode? : boolean ; redirects? : boolean ; requests? : boolean } |
hostUrl | string |
integrations | undefined | Integrations |
preview | undefined | PreviewConfig |
redirectStrategy | RedirectStrategy |
sites | HeadlessConfig [] |
sourceUrl | undefined | string |
useWordPressPlugin | boolean |
Defined in
packages/core/src/utils/config.ts:22
getHeadstartWPConfig
▸ getHeadstartWPConfig(): Object
Returns the contents of headless.config.js
This function requires framework integration in order to work. The contents of headless.config.js
needs to be injected at build time into a global variable.
Make sure you are using one of the framework's integration (such as next) before using this function.
Returns
Object
The contents of headless.config.js
Name | Type |
---|---|
cache | undefined | FetchStrategyCacheConfig |
customPostTypes | CustomPostTypes |
customTaxonomies | CustomTaxonomies |
debug | undefined | { devMode? : boolean ; redirects? : boolean ; requests? : boolean } |
hostUrl | string |
integrations | undefined | Integrations |
preview | undefined | PreviewConfig |
redirectStrategy | RedirectStrategy |
sites | HeadlessConfig [] |
sourceUrl | undefined | string |
useWordPressPlugin | boolean |
Defined in
packages/core/src/utils/config.ts:22
getHostUrl
▸ getHostUrl(): string
Returns the WP URL based on the headless config
Returns
string
Defined in
packages/core/src/utils/config.ts:271
getQueryArgs
▸ getQueryArgs(url
): Record
<string
, any
>
Returns an object of query arguments of the given URL. If the given URL is invalid or has no querystring, an empty object is returned.
Example
const foo = getQueryArgs( 'https://wordpress.org?foo=bar&bar=baz' );
// { "foo": "bar", "bar": "baz" }
Parameters
Name | Type | Description |
---|---|---|
url | string | URL. |
Returns
Record
<string
, any
>
Query args object.
Defined in
packages/core/src/utils/url.ts:78
getQueryString
▸ getQueryString(url
): any
Parameters
Name | Type |
---|---|
url | string |
Returns
any
Defined in
packages/core/src/utils/url.ts:49
getSite
▸ getSite(site?
): HeadlessConfig
Get a config for a specific site
Parameters
Name | Type |
---|---|
site? | HeadlessConfig |
Returns
Defined in
packages/core/src/utils/config.ts:115
getSiteByHost
▸ getSiteByHost(hostOrUrl
, locale?
): null
| HeadlessConfig
Finds a site by host and optionally locale
Parameters
Name | Type | Description |
---|---|---|
hostOrUrl | string | The hostname |
locale? | string |
Returns
null
| HeadlessConfig
Defined in
packages/core/src/utils/config.ts:141
getSiteBySourceUrl
▸ getSiteBySourceUrl(sourceUrl
): HeadlessConfig
Get a site by source url
Parameters
Name | Type |
---|---|
sourceUrl | string |
Returns
HeadlessConfig
Defined in
packages/core/src/utils/config.ts:179
getWPUrl
▸ getWPUrl(): string
Returns the WP URL based on the headless config
Returns
string
Defined in
packages/core/src/utils/config.ts:263
htmlToDOM
▸ htmlToDOM(html
, options?
): (Comment
| Element
| ProcessingInstruction
| Text
)[]
Parses HTML string to DOM nodes in Node.js.
This is the same method as require('htmlparser2').parseDOM
https://github.com/fb55/htmlparser2/blob/v6.0.0/src/index.ts#L29-L41
Parameters
Name | Type | Description |
---|---|---|
html | string | HTML markup. |
options? | DomHandlerOptions | Parser options (https://github.com/fb55/domhandler/tree/v5.0.3#readme). |
Returns
(Comment
| Element
| ProcessingInstruction
| Text
)[]
- DOM nodes.
Defined in
node_modules/html-dom-parser/lib/server/html-to-dom.d.ts:21
isElement
▸ isElement(node
): node is Element
Checks if the node is an Element.
We rely on this function to avoid issues with instanceof.
See
https://github.com/10up/headstartwp/issues/504
Parameters
Name | Type | Description |
---|---|---|
node | DOMNode | The dom node |
Returns
node is Element
Whether the node is of type element or not
Defined in
packages/core/src/dom/index.ts:25
isExternalUrl
▸ isExternalUrl(link
): boolean
Checks if the provided link is an external Url.
Inspired on the Frontity implementation
See
https://github.com/frontity/frontity/blob/dev/packages/components/link/utils.ts
Parameters
Name | Type | Description |
---|---|---|
link | string | The link Url. |
Returns
boolean
True if the link is an external Url.
Defined in
packages/core/src/utils/isExternalUrl.ts:12
isInternalLink
▸ isInternalLink(url
, site?
): boolean
Checks if the url is for an internal link
Parameters
Name | Type | Description |
---|---|---|
url | string | The url to check |
site? | HeadlessConfig | (optional) the site config |
Returns
boolean
Defined in
packages/core/src/utils/isInternalLink.ts:14
log
▸ log(type
, ...args
): void
Parameters
Name | Type |
---|---|
type | LOGTYPE |
...args | any [] |
Returns
void
Defined in
packages/core/src/utils/log.ts:9
removeFieldsFromPostRelatedData
▸ removeFieldsFromPostRelatedData(fieldsToRemove
, post
): PostEntity
| { _embedded
: { author
: AuthorEntity
[] ; wp:featuredmedia
: any
; wp:term
: TermEntity
[][] } ; author?
: AuthorEntity
[] ; categories?
: number
[] ; comment_status?
: "open"
| "closed"
; content
: Rendered
; date
: string
; date_gmt
: string
; excerpt
: Rendered
; featured_media
: number
; format
: "link"
| "status"
| "standard"
| "aside"
| "chat"
| "gallery"
| "image"
| "quote"
| "video"
| "audio"
; guid
: Rendered
; id
: number
; link
: string
; meta
: Record
<string
, unknown
> ; modified
: string
; modified_gmt
: string
; ping_status
: "open"
| "closed"
; slug
: string
; status
: "publish"
| "future"
| "draft"
| "pending"
| "private"
; sticky
: boolean
; tags?
: number
[] ; template
: string
; terms?
: Record
<string
, TermEntity
[]> ; title
: Rendered
; type
: string
; yoast_head?
: null
| string
; yoast_head_json?
: null
| Record
<string
, any
> }
Parameters
Name | Type |
---|---|
fieldsToRemove | (string | number )[] |
post | PostEntity |
Returns
PostEntity
| { _embedded
: { author
: AuthorEntity
[] ; wp:featuredmedia
: any
; wp:term
: TermEntity
[][] } ; author?
: AuthorEntity
[] ; categories?
: number
[] ; comment_status?
: "open"
| "closed"
; content
: Rendered
; date
: string
; date_gmt
: string
; excerpt
: Rendered
; featured_media
: number
; format
: "link"
| "status"
| "standard"
| "aside"
| "chat"
| "gallery"
| "image"
| "quote"
| "video"
| "audio"
; guid
: Rendered
; id
: number
; link
: string
; meta
: Record
<string
, unknown
> ; modified
: string
; modified_gmt
: string
; ping_status
: "open"
| "closed"
; slug
: string
; status
: "publish"
| "future"
| "draft"
| "pending"
| "private"
; sticky
: boolean
; tags?
: number
[] ; template
: string
; terms?
: Record
<string
, TermEntity
[]> ; title
: Rendered
; type
: string
; yoast_head?
: null
| string
; yoast_head_json?
: null
| Record
<string
, any
> }
Defined in
packages/core/src/data/utils/postHandling.ts:51
removeSourceUrl
▸ removeSourceUrl(«destructured»
): string
Make the link relative if it belongs to the backend, to force client-side navigation.
Inspired on the Frontity implementation
See
https://github.com/frontity/frontity/blob/dev/packages/components/link/utils.ts
Parameters
Name | Type |
---|---|
«destructured» | removeSourceUrlType |
Returns
string
The URL without the Source URL.
Defined in
packages/core/src/utils/removeSourceUrl.ts:42
setHeadlessConfig
▸ setHeadlessConfig(config
): void
Parameters
Name | Type |
---|---|
config | HeadlessConfig |
Returns
void
Defined in
packages/core/src/utils/config.ts:6
setHeadstartWPConfig
▸ setHeadstartWPConfig(config
): void
Parameters
Name | Type |
---|---|
config | HeadlessConfig |
Returns
void
Defined in
packages/core/src/utils/config.ts:6
stripTags
▸ stripTags(html
): any
Utility functions to strip any tags
Parameters
Name | Type | Description |
---|---|---|
html | any | The html string |
Returns
any
Defined in
packages/core/src/dom/stripTags.ts:8
warn
▸ warn(message
): void
Logs a warning in the console in dev mode
Example
warn("You should do/change something.")
Parameters
Name | Type | Description |
---|---|---|
message | string | The message that describes the warning. |
Returns
void
Defined in
packages/core/src/utils/errors.ts:45
Utility Functions
parsePath
▸ parsePath(matchers
, path
): Record
<string
, string
>
Parses a path and extracts the parameters from it
Parameters
Name | Type | Description |
---|---|---|
matchers | Matcher [] | An array of Matchers |
path | string | The path |
Returns
Record
<string
, string
>
the extracted parameters