@alanizcreative/formation-static 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -0
- package/cjs/actions/actions.d.ts +8 -0
- package/cjs/actions/actions.js +1 -0
- package/cjs/actions/actionsTypes.d.ts +10 -0
- package/cjs/actions/actionsTypes.js +1 -0
- package/cjs/components/Navigation/Navigation.d.ts +14 -0
- package/cjs/components/Navigation/Navigation.js +1 -0
- package/cjs/components/Navigation/NavigationTypes.d.ts +88 -0
- package/cjs/components/Navigation/NavigationTypes.js +1 -0
- package/cjs/components/Pagination/Pagination.d.ts +3 -0
- package/cjs/components/Pagination/Pagination.js +1 -0
- package/cjs/components/Pagination/PaginationTypes.d.ts +54 -0
- package/cjs/components/Pagination/PaginationTypes.js +1 -0
- package/cjs/config/config.d.ts +5 -0
- package/cjs/config/config.js +1 -0
- package/cjs/config/configTypes.d.ts +66 -0
- package/cjs/config/configTypes.js +1 -0
- package/cjs/contentful/contentfulData.d.ts +5 -0
- package/cjs/contentful/contentfulData.js +1 -0
- package/cjs/contentful/contentfulDataNormal.d.ts +4 -0
- package/cjs/contentful/contentfulDataNormal.js +1 -0
- package/cjs/contentful/contentfulDataTypes.d.ts +78 -0
- package/cjs/contentful/contentfulDataTypes.js +1 -0
- package/cjs/filters/filters.d.ts +8 -0
- package/cjs/filters/filters.js +1 -0
- package/cjs/filters/filtersTypes.d.ts +60 -0
- package/cjs/filters/filtersTypes.js +1 -0
- package/cjs/global/globalTypes.d.ts +34 -0
- package/cjs/global/globalTypes.js +1 -0
- package/cjs/layouts/Column/Column.d.ts +3 -0
- package/cjs/layouts/Column/Column.js +1 -0
- package/cjs/layouts/Column/ColumnTypes.d.ts +16 -0
- package/cjs/layouts/Column/ColumnTypes.js +1 -0
- package/cjs/layouts/Container/Container.d.ts +3 -0
- package/cjs/layouts/Container/Container.js +1 -0
- package/cjs/layouts/Container/ContainerTypes.d.ts +15 -0
- package/cjs/layouts/Container/ContainerTypes.js +1 -0
- package/cjs/local/localData.d.ts +5 -0
- package/cjs/local/localData.js +1 -0
- package/cjs/local/localDataNormal.d.ts +3 -0
- package/cjs/local/localDataNormal.js +1 -0
- package/cjs/local/localDataTypes.d.ts +14 -0
- package/cjs/local/localDataTypes.js +1 -0
- package/cjs/objects/Form/Form.d.ts +3 -0
- package/cjs/objects/Form/Form.js +1 -0
- package/cjs/objects/Form/FormField.d.ts +3 -0
- package/cjs/objects/Form/FormField.js +1 -0
- package/cjs/objects/Form/FormOption.d.ts +3 -0
- package/cjs/objects/Form/FormOption.js +1 -0
- package/cjs/objects/Form/FormTypes.d.ts +76 -0
- package/cjs/objects/Form/FormTypes.js +1 -0
- package/cjs/package.json +1 -0
- package/cjs/redirects/redirects.d.ts +4 -0
- package/cjs/redirects/redirects.js +1 -0
- package/cjs/redirects/redirectsFile.d.ts +2 -0
- package/cjs/redirects/redirectsFile.js +1 -0
- package/cjs/render/render.d.ts +11 -0
- package/cjs/render/render.js +1 -0
- package/cjs/render/renderInline.d.ts +4 -0
- package/cjs/render/renderInline.js +1 -0
- package/cjs/render/renderTypes.d.ts +197 -0
- package/cjs/render/renderTypes.js +1 -0
- package/cjs/scripts/scripts.d.ts +8 -0
- package/cjs/scripts/scripts.js +1 -0
- package/cjs/scripts/scriptsTypes.d.ts +15 -0
- package/cjs/scripts/scriptsTypes.js +1 -0
- package/cjs/serverless/Contact/Contact.d.ts +3 -0
- package/cjs/serverless/Contact/Contact.js +1 -0
- package/cjs/serverless/Contact/ContactTypes.d.ts +13 -0
- package/cjs/serverless/Contact/ContactTypes.js +1 -0
- package/cjs/serverless/serverless.d.ts +12 -0
- package/cjs/serverless/serverless.js +1 -0
- package/cjs/serverless/serverlessTypes.d.ts +41 -0
- package/cjs/serverless/serverlessTypes.js +1 -0
- package/cjs/shortcodes/shortcodes.d.ts +10 -0
- package/cjs/shortcodes/shortcodes.js +1 -0
- package/cjs/shortcodes/shortcodesTypes.d.ts +20 -0
- package/cjs/shortcodes/shortcodesTypes.js +1 -0
- package/cjs/store/store.d.ts +9 -0
- package/cjs/store/store.js +1 -0
- package/cjs/store/storeFiles.d.ts +2 -0
- package/cjs/store/storeFiles.js +1 -0
- package/cjs/store/storeTypes.d.ts +28 -0
- package/cjs/store/storeTypes.js +1 -0
- package/cjs/text/RichText/RichText.d.ts +4 -0
- package/cjs/text/RichText/RichText.js +1 -0
- package/cjs/text/RichText/RichTextTypes.d.ts +54 -0
- package/cjs/text/RichText/RichTextTypes.js +1 -0
- package/cjs/utils/ResponseError/ResponseError.d.ts +5 -0
- package/cjs/utils/ResponseError/ResponseError.js +1 -0
- package/cjs/utils/archive/archive.d.ts +10 -0
- package/cjs/utils/archive/archive.js +1 -0
- package/cjs/utils/archive/archiveTypes.d.ts +29 -0
- package/cjs/utils/archive/archiveTypes.js +1 -0
- package/cjs/utils/array/array.d.ts +3 -0
- package/cjs/utils/array/array.js +1 -0
- package/cjs/utils/boolean/boolean.d.ts +2 -0
- package/cjs/utils/boolean/boolean.js +1 -0
- package/cjs/utils/contentType/contentType.d.ts +2 -0
- package/cjs/utils/contentType/contentType.js +1 -0
- package/cjs/utils/dataSource/dataSource.d.ts +3 -0
- package/cjs/utils/dataSource/dataSource.js +1 -0
- package/cjs/utils/dataSource/dataSourceTypes.d.ts +9 -0
- package/cjs/utils/dataSource/dataSourceTypes.js +1 -0
- package/cjs/utils/escape/escape.d.ts +2 -0
- package/cjs/utils/escape/escape.js +1 -0
- package/cjs/utils/excerpt/excerpt.d.ts +3 -0
- package/cjs/utils/excerpt/excerpt.js +1 -0
- package/cjs/utils/excerpt/excerptTypes.d.ts +14 -0
- package/cjs/utils/excerpt/excerptTypes.js +1 -0
- package/cjs/utils/file/file.d.ts +3 -0
- package/cjs/utils/file/file.js +1 -0
- package/cjs/utils/file/filePath.d.ts +2 -0
- package/cjs/utils/file/filePath.js +1 -0
- package/cjs/utils/function/function.d.ts +3 -0
- package/cjs/utils/function/function.js +1 -0
- package/cjs/utils/heading/heading.d.ts +2 -0
- package/cjs/utils/heading/heading.js +1 -0
- package/cjs/utils/image/image.d.ts +5 -0
- package/cjs/utils/image/image.js +1 -0
- package/cjs/utils/image/imageLocal.d.ts +3 -0
- package/cjs/utils/image/imageLocal.js +1 -0
- package/cjs/utils/image/imageRemote.d.ts +3 -0
- package/cjs/utils/image/imageRemote.js +1 -0
- package/cjs/utils/image/imageTypes.d.ts +69 -0
- package/cjs/utils/image/imageTypes.js +1 -0
- package/cjs/utils/json/json.d.ts +3 -0
- package/cjs/utils/json/json.js +1 -0
- package/cjs/utils/link/link.d.ts +6 -0
- package/cjs/utils/link/link.js +1 -0
- package/cjs/utils/link/linkShare.d.ts +3 -0
- package/cjs/utils/link/linkShare.js +1 -0
- package/cjs/utils/link/linkTypes.d.ts +28 -0
- package/cjs/utils/link/linkTypes.js +1 -0
- package/cjs/utils/map/map.d.ts +2 -0
- package/cjs/utils/map/map.js +1 -0
- package/cjs/utils/minify/minify.d.ts +2 -0
- package/cjs/utils/minify/minify.js +1 -0
- package/cjs/utils/number/number.d.ts +2 -0
- package/cjs/utils/number/number.js +1 -0
- package/cjs/utils/object/object.d.ts +4 -0
- package/cjs/utils/object/object.js +1 -0
- package/cjs/utils/object/objectUtils.d.ts +2 -0
- package/cjs/utils/object/objectUtils.js +1 -0
- package/cjs/utils/path/path.d.ts +3 -0
- package/cjs/utils/path/path.js +1 -0
- package/cjs/utils/print/print.d.ts +2 -0
- package/cjs/utils/print/print.js +1 -0
- package/cjs/utils/set/set.d.ts +3 -0
- package/cjs/utils/set/set.js +1 -0
- package/cjs/utils/string/string.d.ts +3 -0
- package/cjs/utils/string/string.js +1 -0
- package/cjs/utils/tag/tag.d.ts +4 -0
- package/cjs/utils/tag/tag.js +1 -0
- package/cjs/utils/tag/tagTypes.d.ts +6 -0
- package/cjs/utils/tag/tagTypes.js +1 -0
- package/cjs/utils/year/year.d.ts +2 -0
- package/cjs/utils/year/year.js +1 -0
- package/cjs/wordpress/wordpressData.d.ts +6 -0
- package/cjs/wordpress/wordpressData.js +1 -0
- package/cjs/wordpress/wordpressDataNormal.d.ts +9 -0
- package/cjs/wordpress/wordpressDataNormal.js +1 -0
- package/cjs/wordpress/wordpressDataTypes.d.ts +208 -0
- package/cjs/wordpress/wordpressDataTypes.js +1 -0
- package/lib/actions/actions.d.ts +8 -0
- package/lib/actions/actions.js +1 -0
- package/lib/actions/actionsTypes.d.ts +10 -0
- package/lib/actions/actionsTypes.js +1 -0
- package/lib/components/Navigation/Navigation.d.ts +14 -0
- package/lib/components/Navigation/Navigation.js +1 -0
- package/lib/components/Navigation/NavigationTypes.d.ts +88 -0
- package/lib/components/Navigation/NavigationTypes.js +1 -0
- package/lib/components/Pagination/Pagination.d.ts +3 -0
- package/lib/components/Pagination/Pagination.js +1 -0
- package/lib/components/Pagination/PaginationTypes.d.ts +54 -0
- package/lib/components/Pagination/PaginationTypes.js +1 -0
- package/lib/config/config.d.ts +5 -0
- package/lib/config/config.js +1 -0
- package/lib/config/configTypes.d.ts +66 -0
- package/lib/config/configTypes.js +1 -0
- package/lib/contentful/contentfulData.d.ts +5 -0
- package/lib/contentful/contentfulData.js +1 -0
- package/lib/contentful/contentfulDataNormal.d.ts +4 -0
- package/lib/contentful/contentfulDataNormal.js +1 -0
- package/lib/contentful/contentfulDataTypes.d.ts +78 -0
- package/lib/contentful/contentfulDataTypes.js +1 -0
- package/lib/filters/filters.d.ts +8 -0
- package/lib/filters/filters.js +1 -0
- package/lib/filters/filtersTypes.d.ts +60 -0
- package/lib/filters/filtersTypes.js +1 -0
- package/lib/global/globalTypes.d.ts +34 -0
- package/lib/global/globalTypes.js +1 -0
- package/lib/layouts/Column/Column.d.ts +3 -0
- package/lib/layouts/Column/Column.js +1 -0
- package/lib/layouts/Column/ColumnTypes.d.ts +16 -0
- package/lib/layouts/Column/ColumnTypes.js +1 -0
- package/lib/layouts/Container/Container.d.ts +3 -0
- package/lib/layouts/Container/Container.js +1 -0
- package/lib/layouts/Container/ContainerTypes.d.ts +15 -0
- package/lib/layouts/Container/ContainerTypes.js +1 -0
- package/lib/local/localData.d.ts +5 -0
- package/lib/local/localData.js +1 -0
- package/lib/local/localDataNormal.d.ts +3 -0
- package/lib/local/localDataNormal.js +1 -0
- package/lib/local/localDataTypes.d.ts +14 -0
- package/lib/local/localDataTypes.js +1 -0
- package/lib/objects/Form/Form.d.ts +3 -0
- package/lib/objects/Form/Form.js +1 -0
- package/lib/objects/Form/FormField.d.ts +3 -0
- package/lib/objects/Form/FormField.js +1 -0
- package/lib/objects/Form/FormOption.d.ts +3 -0
- package/lib/objects/Form/FormOption.js +1 -0
- package/lib/objects/Form/FormTypes.d.ts +76 -0
- package/lib/objects/Form/FormTypes.js +1 -0
- package/lib/package.json +1 -0
- package/lib/redirects/redirects.d.ts +4 -0
- package/lib/redirects/redirects.js +1 -0
- package/lib/redirects/redirectsFile.d.ts +2 -0
- package/lib/redirects/redirectsFile.js +1 -0
- package/lib/render/render.d.ts +11 -0
- package/lib/render/render.js +1 -0
- package/lib/render/renderInline.d.ts +4 -0
- package/lib/render/renderInline.js +1 -0
- package/lib/render/renderTypes.d.ts +197 -0
- package/lib/render/renderTypes.js +1 -0
- package/lib/scripts/scripts.d.ts +8 -0
- package/lib/scripts/scripts.js +1 -0
- package/lib/scripts/scriptsTypes.d.ts +15 -0
- package/lib/scripts/scriptsTypes.js +1 -0
- package/lib/serverless/Contact/Contact.d.ts +3 -0
- package/lib/serverless/Contact/Contact.js +1 -0
- package/lib/serverless/Contact/ContactTypes.d.ts +13 -0
- package/lib/serverless/Contact/ContactTypes.js +1 -0
- package/lib/serverless/serverless.d.ts +12 -0
- package/lib/serverless/serverless.js +1 -0
- package/lib/serverless/serverlessTypes.d.ts +41 -0
- package/lib/serverless/serverlessTypes.js +1 -0
- package/lib/shortcodes/shortcodes.d.ts +10 -0
- package/lib/shortcodes/shortcodes.js +1 -0
- package/lib/shortcodes/shortcodesTypes.d.ts +20 -0
- package/lib/shortcodes/shortcodesTypes.js +1 -0
- package/lib/store/store.d.ts +9 -0
- package/lib/store/store.js +1 -0
- package/lib/store/storeFiles.d.ts +2 -0
- package/lib/store/storeFiles.js +1 -0
- package/lib/store/storeTypes.d.ts +28 -0
- package/lib/store/storeTypes.js +1 -0
- package/lib/text/RichText/RichText.d.ts +4 -0
- package/lib/text/RichText/RichText.js +1 -0
- package/lib/text/RichText/RichTextTypes.d.ts +54 -0
- package/lib/text/RichText/RichTextTypes.js +1 -0
- package/lib/utils/ResponseError/ResponseError.d.ts +5 -0
- package/lib/utils/ResponseError/ResponseError.js +1 -0
- package/lib/utils/archive/archive.d.ts +10 -0
- package/lib/utils/archive/archive.js +1 -0
- package/lib/utils/archive/archiveTypes.d.ts +29 -0
- package/lib/utils/archive/archiveTypes.js +1 -0
- package/lib/utils/array/array.d.ts +3 -0
- package/lib/utils/array/array.js +1 -0
- package/lib/utils/boolean/boolean.d.ts +2 -0
- package/lib/utils/boolean/boolean.js +1 -0
- package/lib/utils/contentType/contentType.d.ts +2 -0
- package/lib/utils/contentType/contentType.js +1 -0
- package/lib/utils/dataSource/dataSource.d.ts +3 -0
- package/lib/utils/dataSource/dataSource.js +1 -0
- package/lib/utils/dataSource/dataSourceTypes.d.ts +9 -0
- package/lib/utils/dataSource/dataSourceTypes.js +1 -0
- package/lib/utils/escape/escape.d.ts +2 -0
- package/lib/utils/escape/escape.js +1 -0
- package/lib/utils/excerpt/excerpt.d.ts +3 -0
- package/lib/utils/excerpt/excerpt.js +1 -0
- package/lib/utils/excerpt/excerptTypes.d.ts +14 -0
- package/lib/utils/excerpt/excerptTypes.js +1 -0
- package/lib/utils/file/file.d.ts +3 -0
- package/lib/utils/file/file.js +1 -0
- package/lib/utils/file/filePath.d.ts +2 -0
- package/lib/utils/file/filePath.js +1 -0
- package/lib/utils/function/function.d.ts +3 -0
- package/lib/utils/function/function.js +1 -0
- package/lib/utils/heading/heading.d.ts +2 -0
- package/lib/utils/heading/heading.js +1 -0
- package/lib/utils/image/image.d.ts +5 -0
- package/lib/utils/image/image.js +1 -0
- package/lib/utils/image/imageLocal.d.ts +3 -0
- package/lib/utils/image/imageLocal.js +1 -0
- package/lib/utils/image/imageRemote.d.ts +3 -0
- package/lib/utils/image/imageRemote.js +1 -0
- package/lib/utils/image/imageTypes.d.ts +69 -0
- package/lib/utils/image/imageTypes.js +1 -0
- package/lib/utils/json/json.d.ts +3 -0
- package/lib/utils/json/json.js +1 -0
- package/lib/utils/link/link.d.ts +6 -0
- package/lib/utils/link/link.js +1 -0
- package/lib/utils/link/linkShare.d.ts +3 -0
- package/lib/utils/link/linkShare.js +1 -0
- package/lib/utils/link/linkTypes.d.ts +28 -0
- package/lib/utils/link/linkTypes.js +1 -0
- package/lib/utils/map/map.d.ts +2 -0
- package/lib/utils/map/map.js +1 -0
- package/lib/utils/minify/minify.d.ts +2 -0
- package/lib/utils/minify/minify.js +1 -0
- package/lib/utils/number/number.d.ts +2 -0
- package/lib/utils/number/number.js +1 -0
- package/lib/utils/object/object.d.ts +4 -0
- package/lib/utils/object/object.js +1 -0
- package/lib/utils/object/objectUtils.d.ts +2 -0
- package/lib/utils/object/objectUtils.js +1 -0
- package/lib/utils/path/path.d.ts +3 -0
- package/lib/utils/path/path.js +1 -0
- package/lib/utils/print/print.d.ts +2 -0
- package/lib/utils/print/print.js +1 -0
- package/lib/utils/set/set.d.ts +3 -0
- package/lib/utils/set/set.js +1 -0
- package/lib/utils/string/string.d.ts +3 -0
- package/lib/utils/string/string.js +1 -0
- package/lib/utils/tag/tag.d.ts +4 -0
- package/lib/utils/tag/tag.js +1 -0
- package/lib/utils/tag/tagTypes.d.ts +6 -0
- package/lib/utils/tag/tagTypes.js +1 -0
- package/lib/utils/year/year.d.ts +2 -0
- package/lib/utils/year/year.js +1 -0
- package/lib/wordpress/wordpressData.d.ts +6 -0
- package/lib/wordpress/wordpressData.js +1 -0
- package/lib/wordpress/wordpressDataNormal.d.ts +9 -0
- package/lib/wordpress/wordpressDataNormal.js +1 -0
- package/lib/wordpress/wordpressDataTypes.d.ts +208 -0
- package/lib/wordpress/wordpressDataTypes.js +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RichTextProps, RichTextContent } from './RichTextTypes.js';
|
|
2
|
+
declare const getPlainText: (args: RichTextContent | RichTextContent[] | string | undefined, _output?: string) => string;
|
|
3
|
+
declare const RichText: (props: RichTextProps) => string;
|
|
4
|
+
export { RichText, getPlainText };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getLink}from"../../utils/link/link.js";import{getExcerpt}from"../../utils/excerpt/excerpt.js";import{applyFilters}from"../../filters/filters.js";import{isString,isStringStrict}from"../../utils/string/string.js";import{isArray,isArrayStrict}from"../../utils/array/array.js";import{isObjectStrict}from"../../utils/object/object.js";import{isHeading}from"../../utils/heading/heading.js";const containsShortcode=(tag,content)=>"p"===tag&&"["===content.charAt(0)&&"]"===content.charAt(content.length-1),addDataAttr=(dataAttr=!0,tag="")=>isArrayStrict(dataAttr)?dataAttr.includes(tag):dataAttr,getContent=args=>{const{content:content=[],props:props,dataAttr:dataAttr=!1}=args;let{_output:_output=""}=args;for(const item of content){const newItem=applyFilters("richTextContentItem",item,props),{link:link,attr:attr,internalLink:internalLink,content:itemContent}=newItem;let{tag:tag=""}=newItem,newContent=itemContent;const isSingleTag="br"===tag||"hr"===tag;isArrayStrict(itemContent)&&(newContent=getContent({content:itemContent,props:props,dataAttr:dataAttr}));const attrs=[];if(addDataAttr(dataAttr,tag)&&attrs.push(`data-rich="${tag}"`),isStringStrict(attr)&&attrs.push(attr),isObjectStrict(attr)&&Object.entries(attr).forEach(([key,value])=>{attrs.push(`${key}="${value}"`)}),"a"===tag){let anchorLink=link;internalLink&&(anchorLink=getLink(internalLink)),isStringStrict(anchorLink)&&attrs.push(`href="${anchorLink}"`)}let outputStr="";if(isString(newContent)){outputStr+=applyFilters("richTextContent",newContent,{args:newItem,props:props})}containsShortcode(tag,outputStr)&&(tag="");let opening="",closing="",inner="";isStringStrict(tag)&&outputStr.trim()&&!isSingleTag&&(opening=`<${tag}${attrs.length?` ${attrs.join(" ")}`:""}>`,closing=`</${tag}>`,inner=outputStr,outputStr=`${opening}${outputStr}${closing}`),isSingleTag&&(outputStr=`<${tag}>`);_output+=applyFilters("richTextContentOutput",outputStr,{args:newItem,props:props,element:{opening:opening,closing:closing,content:inner}})}return _output},getPlainText=(args,_output="")=>{if(isString(args))return args;const content=isObjectStrict(args)?args.content:args;if(!isArrayStrict(content))return _output;for(const item of content){const{content:itemContent}=isObjectStrict(item)?item:{};isString(itemContent)&&(_output+=itemContent),isArrayStrict(itemContent)&&(_output=getPlainText({content:itemContent},_output))}return _output},RichText=props=>{if(!isObjectStrict(props))return"";props=applyFilters("richTextProps",props);const{args:args}=props;if(!isObjectStrict(args))return"";const{content:content=[],classes:classes,link:link,internalLink:internalLink,textStyle:textStyle,headingStyle:headingStyle,align:align,style:style,attr:attr,dataAttr:dataAttr=!0}=args;let{tag:tag=""}=args;if("hr"===tag||"br"===tag)return`<${tag}>`;const isSectionHeading=isHeading(tag),classesArr=[];isStringStrict(classes)&&classesArr.push(classes),isStringStrict(textStyle)&&classesArr.push(textStyle),isStringStrict(headingStyle)&&isSectionHeading&&classesArr.push(headingStyle),isStringStrict(align)&&classesArr.push(align);const filterProps={...props};filterProps.args.content=void 0;let headingObj,output="",headingStr="";isStringStrict(content)&&(output=content,headingStr=content),isArrayStrict(content)&&(headingObj=content,output=getContent({content:content,props:filterProps,dataAttr:dataAttr}));const attrs=[];if(addDataAttr(dataAttr,tag)&&attrs.push(`data-rich="${tag}"`),isSectionHeading){const headingContents=getExcerpt({limit:10,limitExcerpt:!0,excerpt:headingStr,content:headingObj}),id=headingContents.trim().replace(/…/g,"").replace(/[^\w\s]|_/g,"").replace(/\s+/g,"-").toLowerCase();headingContents&&id&&(attrs.push(`id="${id}"`),isArray(props.headings)&&props.headings.push({id:id,title:headingContents,tag:tag}))}if("a"===tag){let anchorLink=link;const inLink=getLink(internalLink);isStringStrict(inLink)&&(anchorLink=inLink),isStringStrict(anchorLink)&&attrs.push(`href="${anchorLink}"`)}classesArr.length&&attrs.push(`class="${classesArr.join(" ")}"`),isStringStrict(style)&&attrs.push(`style="${style}"`),isStringStrict(attr)&&attrs.push(attr),isObjectStrict(attr)&&Object.entries(attr).forEach(([key,value])=>{attrs.push(`${key}="${value}"`)}),containsShortcode(tag,output)&&(tag="");let opening="",closing="",inner="";isStringStrict(tag)&&output.trim()&&(opening=`<${tag}${attrs.length?` ${attrs.join(" ")}`:""}>`,closing=`</${tag}>`,inner=output,output=`${opening}${output}${closing}`);return applyFilters("richTextOutput",output,{props:filterProps,element:{opening:opening,closing:closing,content:inner}})};export{RichText,getPlainText};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { InternalLink, Generic, GenericStrings } from '../../global/globalTypes.js';
|
|
2
|
+
import type { RenderRichText, RenderFunctionArgs, RenderItem } from '../../render/renderTypes.js';
|
|
3
|
+
export interface RichTextHeading {
|
|
4
|
+
title: string;
|
|
5
|
+
id: string;
|
|
6
|
+
tag: string;
|
|
7
|
+
}
|
|
8
|
+
export interface RichTextElement {
|
|
9
|
+
opening: string;
|
|
10
|
+
content: string;
|
|
11
|
+
closing: string;
|
|
12
|
+
}
|
|
13
|
+
export interface RichTextArgs extends Generic {
|
|
14
|
+
tag?: string;
|
|
15
|
+
content?: RenderRichText[] | string;
|
|
16
|
+
classes?: string;
|
|
17
|
+
textStyle?: string;
|
|
18
|
+
headingStyle?: string;
|
|
19
|
+
caption?: RenderRichText[] | string;
|
|
20
|
+
align?: string;
|
|
21
|
+
link?: string;
|
|
22
|
+
internalLink?: InternalLink;
|
|
23
|
+
style?: string;
|
|
24
|
+
attr?: string | GenericStrings;
|
|
25
|
+
dataAttr?: boolean | string[];
|
|
26
|
+
}
|
|
27
|
+
export interface RichTextContent extends Generic {
|
|
28
|
+
content?: RenderRichText[] | string;
|
|
29
|
+
}
|
|
30
|
+
export interface RichTextProps<A = RichTextArgs, R = RenderItem> extends RenderFunctionArgs<A, R> {
|
|
31
|
+
args: RichTextArgs & A;
|
|
32
|
+
}
|
|
33
|
+
export interface RichTextContentProps {
|
|
34
|
+
content: RenderRichText[];
|
|
35
|
+
props: RichTextProps;
|
|
36
|
+
dataAttr: boolean | string[];
|
|
37
|
+
_output?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface RichTextContentFilterArgs {
|
|
40
|
+
args: RenderRichText;
|
|
41
|
+
props: RichTextProps;
|
|
42
|
+
}
|
|
43
|
+
export interface RichTextContentOutputFilterArgs extends RichTextContentFilterArgs {
|
|
44
|
+
element: RichTextElement;
|
|
45
|
+
}
|
|
46
|
+
export interface RichTextOutputFilterArgs {
|
|
47
|
+
props: RichTextProps;
|
|
48
|
+
element: RichTextElement;
|
|
49
|
+
}
|
|
50
|
+
export type RichTextPropsFilter = (props: RichTextProps) => RichTextProps;
|
|
51
|
+
export type RichTextOutputFilter = (output: string, args: RichTextContentOutputFilterArgs) => string;
|
|
52
|
+
export type RichTextContentItemFilter = (item: RenderRichText, args: RichTextProps) => RenderRichText;
|
|
53
|
+
export type RichTextContentFilter = (content: string, args: RichTextContentFilterArgs) => string;
|
|
54
|
+
export type RichTextContentOutputFilter = (content: string, args: RichTextContentOutputFilterArgs) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class ResponseError extends Error{response;constructor(message,resp){super(message),this.message=message,this.response=resp}}export{ResponseError};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ArchiveInfo, ArchiveTaxonomy, ArchiveLink, ArchiveLabels, ArchiveMeta } from './archiveTypes.js';
|
|
2
|
+
import type { RenderItem } from '../../render/renderTypes.js';
|
|
3
|
+
declare const isTerm: (contentType: string, itemData: RenderItem) => boolean;
|
|
4
|
+
declare const isArchive: (contentType: string, itemData: RenderItem) => boolean;
|
|
5
|
+
declare const getArchiveMeta: (contentType: string, locale?: string) => ArchiveMeta;
|
|
6
|
+
declare const getArchiveInfo: (contentType: string, locale?: string) => ArchiveInfo;
|
|
7
|
+
declare const getTaxonomyInfo: (contentType: string, itemData?: RenderItem) => ArchiveTaxonomy;
|
|
8
|
+
declare const getArchiveLink: (contentType: string, itemData?: RenderItem) => ArchiveLink;
|
|
9
|
+
declare const getArchiveLabels: (contentType: string, itemData?: RenderItem) => ArchiveLabels;
|
|
10
|
+
export { isTerm, isArchive, getArchiveMeta, getArchiveInfo, getTaxonomyInfo, getArchiveLink, getArchiveLabels };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getStoreItem}from"../../store/store.js";import{isObjectStrict}from"../object/object.js";import{isArrayStrict}from"../array/array.js";import{isStringStrict}from"../string/string.js";import{isBoolean}from"../boolean/boolean.js";import{normalizeContentType}from"../contentType/contentType.js";import{getSlug,getPermalink}from"../link/link.js";const isTerm=(contentType,itemData)=>{if(!isObjectStrict(itemData))return!1;const{contentType:type,taxonomy:taxonomy}=itemData;return!("term"!==type||!isObjectStrict(taxonomy))&&taxonomy.contentTypes.includes(contentType)},isArchive=(contentType,itemData)=>{if(!isObjectStrict(itemData))return!1;const{archive:archive}=itemData;return archive===contentType||isTerm(contentType,itemData)},getArchiveMeta=(contentType,locale)=>{const archiveMeta=getStoreItem("archiveMeta")[contentType];return isObjectStrict(archiveMeta)?isStringStrict(locale)&&isObjectStrict(archiveMeta[locale])?archiveMeta[locale]:archiveMeta:{}},getArchiveInfo=(contentType,locale)=>{const value={id:"",slug:"",title:"",contentType:""};if("page"===(contentType=normalizeContentType(contentType)))return value;const{id:id,slug:slug,title:title,contentType:type}=getArchiveMeta(contentType,locale);return value.id=isStringStrict(id)?id:"",value.slug=isStringStrict(slug)?slug:"",value.title=isStringStrict(title)?title:"",value.contentType=isStringStrict(type)?type:"",value},getTaxonomyInfo=(contentType,itemData)=>{const value={id:"",slug:"",title:"",contentTypes:[],primaryContentType:"",usePrimaryContentTypeSlug:!0,isPage:!1},taxObj="taxonomy"===contentType?itemData:itemData?.taxonomy;if(!isObjectStrict(taxObj))return value;const{id:id,slug:slug,link:link,title:title,contentTypes:contentTypes,usePrimaryContentTypeSlug:usePrimaryContentTypeSlug,isPage:isPage}=taxObj,taxonomyTypes=isArrayStrict(contentTypes)?contentTypes.map(type=>normalizeContentType(type)):[],primaryTaxonomyType=taxonomyTypes[0];return value.id=isStringStrict(id)?id:"",value.slug=isStringStrict(slug)?slug:"",value.title=isStringStrict(title)?title:"",value.contentTypes=taxonomyTypes,value.primaryContentType=isStringStrict(primaryTaxonomyType)?primaryTaxonomyType:"",value.usePrimaryContentTypeSlug=!isBoolean(usePrimaryContentTypeSlug)||usePrimaryContentTypeSlug,value.isPage=!!isBoolean(isPage)&&isPage,isStringStrict(link)&&(value.link=link),value},getArchiveLink=(contentType,itemData)=>{let slug,title="";const locale=itemData?.locale,taxonomyInfo=getTaxonomyInfo(contentType,itemData),{title:taxonomyTitle,isPage:taxonomyIsPage,contentTypes:taxonomyTypes,usePrimaryContentTypeSlug:taxonomyUseTypeSlug}=taxonomyInfo;"term"===contentType&&taxonomyIsPage&&(slug=getSlug({slug:"",contentType:contentType,itemData:itemData}),title=taxonomyTitle);const taxonomyType=taxonomyTypes[0],useArchiveType=taxonomyUseTypeSlug&&isStringStrict(taxonomyType);"taxonomy"===contentType&&useArchiveType&&(contentType=taxonomyType),"term"===contentType&&!taxonomyIsPage&&useArchiveType&&(contentType=taxonomyType);const archiveInfo=getArchiveInfo(contentType,locale),{id:archiveId,slug:archiveSlug,title:archiveTitle,contentType:archiveType}=archiveInfo;return archiveSlug&&archiveId&&(slug=getSlug({id:archiveId,slug:archiveSlug,contentType:archiveType,itemData:{locale:locale}}),title=getArchiveLabel(contentType,itemData,"plural",archiveTitle)),{title:title,link:isStringStrict(slug)?getPermalink(slug):""}},getArchiveLabel=(contentType,itemData,labelType="singular",fallback)=>{fallback=isStringStrict(fallback)?fallback:"singular"===labelType?"Post":"Posts";const label=getArchiveMeta(contentType,itemData?.locale)[labelType];return isStringStrict(label)?label:fallback},getArchiveLabels=(contentType,itemData)=>{let singular="Post",plural="Posts";const taxonomyInfo=getTaxonomyInfo(contentType,itemData),{title:taxonomyTitle,isPage:taxonomyIsPage,primaryContentType:taxonomyType,usePrimaryContentTypeSlug:taxonomyUseTypeSlug}=taxonomyInfo;if("term"===contentType&&taxonomyIsPage&&isStringStrict(taxonomyTitle))return{singular:taxonomyTitle,plural:taxonomyTitle};const useArchiveType=taxonomyUseTypeSlug&&isStringStrict(taxonomyType);return"taxonomy"===contentType&&useArchiveType&&(contentType=taxonomyType),"term"===contentType&&!taxonomyIsPage&&useArchiveType&&(contentType=taxonomyType),isStringStrict(contentType)&&(contentType=normalizeContentType(contentType),singular=getArchiveLabel(contentType,itemData),plural=getArchiveLabel(contentType,itemData,"plural")),{singular:singular,plural:plural}};export{isTerm,isArchive,getArchiveMeta,getArchiveInfo,getTaxonomyInfo,getArchiveLink,getArchiveLabels};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Taxonomy } from '../../global/globalTypes.js';
|
|
2
|
+
export interface ArchiveMeta {
|
|
3
|
+
id?: string;
|
|
4
|
+
slug?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
singular?: string;
|
|
7
|
+
plural?: string;
|
|
8
|
+
contentType?: string;
|
|
9
|
+
layout?: string;
|
|
10
|
+
order?: string;
|
|
11
|
+
display?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ArchiveInfo {
|
|
14
|
+
id: string;
|
|
15
|
+
slug: string;
|
|
16
|
+
title: string;
|
|
17
|
+
contentType: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ArchiveTaxonomy extends Omit<Required<Taxonomy>, 'link'>, Pick<Taxonomy, 'link'> {
|
|
20
|
+
primaryContentType: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ArchiveLink {
|
|
23
|
+
title: string;
|
|
24
|
+
link: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ArchiveLabels {
|
|
27
|
+
singular: string;
|
|
28
|
+
plural: string;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isArray=value=>Array.isArray(value),isArrayStrict=value=>isArray(value)&&value.length>0;export{isArray,isArrayStrict};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isBoolean=value=>"boolean"==typeof value;export{isBoolean};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isStringStrict}from"../string/string.js";import{config}from"../../config/config.js";const normalizeContentType=(contentType="")=>{if(!isStringStrict(contentType))return"";const normalType=config.normalTypes[contentType];return isStringStrict(normalType)?normalType:contentType};export{normalizeContentType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isStringStrict}from"../string/string.js";import{config}from"../../config/config.js";const dataSource={isContentful:(source=config.source)=>"contentful"===config.cms.name&&"cms"===source,isWordPress:(source=config.source)=>"wordpress"===config.cms.name&&"cms"===source,isLocal:(source=config.source)=>"local"===source,get(){const cmsName=config.cms.name;return isStringStrict(cmsName)?cmsName:config.source}};export{dataSource};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Source } from '../../global/globalTypes.js';
|
|
2
|
+
export type DataSourceCheck = (source?: Source) => boolean;
|
|
3
|
+
export type DataSourceGet = () => string;
|
|
4
|
+
export interface DataSource {
|
|
5
|
+
isContentful: DataSourceCheck;
|
|
6
|
+
isWordPress: DataSourceCheck;
|
|
7
|
+
isLocal: DataSourceCheck;
|
|
8
|
+
get: DataSourceGet;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isString}from"../string/string.js";const escape=value=>{if(!isString(value))throw new TypeError("Value is not a string");return value.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")};export{escape};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObject,isObjectStrict}from"../object/object.js";import{isStringStrict}from"../string/string.js";import{stripShortcodes}from"../../shortcodes/shortcodes.js";const getContentWords=args=>{const{content:content,prop:prop,limit:limit=25}=args;let{_words:_words=[]}=args;const max=limit+1,wordsLen=_words.length;if(isObject(content)&&wordsLen<max){const addMax=max-wordsLen;for(const[key,value]of Object.entries(content)){if(key===prop&&isStringStrict(value)){const val=stripShortcodes(value);if(isStringStrict(val)){let valArr=val.split(" ");valArr.length>addMax&&(valArr=valArr.slice(0,addMax)),_words=_words.concat(valArr)}}isObject(value)&&(_words=getContentWords({content:value,prop:prop,limit:limit,_words:_words}))}}return _words},getExcerpt=args=>{const{excerpt:excerpt,content:content,prop:prop="content",limit:limit=25,limitExcerpt:limitExcerpt=!1,more:more="…"}=isObjectStrict(args)?args:{};let output="";if(isStringStrict(excerpt)){if(output=excerpt,limitExcerpt){let excerptArr=excerpt.split(" ");excerptArr.length>limit&&(excerptArr=excerptArr.slice(0,limit),output=`${excerptArr.join(" ")}${more}`)}}else{const words=getContentWords({content:content,prop:prop,limit:limit}),wordsLen=words.length;wordsLen>0&&(wordsLen>limit&&more&&words.pop(),output=`${words.join(" ")}${wordsLen>limit?more:""}`)}return output};export{getExcerpt};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ExcerptArgs<T extends object> {
|
|
2
|
+
excerpt?: string;
|
|
3
|
+
content?: T;
|
|
4
|
+
prop?: string;
|
|
5
|
+
limit?: number;
|
|
6
|
+
limitExcerpt?: boolean;
|
|
7
|
+
more?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ExcerptContentWordArgs<T> {
|
|
10
|
+
content: T;
|
|
11
|
+
prop?: string;
|
|
12
|
+
limit?: number;
|
|
13
|
+
_words?: string[];
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isFile=value=>value instanceof File,isBlob=value=>value instanceof Blob;export{isFile,isBlob};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readdir}from"node:fs/promises";import{join}from"node:path";import{isStringStrict}from"../string/string.js";const getFilePaths=async function*(dir){if(!isStringStrict(dir))throw new Error("No directory provided");const files=await readdir(dir,{withFileTypes:!0});for(const file of files)file.isDirectory()?yield*getFilePaths(join(dir,file.name)):yield join(dir,file.name)};export{getFilePaths};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isFunction=value=>"function"==typeof value;export{isFunction};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isHeading=tag=>new Set(["h1","h2","h3","h4","h5","h6"]).has(tag);export{isHeading};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ImageArgs, ImageReturnType, ImageSizesArgs, ImageSizesReturn } from './imageTypes.js';
|
|
2
|
+
declare const getImage: <V extends boolean = false>(args: ImageArgs, returnDetails?: V) => ImageReturnType<V>;
|
|
3
|
+
declare const getImageClosestSize: (size: number, sizes?: number[]) => number;
|
|
4
|
+
declare const getImageSizes: (args: ImageSizesArgs) => ImageSizesReturn;
|
|
5
|
+
export { getImage, getImageClosestSize, getImageSizes };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{config}from"../../config/config.js";import{isString,isStringStrict}from"../string/string.js";import{isArrayStrict}from"../array/array.js";import{isNumber}from"../number/number.js";import{isObjectStrict}from"../object/object.js";import{dataSource}from"../dataSource/dataSource.js";const getImageUrl=(url,format,quality,width,height,params)=>{const urlObj=new URL(url);return Object.entries(params).forEach(([key,value])=>{let val=value;"%format"===val&&(val=format),"%quality"===val&&(val=`${quality}`),"%width"===val&&(val=`${width}`),"%height"===val&&(val=`${height}`),urlObj.searchParams.set(key,val)}),urlObj.toString()},getImage=(args,returnDetails=!1)=>{const{data:data,classes:classes,attr:attr,alt:imageAlt="inherit",width:width="auto",height:height="auto",lazy:lazy=!0,picture:picture=!1,quality:quality=75,source:source=config.source,maxWidth:maxWidth=1200,viewportWidth:viewportWidth=100,sizes:sizes,format:format="webp",params:params={fm:"%format",q:"%quality",w:"%width",h:"%height"}}=isObjectStrict(args)?args:{},fallback=returnDetails?{output:"",aspectRatio:0,naturalWidth:0,naturalHeight:0,src:"",srcFallback:"",srcset:[],sizes:""}:"";if(!isObjectStrict(data))return fallback;const{path:path="",alt:dataAlt="",width:naturalWidth=1,height:naturalHeight=1,format:naturalFormat="jpg",sizes:dataSizes}=data;let{url:url=config.image.remoteUrl}=data,alt="inherit"===imageAlt?dataAlt:imageAlt;isStringStrict(alt)||(alt="");const isLocal="local"===source,isRemote=dataSource.isContentful(source)||"remote"===source,isWordpress=dataSource.isWordPress(source);if(isLocal){if(!isStringStrict(path))return fallback;url=`${config.image.localUrl}/${path}`}const aspectRatio=naturalHeight/naturalWidth,aspectRatioReverse=naturalWidth/naturalHeight;let w=naturalWidth,h=naturalHeight;if(isNumber(width)&&(w=width,h=isString(height)?w*aspectRatio:height),isNumber(height)&&(h=height,w=isString(width)?h*aspectRatioReverse:width),w>maxWidth&&(w=Math.round(maxWidth),h=Math.round(w*aspectRatio)),isWordpress&&dataSizes&&!dataSizes[w]){const isNatural=w===naturalWidth;isNatural||(w=getImageClosestSize(w,Object.keys(dataSizes).map(s=>parseInt(s,10))),h=Math.round(w*aspectRatio)),isNatural&&(dataSizes[w]=url)}let src=url,srcFallback=url;isLocal&&(src=`${url}.${format}`,srcFallback=`${url}.${naturalFormat}`),isRemote&&(src=getImageUrl(url,format,quality,w,h,params),srcFallback=getImageUrl(url,naturalFormat,quality,w,h,params));const sizesValue=sizes||`(min-width: ${w/16}rem) ${w/16}rem, ${viewportWidth}vw`,srcsetFallback=[];let srcset=[...config.image.sizes];srcset.includes(w)||srcset.push(w),srcset=srcset.filter(s=>s<=w),srcset.sort((a,b)=>a-b);const srcsetSource=[];srcset.forEach(s=>{if(isLocal){const base=`${url}${s!==naturalWidth?`@${s}`:""}`;srcsetFallback.push(`${base}.${naturalFormat} ${s}w`),srcsetSource.push(`${base}.${format} ${s}w`)}if(isRemote){const sizeHeight=Math.round(s*aspectRatio);srcsetFallback.push(getImageUrl(url,naturalFormat,quality,s,sizeHeight,params)+` ${s}w`),srcsetSource.push(getImageUrl(url,format,quality,s,sizeHeight,params)+` ${s}w`)}if(isWordpress){const sizeUrl=dataSizes?.[s];isStringStrict(sizeUrl)&&srcsetSource.push(`${sizeUrl} ${s}w`)}});let sourceOutput="";picture&&(sourceOutput=`<source srcset="${srcsetSource.join(", ")}" sizes="${sizesValue}" type="image/${format}">`);let eagerHackOutput="";lazy||(eagerHackOutput=`\n <img\n alt=""\n role="presentation"\n aria-hidden="true"\n src="data:image/svg+xml;charset=utf-8,%3Csvg height='${h}' width='${w}' xmlns='http://www.w3.org/2000/svg' version='1.1'%3E%3C/svg%3E" style="pointerEvents: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%"\n >\n `);const output=`\n ${eagerHackOutput}\n ${sourceOutput}\n <img\n ${isStringStrict(classes)?` class="${classes}"`:""}\n alt="${alt}"\n src="${picture?srcFallback:src}"\n srcset="${picture?srcsetFallback.join(", "):srcsetSource.join(", ")}"\n sizes="${sizesValue}"\n width="${w}"\n height="${h}"\n ${isStringStrict(attr)?` ${attr}`:""}\n ${lazy?' loading="lazy" decoding="async"':' loading="eager" fetchpriority="high"'}\n >\n `;return returnDetails?{output:output,aspectRatio:aspectRatio,naturalWidth:naturalWidth,naturalHeight:naturalHeight,src:src,srcFallback:srcFallback,srcset:srcsetSource,sizes:sizesValue}:output},getImageClosestSize=(size,sizes=[])=>(sizes.length||(sizes=config.image.sizes),[...sizes].reduce((prev,curr)=>Math.abs(curr-size)<=Math.abs(prev-size)?curr:prev)),getImageSizes=args=>{const fallback={maxWidth:0,sizes:""};if(!isObjectStrict(args))return fallback;const{parents:parents,widths:widths,maxWidths:maxWidths,breakpoints:breakpoints,source:source=config.source,viewportWidth:viewportWidth=100,maxWidth:max}=args;if(!(isArrayStrict(parents)&&isObjectStrict(widths)&&isObjectStrict(maxWidths)&&isArrayStrict(breakpoints)))return fallback;let containerWidth=0;const columnWidths=[];let col=1,colSmall=1,colMedium=1,colLarge=1;parents.forEach(parent=>{if(!isObjectStrict(parent))return;const{renderType:renderType,args:args}=parent;if(isObjectStrict(args)){if("column"===renderType){const{width:width="Default",widthSmall:widthSmall="Default",widthMedium:widthMedium="Default",widthLarge:widthLarge="Default"}=args,base=isNumber(widths[width])&&widths[width]?widths[width]:1,baseSmall=isNumber(widths[widthSmall])&&widths[widthSmall]?widths[widthSmall]:base,baseMedium=isNumber(widths[widthMedium])&&widths[widthMedium]?widths[widthMedium]:baseSmall,baseLarge=isNumber(widths[widthLarge])&&widths[widthLarge]?widths[widthLarge]:baseMedium;col*=base,colSmall*=baseSmall,colMedium*=baseMedium,colLarge*=baseLarge,columnWidths[0]=col,columnWidths[1]=colSmall,columnWidths[2]=colMedium,columnWidths[3]=colLarge}if("container"===renderType){const{maxWidth:maxWidth="Default"}=args;isNumber(maxWidths[maxWidth])&&(containerWidth=maxWidths[maxWidth])}}});const columnWidthsLen=columnWidths.length,hasContainerWidth=!!containerWidth;if(!columnWidthsLen&&!hasContainerWidth)return fallback;const maxPx=isNumber(max)?max/2:0,maxRem=maxPx/16+"rem",hasMax=!!maxPx&&(!hasContainerWidth||maxPx<containerWidth),breakpointsLen=breakpoints.length,maxWidthArr=[],sizesArr=[],sizeFactor=viewportWidth/100;let lastWidth=1,lastBreakpoint=0,lastSize="",containerWidthAdded=!1,sizesArrLen=0,maxIndex=-1;for(let i=0;i<breakpointsLen;i+=1){const breakpoint=breakpoints[i],width=columnWidths[i];if(!isNumber(width))continue;const bk=0===breakpoint&&0===i?breakpoints[i+1]:breakpoint,gteContainerWidth=hasContainerWidth&&breakpoint>=containerWidth,breakpointWidth=Math.round(width*(gteContainerWidth?containerWidth:bk)),gtMaxWidth=hasMax&&breakpointWidth>maxPx,sizeWidth=gteContainerWidth?breakpointWidth/16:100*width*sizeFactor,size=gteContainerWidth?`${sizeWidth}rem`:`${sizeWidth%1==0?sizeWidth:sizeWidth.toFixed(2)}vw`;if(hasContainerWidth&&containerWidth>lastBreakpoint&&containerWidth<breakpoint){const relMaxWidth=Math.round(lastWidth*containerWidth),relSize=relMaxWidth/16+"rem";hasMax&&relMaxWidth>maxPx||(maxWidthArr.push(relMaxWidth),sizesArrLen=sizesArr.push(`(min-width: ${containerWidth/16}rem) ${relSize}`),containerWidthAdded=!0,lastSize=relSize)}gtMaxWidth||maxWidthArr.push(breakpointWidth),gtMaxWidth||lastSize===size||(sizesArrLen=sizesArr.push(breakpoint?`(min-width: ${breakpoint/16}rem) ${size}`:size)),hasMax&&maxPx>lastBreakpoint&&maxPx<breakpoint&&maxPx<breakpointWidth&&(maxIndex=sizesArrLen),lastWidth=width,lastBreakpoint=breakpoint,lastSize=size}if(!containerWidthAdded&&hasContainerWidth&&containerWidth>lastBreakpoint){const relMaxWidth=Math.round(lastWidth*containerWidth),relSize=relMaxWidth/16+"rem";hasMax&&relMaxWidth>maxPx||(maxWidthArr.push(relMaxWidth),sizesArrLen=sizesArr.push(`(min-width: ${containerWidth/16}rem) ${relSize}`),containerWidthAdded=!0)}hasMax&&maxPx>lastBreakpoint&&(maxIndex=sizesArrLen),-1!==maxIndex&&(maxWidthArr.push(maxPx),sizesArr.splice(maxIndex,0,`(min-width: ${maxRem}) ${maxRem}`));const maxWidth=2*Math.max(...maxWidthArr);if(!hasMax&&(!columnWidthsLen||1===col&&1===colSmall&&1===colMedium&&1===colLarge)){const sizeWidth=maxWidth/32+"rem";sizesArr[0]=`${viewportWidth}vw`,sizesArr[1]=`(min-width: ${sizeWidth}) ${sizeWidth}`}const sizes=sizesArr.reverse().join(", ");return"local"===source?{maxWidth:getImageClosestSize(maxWidth),sizes:sizes}:{maxWidth:maxWidth,sizes:sizes}};export{getImage,getImageClosestSize,getImageSizes};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{extname,resolve,basename,dirname}from"node:path";import{mkdir,stat}from"node:fs/promises";import sharp from"sharp";import{getFilePaths}from"../file/filePath.js";import{isStringStrict}from"../string/string.js";import{setStoreItem}from"../../store/store.js";import{config}from"../../config/config.js";const setLocalImages=async()=>{const inputDir=config.image.inputDir,outputDir=config.image.outputDir;if(!isStringStrict(inputDir)||!isStringStrict(outputDir))throw new Error("No input or output directories");await mkdir(resolve(outputDir),{recursive:!0});const images=[],meta={};for await(const path of getFilePaths(inputDir)){const baseName=basename(path),ext=extname(baseName);if(!isStringStrict(ext))continue;const[base]=baseName.split(ext);if(!isStringStrict(base?.trim()))continue;let[,folders]=dirname(path).split(`${inputDir}/`);isStringStrict(folders)&&folders!==baseName?await mkdir(resolve(outputDir,folders),{recursive:!0}):folders="";const instance=sharp(path),metadata=await sharp(path).metadata(),stats=await stat(path),{width:width=0,height:height=0,format:fileFormat="jpeg"}=metadata,id=`${folders?`${folders}/`:""}${base}`,format=ext.replace(".","");meta[id]={path:id,name:baseName,type:`image/${fileFormat}`,format:format,size:stats.size,width:width,height:height};let sizes=[...config.image.sizes];sizes.includes(width)||sizes.push(width),sizes=sizes.filter(s=>s<=width),sizes.forEach(size=>{images.push({size:size,format:format,path:resolve(path),newPath:resolve(outputDir,folders,`${base}${size!==width?`@${size}`:""}`),instance:instance})})}if(!images.length)throw new Error("No local images to transform");return setStoreItem("imageMeta",meta),await Promise.all(images.map(async image=>{const{size:size,instance:instance,newPath:newPath,format:format}=image;return await instance.clone().resize(size).toFile(`${newPath}.${format}`),await instance.clone().resize(size).webp({quality:config.image.quality}).toFile(`${newPath}.webp`)}))};export{setLocalImages};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{mkdir,writeFile}from"node:fs/promises";import{resolve}from"node:path";import{config}from"../../config/config.js";import{isStringStrict}from"../string/string.js";import{isArrayStrict}from"../array/array.js";const getRemoteImages=async images=>{const inputDir=config.image.inputDir;if(!isStringStrict(inputDir))throw new Error("No input directory");if(!isArrayStrict(images))throw new Error("No images array");return await Promise.all(images.map(async image=>{const{path:path,url:url,format:format="jpg"}=image;if(!isStringStrict(path)||!isStringStrict(url)||!isStringStrict(format))throw new Error("No path, URL or format");const resp=await fetch(url);if(!resp.ok)throw new Error("Failed to fetch image");const buffer=await resp.arrayBuffer(),fullPath=`${inputDir}/${path}.${format}`,folders=fullPath.split("/");return folders.pop(),await mkdir(resolve(folders.join("/")),{recursive:!0}),await writeFile(resolve(fullPath),Buffer.from(buffer)),fullPath}))};export{getRemoteImages};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Source, GenericNumbers, ParentArgs } from '../../global/globalTypes.js';
|
|
2
|
+
import type { RenderFile } from '../../render/renderTypes.js';
|
|
3
|
+
import type { ColumnProps } from '../../layouts/Column/ColumnTypes.js';
|
|
4
|
+
import type { ContainerProps } from '../../layouts/Container/ContainerTypes.js';
|
|
5
|
+
import type sharp from 'sharp';
|
|
6
|
+
export interface ImageArgs {
|
|
7
|
+
data?: RenderFile;
|
|
8
|
+
classes?: string;
|
|
9
|
+
attr?: string;
|
|
10
|
+
alt?: string;
|
|
11
|
+
width?: string | number;
|
|
12
|
+
height?: string | number;
|
|
13
|
+
lazy?: boolean;
|
|
14
|
+
picture?: boolean;
|
|
15
|
+
quality?: number;
|
|
16
|
+
source?: Source | 'remote';
|
|
17
|
+
maxWidth?: number;
|
|
18
|
+
viewportWidth?: number;
|
|
19
|
+
sizes?: string;
|
|
20
|
+
format?: string;
|
|
21
|
+
params?: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
export interface ImageReturn {
|
|
24
|
+
output: string;
|
|
25
|
+
src: string;
|
|
26
|
+
srcFallback: string;
|
|
27
|
+
srcset: string[];
|
|
28
|
+
sizes: string;
|
|
29
|
+
aspectRatio: number;
|
|
30
|
+
naturalWidth: number;
|
|
31
|
+
naturalHeight: number;
|
|
32
|
+
}
|
|
33
|
+
export type ImageReturnType<V extends false | true> = V extends true ? ImageReturn : string;
|
|
34
|
+
export type ImageSizesParents = ParentArgs & ColumnProps & ContainerProps;
|
|
35
|
+
export type ImageSizesParentsArgs = ParentArgs & ColumnProps<string, string | number> & ContainerProps<string, string | number>;
|
|
36
|
+
export interface ImageSizesArgs<T = ImageSizesParents> {
|
|
37
|
+
parents: T[];
|
|
38
|
+
widths: GenericNumbers;
|
|
39
|
+
maxWidths: GenericNumbers;
|
|
40
|
+
breakpoints: number[];
|
|
41
|
+
source?: Source;
|
|
42
|
+
viewportWidth?: number;
|
|
43
|
+
maxWidth?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ImageSizesReturn {
|
|
46
|
+
maxWidth: number;
|
|
47
|
+
sizes: string;
|
|
48
|
+
}
|
|
49
|
+
export interface ImageLocal {
|
|
50
|
+
instance: sharp.Sharp;
|
|
51
|
+
size: number;
|
|
52
|
+
format: string;
|
|
53
|
+
path: string;
|
|
54
|
+
newPath: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ImageRemote {
|
|
57
|
+
path: string;
|
|
58
|
+
url: string;
|
|
59
|
+
format?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ImageProps {
|
|
62
|
+
path: string;
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
format: string;
|
|
66
|
+
width: number;
|
|
67
|
+
height: number;
|
|
68
|
+
size: number;
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObject}from"../object/object.js";import{getPath}from"../path/path.js";import{applyFilters}from"../../filters/filters.js";const getJson=value=>{try{const val=JSON.parse(value);if(isObject(val))return val;throw new Error("Parsed value is not an object")}catch{return}},getJsonFile=async(path,store=!1)=>{let res,newPath=path;try{newPath=store?getPath(path,"store"):path;const{default:obj}=await import(newPath);if(!isObject(obj))throw new Error("No object in json file");res=obj}catch{res=void 0}return store?await applyFilters("storeData",res,newPath,!0):res};export{getJson,getJsonFile};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LinkSlugArgs, LinkSlugReturnType } from './linkTypes.js';
|
|
2
|
+
import type { InternalLink } from '../../global/globalTypes.js';
|
|
3
|
+
declare const getSlug: <T extends boolean = false>(args: LinkSlugArgs, returnParents?: T) => LinkSlugReturnType<T>;
|
|
4
|
+
declare const getPermalink: (slug?: string, trailingSlash?: boolean) => string;
|
|
5
|
+
declare const getLink: (internalLink?: InternalLink, externalLink?: string) => string;
|
|
6
|
+
export { getSlug, getLink, getPermalink };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObjectStrict}from"../object/object.js";import{isString,isStringStrict}from"../string/string.js";import{applyFilters}from"../../filters/filters.js";import{getArchiveInfo,getTaxonomyInfo}from"../archive/archive.js";import{getStoreItem}from"../../store/store.js";import{config}from"../../config/config.js";const getParentSlug=(id,contentType,parents,taxonomy,locale)=>{const storeParents=getStoreItem("parents"),parent=storeParents[contentType]?.[id];if(parent){const[parentId,parentSlug,parentTitle]=parent,newParent={id:parentId,slug:parentSlug,title:parentTitle,contentType:contentType,locale:locale};"term"===contentType&&(newParent.taxonomy=taxonomy),parents.unshift(newParent),getParentSlug(parentId,contentType,parents,taxonomy,locale)}},getSlug=(args,returnParents=!1)=>{const{id:id="",slug:initSlug="",contentType:contentType="page",itemData:itemData,params:params}=isObjectStrict(args)?args:{};let slug=initSlug,typeSlug="",taxSlug="",parentSlugs="",parts=[];const{hierarchicalTypes:hierarchicalTypes,typeInSlug:typeInSlug,localeInSlug:localeInSlug,taxonomyInSlug:taxonomyInSlug}=config,itemLocale=isStringStrict(itemData?.locale)?itemData.locale:void 0,hasItemLocale=null!=itemLocale,locale=hasItemLocale?localeInSlug[itemLocale]:"",hasLocale=isStringStrict(locale),taxonomyInfo=getTaxonomyInfo(contentType,itemData),isTaxonomy="taxonomy"===contentType,isTerm="term"===contentType,{id:taxonomyId,slug:taxonomySlug,primaryContentType:taxonomyType,usePrimaryContentTypeSlug:taxonomyUseTypeSlug,isPage:taxonomyIsPage}=taxonomyInfo,archiveType=isStringStrict(taxonomyType)?taxonomyType:contentType,archiveInfo=getArchiveInfo(archiveType,itemLocale),{id:archiveId,slug:archiveSlug,title:archiveTitle,contentType:archiveContentType}=archiveInfo,archiveParents=[];if(archiveSlug&&archiveId&&(typeSlug=archiveSlug,archiveParents.push({contentType:archiveContentType,title:archiveTitle,slug:archiveSlug,id:archiveId,locale:itemLocale})),!isTaxonomy&&!isTerm||taxonomyUseTypeSlug||(typeSlug=""),isTerm&&taxonomySlug&&taxonomyId){taxSlug=taxonomySlug;const taxInSlug=taxonomyInSlug[taxSlug];if(isString(taxInSlug)&&(taxSlug=taxInSlug),isObjectStrict(taxInSlug)&&hasItemLocale){const localizedTaxSlug=taxInSlug[itemLocale];isString(localizedTaxSlug)&&(taxSlug=localizedTaxSlug)}taxonomyIsPage&&archiveParents.push({contentType:"taxonomy",locale:itemLocale,...taxonomyInfo})}const contentTypeInSlug=typeInSlug[archiveType];if(isString(contentTypeInSlug)&&(typeSlug=contentTypeInSlug),isObjectStrict(contentTypeInSlug)&&hasItemLocale){const localizedTypeSlug=contentTypeInSlug[itemLocale];isString(localizedTypeSlug)&&(typeSlug=localizedTypeSlug)}const isHierarchical=hierarchicalTypes.includes(contentType);let parents=[],hasParents=!1;getParentSlug(isHierarchical?id:archiveId,isHierarchical?contentType:archiveContentType,parents,taxonomyInfo,itemLocale),parents.length&&(parentSlugs=parents.map(({slug:slug})=>slug).join("/"),hasParents=!0),parents=isHierarchical?[...archiveParents,...parents]:[...parents,...archiveParents];const isIndex="index"===slug;if(isIndex&&!returnParents&&(slug=""),hasLocale&&parts.push(locale),hasParents&&!isHierarchical&&parts.push(parentSlugs),typeSlug&&parts.push(typeSlug),taxSlug&&parts.push(taxSlug),hasParents&&isHierarchical&&parts.push(parentSlugs),isStringStrict(slug)&&!isIndex&&parts.push(slug),parts=applyFilters("slugParts",parts,args),params){const paramsStr=new URLSearchParams(params).toString();paramsStr&&parts.push(`?${paramsStr}`)}let fullSlug=parts.length?parts.join("/"):"";if(fullSlug=applyFilters("slug",fullSlug,args),returnParents){return{slug:fullSlug,parents:parents}}return fullSlug},getPermalink=(slug="",trailingSlash=!0)=>{let url="";if(config.env.prod&&(url=config.env.prodUrl),!isStringStrict(slug)||"/"===slug)return`${url}/`;const hasStartSlash=slug.startsWith("/"),hasEndSlash=slug.endsWith("/");return hasStartSlash||(slug=`/${slug}`),!hasEndSlash&&trailingSlash&&(slug=`${slug}/`),`${url}${slug}`},getLink=(internalLink,externalLink)=>{if(isObjectStrict(internalLink)){const slug=internalLink.slug,res=getSlug({id:internalLink.id,contentType:internalLink.contentType,itemData:internalLink,slug:isString(slug)?slug:""});return getPermalink(res)}return isStringStrict(externalLink)?externalLink:""};export{getSlug,getLink,getPermalink};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isStringStrict}from"../string/string.js";import{isArrayStrict}from"../array/array.js";const shareLinks={Facebook:"https://www.facebook.com/sharer.php?u=",X:"https://twitter.com/intent/tweet?url=",LinkedIn:"https://www.linkedin.com/shareArticle?url=",Pinterest:"https://pinterest.com/pin/create/button/?url=",Reddit:"https://reddit.com/submit?url=",Email:""},getShareLinks=(url,platforms,title)=>isStringStrict(url)&&isArrayStrict(platforms)?platforms.map(platform=>{const platformLink=shareLinks[platform];let link=isStringStrict(platformLink)?`${platformLink}${url}`:"";return"Email"===platform&&(link=`mailto:?subject=${encodeURIComponent(isStringStrict(title)?title:"Check out this article")}&body=${url}`),{type:platform,link:link}}):[];export{getShareLinks};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RenderItem } from '../../render/renderTypes.js';
|
|
2
|
+
import type { Parent } from '../../global/globalTypes.js';
|
|
3
|
+
export interface LinkSlugArgs {
|
|
4
|
+
slug: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
contentType?: string;
|
|
7
|
+
itemData?: RenderItem;
|
|
8
|
+
params?: Record<string, string> | string;
|
|
9
|
+
}
|
|
10
|
+
export interface LinkSlugReturn {
|
|
11
|
+
slug: string;
|
|
12
|
+
parents: Parent[];
|
|
13
|
+
}
|
|
14
|
+
export type LinkSlugReturnType<T extends boolean> = T extends true ? LinkSlugReturn : string;
|
|
15
|
+
export interface LinkShare {
|
|
16
|
+
Facebook: string;
|
|
17
|
+
X: string;
|
|
18
|
+
LinkedIn: string;
|
|
19
|
+
Pinterest: string;
|
|
20
|
+
Reddit: string;
|
|
21
|
+
Email: string;
|
|
22
|
+
}
|
|
23
|
+
export interface LinkShareReturn {
|
|
24
|
+
type: keyof Partial<LinkShare>;
|
|
25
|
+
link: string;
|
|
26
|
+
}
|
|
27
|
+
export type LinkSlugPartsFilter = (parts: string[], args: LinkSlugArgs) => string[];
|
|
28
|
+
export type LinkSlugFilter = (slug: string, args: LinkSlugArgs) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isMap=value=>value instanceof Map;export{isMap};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const minify=value=>value.replace(/\s+/g," ").replace(/>\s+</g,"><").trim();export{minify};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isNumber=value=>"number"==typeof value&&!isNaN(value);export{isNumber};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const isObject: <T>(value: T) => value is object & T;
|
|
2
|
+
type NotObject<T, K> = Exclude<T, string | number | boolean | Map<T, K> | Set<T> | FormData | null | undefined | unknown[] | string[] | number[] | boolean[]>;
|
|
3
|
+
declare const isObjectStrict: <T, K>(value: T) => value is object & NotObject<T, K>;
|
|
4
|
+
export { isObject, isObjectStrict };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isObject=value=>"object"==typeof value&&null!=value,isObjectStrict=value=>isObject(value)&&"[object Object]"===Object.prototype.toString.call(value);export{isObject,isObjectStrict};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const getObjectKeys=obj=>Object.keys(obj);export{getObjectKeys};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isStringStrict}from"../string/string.js";import{config}from"../../config/config.js";import{storeDir}from"../../store/store.js";const getPath=(file,type)=>{const root=config.env.dir;if(!isStringStrict(root)||!isStringStrict(file))return"";let append=file;return"store"===type&&(append=`${storeDir}/${file}.json`),`${root}${root.endsWith("/")?"":"/"}${append}`},getPathDepth=(path="")=>{if(!isStringStrict(path))return"";let pathDepth=path.split("/");return pathDepth.pop(),pathDepth=pathDepth.map(()=>"../"),pathDepth.join("")};export{getPath,getPathDepth};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isArray}from"../array/array.js";const print=(pre="Log",message,type="error")=>{const output=`[1m${pre}: [0m\n${(isArray(message)?message:[message]).join("\n").trim()}`;"error"===type&&console.error(`[31m${output}`),"warning"===type&&console.warn(`[33m${output}`),"success"===type&&console.info(`[32m${output}`),"info"===type&&console.info(`[36m${output}`)};export{print};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isSet=value=>value instanceof Set,isSetStrict=value=>isSet(value)&&value.size>0;export{isSet,isSetStrict};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isString=value=>"string"==typeof value,isStringStrict=value=>isString(value)&&""!==value;export{isString,isStringStrict};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObjectStrict}from"../object/object.js";import{isStringStrict}from"../string/string.js";import{isArrayStrict}from"../array/array.js";const getTag=(item,id)=>{if(!isObjectStrict(item)||!isStringStrict(id))return;const tags=item.metadata?.tags;if(!isArrayStrict(tags))return;let tagInfo;return tags.find(tag=>{if(!isObjectStrict(tag))return!1;const tagId=tag.id;return tagId===id&&(tagInfo={id:tagId},!0)}),tagInfo},tagExists=(item,id)=>null!=getTag(item,id);export{getTag,tagExists};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const getYear=()=>(new Date).getFullYear();export{getYear};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AllWordPressDataArgs, WordPressDataArgs } from './wordpressDataTypes.js';
|
|
2
|
+
import type { RenderAllData, RenderData } from '../render/renderTypes.js';
|
|
3
|
+
declare const getRoute: (type: string) => string;
|
|
4
|
+
declare const getWordPressData: (args: WordPressDataArgs, _page?: number) => Promise<RenderData>;
|
|
5
|
+
declare const getAllWordPressData: (args?: AllWordPressDataArgs) => Promise<RenderAllData | undefined>;
|
|
6
|
+
export { getRoute, getWordPressData, getAllWordPressData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{normalizeWordPressData,normalizeWordPressMenuItems,normalizeWordPressMenus,normalRoutes}from"./wordpressDataNormal.js";import{applyFilters}from"../filters/filters.js";import{isObject,isObjectStrict}from"../utils/object/object.js";import{isString,isStringStrict}from"../utils/string/string.js";import{isArray}from"../utils/array/array.js";import{getStoreItem}from"../store/store.js";import{config}from"../config/config.js";const getRoute=type=>{const route=normalRoutes.get(type);return isString(route)?route:type},getWordPressData=async(args,_page=1)=>{if(!isObjectStrict(args))throw new Error("No args");const{key:key,route:route,params:params,fetcher:fetcher=fetch,options:options}=args;if(!isStringStrict(key))throw new Error("No key");if(config.env.cache){const cacheDataFilterArgs={key:key,type:"get"},cacheData=await applyFilters("cacheData",void 0,cacheDataFilterArgs,!0);if(isObject(cacheData))return structuredClone(cacheData)}if(!isStringStrict(route))throw new Error("No route");const{devUser:devUser,prodUser:prodUser,devCredential:devCredential,prodCredential:prodCredential,devHost:devHost,prodHost:prodHost,ssl:ssl=!0}=config.cms;let user=devUser,pass=devCredential,host=devHost,status="any";if(config.env.prod&&(user=prodUser,pass=prodCredential,host=prodHost,status="publish"),!isStringStrict(user)||!isStringStrict(pass)||!isStringStrict(host))throw new Error("No credentials");let url=`${ssl?"https":"http"}://${host}/wp-json/wp/v2/${route}?status=${status}`,loop=!1,embed=!1;if(isObjectStrict(params))for(const[key,value]of Object.entries(params)){let val=value;"_embed"===key&&(embed=!0),"per_page"===key&&-1===value&&(val=100,loop=!0),url+=`&${key}=${val.toString()}`}loop&&(url+=`&page=${_page}`),embed||(url+="&_embed");const headers=new Headers;headers.set("Authorization",`Basic ${btoa(`${user}:${pass}`)}`);const resp=await fetcher(url,{headers:headers,...options}),data=await resp.json(),isErr=isObjectStrict(data)&&isStringStrict(data.message),message=isErr?data.message:"Bad fetch response";if(!resp.ok||isErr)throw new Error(message,{cause:data});const total=resp.headers.get("X-WP-Total"),totalPages=resp.headers.get("X-WP-TotalPages"),totalNum=isStringStrict(total)?parseInt(total,10):0,totalPagesNum=isStringStrict(totalPages)?parseInt(totalPages,10):0,dataItems=isArray(data)?data:[data];let newItems=normalizeWordPressData(dataItems,route);if(loop&&_page<totalPagesNum){const pagData=await getWordPressData({key:key,route:route,params:{per_page:-1}},_page+1),{items:pagItems}=pagData;newItems=[...newItems,...pagItems]}const newData={items:newItems,total:totalNum,pages:totalPagesNum};if(config.env.cache){const cacheDataFilterArgs={key:key,type:"set",data:data};await applyFilters("cacheData",newData,cacheDataFilterArgs,!0)}return newData},getAllWordPressData=async args=>{const{serverlessData:serverlessData,previewData:previewData}=isObjectStrict(args)?args:{};let allData={navigationItem:[],navigation:[],content:{page:[]}};const isServerless=null!=serverlessData,isPreview=null!=previewData,wordpressDataFilterArgs={serverlessData:serverlessData,previewData:previewData};if(isServerless||isPreview){let contentType="",id="";if(isServerless){const item=getStoreItem("slugs")[serverlessData.path];if(item){const[itemId,itemContentType]=item;id=itemId||"",contentType=itemContentType||""}}if(isPreview&&(id=previewData.id,contentType=previewData.contentType),id){const key=`serverless_${id}_${contentType}`,data=await getWordPressData({key:key,route:`${getRoute(contentType)}/${id}`});let{items:items}=data;items=applyFilters("wordpressData",items,{...wordpressDataFilterArgs,contentType:contentType}),allData.content[contentType]=items}}if(!isServerless){const partial=config.partialTypes;for(const contentType of partial){const isMenu="nav_menu"===contentType,isMenuItem="nav_menu_item"===contentType,partialType=isMenu?"navigation":isMenuItem?"navigationItem":contentType;allData[partialType]=[];const key=`all_${contentType}`,data=await getWordPressData({key:key,route:getRoute(contentType),params:{per_page:-1}});let{items:items}=data;isMenuItem&&(items=normalizeWordPressMenuItems(items)),isMenu&&(items=normalizeWordPressMenus(items)),items=applyFilters("wordpressData",items,{...wordpressDataFilterArgs,contentType:contentType}),allData[partialType]=items}}if(!isServerless&&!isPreview){const whole=config.wholeTypes;for(const contentType of whole){allData.content[contentType]=[];const key=`all_${contentType}`,data=await getWordPressData({key:key,route:getRoute(contentType),params:{per_page:-1}});let{items:items}=data;items=applyFilters("wordpressData",items,{...wordpressDataFilterArgs,contentType:contentType}),allData.content[contentType]=items}}return allData=applyFilters("allData",allData,{type:"wordpress",serverlessData:serverlessData,previewData:previewData}),allData};export{getRoute,getWordPressData,getAllWordPressData};
|