@alanizcreative/formation-static 1.3.0-beta.29
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 +3 -0
- package/cjs/components/Navigation/Navigation.d.ts +16 -0
- package/cjs/components/Navigation/Navigation.js +1 -0
- package/cjs/components/Navigation/NavigationTypes.d.ts +85 -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 +44 -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 +64 -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 +67 -0
- package/cjs/contentful/contentfulDataTypes.js +1 -0
- package/cjs/global/globalTypes.d.ts +32 -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 +74 -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 +198 -0
- package/cjs/render/renderTypes.js +1 -0
- package/cjs/serverless/Ajax/Ajax.d.ts +3 -0
- package/cjs/serverless/Ajax/Ajax.js +1 -0
- package/cjs/serverless/Ajax/AjaxTypes.d.ts +11 -0
- package/cjs/serverless/Ajax/AjaxTypes.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/Preview/Preview.d.ts +5 -0
- package/cjs/serverless/Preview/Preview.js +1 -0
- package/cjs/serverless/Reload/Reload.d.ts +5 -0
- package/cjs/serverless/Reload/Reload.js +1 -0
- package/cjs/serverless/Reload/ReloadTypes.d.ts +5 -0
- package/cjs/serverless/Reload/ReloadTypes.js +1 -0
- package/cjs/serverless/serverless.d.ts +6 -0
- package/cjs/serverless/serverless.js +1 -0
- package/cjs/serverless/serverlessFiles.d.ts +3 -0
- package/cjs/serverless/serverlessFiles.js +1 -0
- package/cjs/serverless/serverlessTypes.d.ts +50 -0
- package/cjs/serverless/serverlessTypes.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 +35 -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/action/action.d.ts +8 -0
- package/cjs/utils/action/action.js +1 -0
- package/cjs/utils/action/actionTypes.d.ts +10 -0
- package/cjs/utils/action/actionTypes.js +1 -0
- package/cjs/utils/archive/archive.d.ts +7 -0
- package/cjs/utils/archive/archive.js +1 -0
- package/cjs/utils/archive/archiveTypes.d.ts +18 -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/filePath.d.ts +2 -0
- package/cjs/utils/file/filePath.js +1 -0
- package/cjs/utils/filter/filter.d.ts +8 -0
- package/cjs/utils/filter/filter.js +1 -0
- package/cjs/utils/filter/filterTypes.d.ts +62 -0
- package/cjs/utils/filter/filterTypes.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 +60 -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 +31 -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/scriptStyle/scriptStyle.d.ts +8 -0
- package/cjs/utils/scriptStyle/scriptStyle.js +1 -0
- package/cjs/utils/scriptStyle/scriptStyleTypes.d.ts +12 -0
- package/cjs/utils/scriptStyle/scriptStyleTypes.js +1 -0
- package/cjs/utils/set/set.d.ts +3 -0
- package/cjs/utils/set/set.js +1 -0
- package/cjs/utils/shortcode/shortcode.d.ts +10 -0
- package/cjs/utils/shortcode/shortcode.js +1 -0
- package/cjs/utils/shortcode/shortcodeTypes.d.ts +20 -0
- package/cjs/utils/shortcode/shortcodeTypes.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 +7 -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 +206 -0
- package/cjs/wordpress/wordpressDataTypes.js +1 -0
- package/lib/components/Navigation/Navigation.d.ts +16 -0
- package/lib/components/Navigation/Navigation.js +1 -0
- package/lib/components/Navigation/NavigationTypes.d.ts +85 -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 +44 -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 +64 -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 +67 -0
- package/lib/contentful/contentfulDataTypes.js +1 -0
- package/lib/global/globalTypes.d.ts +32 -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 +74 -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 +198 -0
- package/lib/render/renderTypes.js +1 -0
- package/lib/serverless/Ajax/Ajax.d.ts +3 -0
- package/lib/serverless/Ajax/Ajax.js +1 -0
- package/lib/serverless/Ajax/AjaxTypes.d.ts +11 -0
- package/lib/serverless/Ajax/AjaxTypes.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/Preview/Preview.d.ts +5 -0
- package/lib/serverless/Preview/Preview.js +1 -0
- package/lib/serverless/Reload/Reload.d.ts +5 -0
- package/lib/serverless/Reload/Reload.js +1 -0
- package/lib/serverless/Reload/ReloadTypes.d.ts +5 -0
- package/lib/serverless/Reload/ReloadTypes.js +1 -0
- package/lib/serverless/serverless.d.ts +6 -0
- package/lib/serverless/serverless.js +1 -0
- package/lib/serverless/serverlessFiles.d.ts +3 -0
- package/lib/serverless/serverlessFiles.js +1 -0
- package/lib/serverless/serverlessTypes.d.ts +50 -0
- package/lib/serverless/serverlessTypes.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 +35 -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/action/action.d.ts +8 -0
- package/lib/utils/action/action.js +1 -0
- package/lib/utils/action/actionTypes.d.ts +10 -0
- package/lib/utils/action/actionTypes.js +1 -0
- package/lib/utils/archive/archive.d.ts +7 -0
- package/lib/utils/archive/archive.js +1 -0
- package/lib/utils/archive/archiveTypes.d.ts +18 -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/filePath.d.ts +2 -0
- package/lib/utils/file/filePath.js +1 -0
- package/lib/utils/filter/filter.d.ts +8 -0
- package/lib/utils/filter/filter.js +1 -0
- package/lib/utils/filter/filterTypes.d.ts +62 -0
- package/lib/utils/filter/filterTypes.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 +60 -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 +31 -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/scriptStyle/scriptStyle.d.ts +8 -0
- package/lib/utils/scriptStyle/scriptStyle.js +1 -0
- package/lib/utils/scriptStyle/scriptStyleTypes.d.ts +12 -0
- package/lib/utils/scriptStyle/scriptStyleTypes.js +1 -0
- package/lib/utils/set/set.d.ts +3 -0
- package/lib/utils/set/set.js +1 -0
- package/lib/utils/shortcode/shortcode.d.ts +10 -0
- package/lib/utils/shortcode/shortcode.js +1 -0
- package/lib/utils/shortcode/shortcodeTypes.d.ts +20 -0
- package/lib/utils/shortcode/shortcodeTypes.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 +7 -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 +206 -0
- package/lib/wordpress/wordpressDataTypes.js +1 -0
- package/package.json +87 -0
|
@@ -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"../shortcode/shortcode.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
|
+
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,8 @@
|
|
|
1
|
+
import type { Filters, FilterMap, FilterReturnType } from './filterTypes.js';
|
|
2
|
+
declare let filters: FilterMap;
|
|
3
|
+
declare const addFilter: <T extends keyof Filters>(name: T, filter: Filters[T]) => boolean;
|
|
4
|
+
declare const removeFilter: <T extends keyof Filters>(name: T, filter: Filters[T]) => boolean;
|
|
5
|
+
declare const applyFilters: <T, V extends boolean = false>(name: string, value: T, args?: unknown, isAsync?: V) => FilterReturnType<T, V>;
|
|
6
|
+
declare const resetFilters: () => void;
|
|
7
|
+
declare const setFilters: (args: Partial<Filters>) => boolean;
|
|
8
|
+
export { filters, addFilter, removeFilter, applyFilters, resetFilters, setFilters };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isSet,isSetStrict}from"../set/set.js";import{isStringStrict}from"../string/string.js";import{isObjectStrict}from"../object/object.js";import{isFunction}from"../function/function.js";let filters=new Map([["columnProps",new Set],["containerProps",new Set],["formOptionProps",new Set],["formFieldProps",new Set],["formProps",new Set],["richTextProps",new Set],["richTextOutput",new Set],["richTextContentItem",new Set],["richTextContent",new Set],["richTextContentOutput",new Set],["renderItem",new Set],["renderItemData",new Set],["renderContent",new Set],["ajaxResult",new Set],["contactResult",new Set],["cacheData",new Set],["storeData",new Set],["contentfulData",new Set],["wordpressData",new Set],["localData",new Set],["allData",new Set],["slugParts",new Set],["slug",new Set]]);const addFilter=(name,filter)=>!(!isStringStrict(name)||!isFunction(filter))&&(isSet(filters.get(name))||filters.set(name,new Set),filters.get(name)?.add(filter),!0),removeFilter=(name,filter)=>{if(!isStringStrict(name)||!isFunction(filter))return!1;const filterSet=filters.get(name);return!!isSet(filterSet)&&filterSet.delete(filter)},applySequentially=async(callbacks,value,args)=>{for(const callback of callbacks)value=await callback(value,args);return value},applyFilters=(name,value,args,isAsync=!1)=>{const filterSet=filters.get(name);if(!isSetStrict(filterSet))return value;const callbacks=[];for(const callback of filterSet.values())isAsync?callbacks.push(callback):value=callback(value,args);return isAsync?applySequentially(callbacks,value,args).then((newValue=>newValue)).catch((()=>value)):value},resetFilters=()=>{filters=new Map([["columnProps",new Set],["containerProps",new Set],["formOptionProps",new Set],["formFieldProps",new Set],["formProps",new Set],["richTextProps",new Set],["richTextOutput",new Set],["richTextContentItem",new Set],["richTextContent",new Set],["richTextContentOutput",new Set],["renderItem",new Set],["renderItemData",new Set],["renderContent",new Set],["ajaxResult",new Set],["contactResult",new Set],["cacheData",new Set],["storeData",new Set],["contentfulData",new Set],["wordpressData",new Set],["localData",new Set],["allData",new Set],["slugParts",new Set],["slug",new Set]])},setFilters=args=>{if(!isObjectStrict(args))return!1;const newFilters=Object.entries(args);return!!newFilters.length&&(resetFilters(),newFilters.forEach((([name,filter])=>{filter&&addFilter(name,filter)})),!0)};export{filters,addFilter,removeFilter,applyFilters,resetFilters,setFilters};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { GenericFunction } from '../../global/globalTypes.js';
|
|
2
|
+
import type { ColumnPropsFilter } from '../../layouts/Column/ColumnTypes.js';
|
|
3
|
+
import type { ContainerPropsFilter } from '../../layouts/Container/ContainerTypes.js';
|
|
4
|
+
import type { FormPropsFilter, FormFieldPropsFilter, FormOptionPropsFilter } from '../../objects/Form/FormTypes.js';
|
|
5
|
+
import type { AjaxResultFilter } from '../../serverless/Ajax/AjaxTypes.js';
|
|
6
|
+
import type { ContactResultFilter } from '../../serverless/Contact/ContactTypes.js';
|
|
7
|
+
import type { LinkSlugPartsFilter, LinkSlugFilter } from '../link/linkTypes.js';
|
|
8
|
+
import type { RichTextPropsFilter, RichTextOutputFilter, RichTextContentItemFilter, RichTextContentFilter, RichTextContentOutputFilter } from '../../text/RichText/RichTextTypes.js';
|
|
9
|
+
import type { RenderItem, RenderItemFilter, RenderItemDataFilter, RenderContentFilter, RenderServerlessData, RenderPreviewData, RenderAllData, RenderDataMeta } from '../../render/renderTypes.js';
|
|
10
|
+
export interface DataFilterArgs {
|
|
11
|
+
serverlessData?: RenderServerlessData;
|
|
12
|
+
previewData?: RenderPreviewData;
|
|
13
|
+
contentType?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AllDataFilterArgs {
|
|
16
|
+
type: 'contentful' | 'wordpress' | 'local';
|
|
17
|
+
serverlessData?: RenderServerlessData;
|
|
18
|
+
previewData?: RenderPreviewData;
|
|
19
|
+
}
|
|
20
|
+
export type ContentfulDataFilter = (data: RenderItem[], args: DataFilterArgs) => RenderItem[];
|
|
21
|
+
export type WordpressDataFilter = (data: RenderItem[], args: DataFilterArgs) => RenderItem[];
|
|
22
|
+
export type LocalDataFilter = (data: RenderItem) => RenderItem;
|
|
23
|
+
export type AllDataFilter = (allData: RenderAllData, args: AllDataFilterArgs) => RenderAllData;
|
|
24
|
+
export interface CacheData {
|
|
25
|
+
items?: RenderItem[];
|
|
26
|
+
meta?: RenderDataMeta;
|
|
27
|
+
data?: Record<string, RenderItem>;
|
|
28
|
+
}
|
|
29
|
+
export interface CacheDataFilterArgs {
|
|
30
|
+
key: string;
|
|
31
|
+
type: string;
|
|
32
|
+
data?: CacheData;
|
|
33
|
+
}
|
|
34
|
+
export type CacheDataFilter = (data: CacheData, args: CacheDataFilterArgs) => Promise<CacheData | undefined>;
|
|
35
|
+
export type StoreDataFilter = (data: object | undefined, type: string) => Promise<object | undefined>;
|
|
36
|
+
export interface Filters extends Record<string, GenericFunction> {
|
|
37
|
+
columnProps: ColumnPropsFilter;
|
|
38
|
+
containerProps: ContainerPropsFilter;
|
|
39
|
+
formOptionProps: FormOptionPropsFilter;
|
|
40
|
+
formFieldProps: FormFieldPropsFilter;
|
|
41
|
+
formProps: FormPropsFilter;
|
|
42
|
+
richTextProps: RichTextPropsFilter;
|
|
43
|
+
richTextOutput: RichTextOutputFilter;
|
|
44
|
+
richTextContentItem: RichTextContentItemFilter;
|
|
45
|
+
richTextContent: RichTextContentFilter;
|
|
46
|
+
richTextContentOutput: RichTextContentOutputFilter;
|
|
47
|
+
renderItem: RenderItemFilter;
|
|
48
|
+
renderItemData: RenderItemDataFilter;
|
|
49
|
+
renderContent: RenderContentFilter;
|
|
50
|
+
ajaxResult: AjaxResultFilter;
|
|
51
|
+
contactResult: ContactResultFilter;
|
|
52
|
+
cacheData: CacheDataFilter;
|
|
53
|
+
storeData: StoreDataFilter;
|
|
54
|
+
contentfulData: ContentfulDataFilter;
|
|
55
|
+
wordpressData: WordpressDataFilter;
|
|
56
|
+
localData: LocalDataFilter;
|
|
57
|
+
allData: AllDataFilter;
|
|
58
|
+
slugParts: LinkSlugPartsFilter;
|
|
59
|
+
slug: LinkSlugFilter;
|
|
60
|
+
}
|
|
61
|
+
export type FilterMap = Map<string, Set<GenericFunction>> & Map<'columnProps' | 'containerProps' | 'formOptionProps' | 'formFieldProps' | 'formProps' | 'richTextProps' | 'richTextOutput' | 'richTextContentItem' | 'richTextContent' | 'richTextContentOutput' | 'renderItem' | 'renderItemData' | 'renderContent' | 'ajaxResult' | 'contactResult' | 'cacheData' | 'storeData' | 'contentfulData' | 'wordpressData' | 'localData' | 'allData' | 'slugParts' | 'slug', Set<ColumnPropsFilter | ContainerPropsFilter | FormOptionPropsFilter | FormFieldPropsFilter | FormPropsFilter | RichTextPropsFilter | RichTextOutputFilter | RichTextContentItemFilter | RichTextContentFilter | RichTextContentOutputFilter | RenderItemFilter | RenderItemDataFilter | RenderContentFilter | AjaxResultFilter | ContactResultFilter | CacheDataFilter | StoreDataFilter | ContentfulDataFilter | WordpressDataFilter | LocalDataFilter | AllDataFilter | LinkSlugPartsFilter | LinkSlugFilter>>;
|
|
62
|
+
export type FilterReturnType<T, V extends false | true> = V extends true ? Promise<T> : T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isFunction=value=>"function"==typeof value;export{isFunction};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isHeading=tag=>["h1","h2","h3","h4","h5","h6"].includes(tag);export{isHeading};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ImageArgs, ImageReturnType, ImageMaxWidthArgs } from './imageTypes.js';
|
|
2
|
+
declare const getImage: <V extends boolean = false>(args: ImageArgs, returnDetails?: V) => ImageReturnType<V>;
|
|
3
|
+
declare const getImageClosestSize: (size: number) => number;
|
|
4
|
+
declare const getImageMaxWidth: (args: ImageMaxWidthArgs) => number;
|
|
5
|
+
export { getImage, getImageClosestSize, getImageMaxWidth };
|
|
@@ -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 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,format:format="webp"}=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"}=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;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));let src=url,srcFallback=url;if(isLocal&&(src=`${url}.${format}`,srcFallback=`${url}.${naturalFormat}`),isRemote){const params=`&q=${quality}&w=${w}&h=${h}`;src=`${url}?fm=${format}${params}`,srcFallback=`${url}?fm=${naturalFormat}${params}`}const 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 params=`&q=${quality}&w=${s}&h=${Math.round(s*aspectRatio)} ${s}w`;srcsetFallback.push(`${url}?fm=${naturalFormat}${params}`),srcsetSource.push(`${url}?fm=${format}${params}`)}if(isWordpress){const sizeUrl=data.sizes?.[s];isStringStrict(sizeUrl)&&srcsetSource.push(`${sizeUrl} ${s}w`)}}));let sourceOutput="";picture&&(sourceOutput=`<source srcset="${srcsetSource.join(", ")}" sizes="${sizes}" 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="${sizes}"\n width="${w}"\n height="${h}"\n ${isStringStrict(attr)?` ${attr}`:""}\n ${lazy?' loading="lazy" decoding="async"':' loading="eager"'}\n >\n `;return returnDetails?{output:output,aspectRatio:aspectRatio,naturalWidth:naturalWidth,naturalHeight:naturalHeight,src:src,srcFallback:srcFallback,srcset:srcsetSource,sizes:sizes}:output},getImageClosestSize=size=>[...config.image.sizes].reduce(((prev,curr)=>Math.abs(curr-size)<=Math.abs(prev-size)?curr:prev)),getImageMaxWidth=args=>{if(!isObjectStrict(args))return 0;const{parents:parents,widths:widths,maxWidths:maxWidths,breakpoints:breakpoints,source:source=config.source}=args;if(!(isArrayStrict(parents)&&isObjectStrict(widths)&&isObjectStrict(maxWidths)&&isArrayStrict(breakpoints)))return 0;const w=[];let m=0;if(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;w[0]=isNumber(widths[width])&&widths[width]>0?widths[width]:1,w[1]=isNumber(widths[widthSmall])&&widths[widthSmall]>0?widths[widthSmall]:w[0],w[2]=isNumber(widths[widthMedium])&&widths[widthMedium]>0?widths[widthMedium]:w[1],w[3]=isNumber(widths[widthLarge])&&widths[widthLarge]>0?widths[widthLarge]:w[2]}if("container"===renderType){const{maxWidth:maxWidth="Default"}=args;m=isNumber(maxWidths[maxWidth])?maxWidths[maxWidth]:0}}})),!w.length&&0===m)return 0;const bk=[...breakpoints],calc=[];let lastW=1;bk.forEach(((b,i)=>{const wd=w[i];isNumber(wd)&&(lastW=wd,m>0&&b>m?calc.push(wd*m):calc.push(wd*b))})),m>0&&calc.push(lastW*m);const res=2*Math.max(...calc);return"local"===source?getImageClosestSize(res):res};export{getImage,getImageClosestSize,getImageMaxWidth};
|
|
@@ -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,60 @@
|
|
|
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
|
+
format?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ImageReturn {
|
|
22
|
+
output: string;
|
|
23
|
+
src: string;
|
|
24
|
+
srcFallback: string;
|
|
25
|
+
srcset: string[];
|
|
26
|
+
sizes: string;
|
|
27
|
+
aspectRatio: number;
|
|
28
|
+
naturalWidth: number;
|
|
29
|
+
naturalHeight: number;
|
|
30
|
+
}
|
|
31
|
+
export type ImageReturnType<V extends false | true> = V extends true ? ImageReturn : string;
|
|
32
|
+
export type ImageMaxWidthParents = ParentArgs & ColumnProps & ContainerProps;
|
|
33
|
+
export interface ImageMaxWidthArgs<T = ImageMaxWidthParents> {
|
|
34
|
+
parents: T[];
|
|
35
|
+
widths: GenericNumbers;
|
|
36
|
+
maxWidths: GenericNumbers;
|
|
37
|
+
breakpoints: number[];
|
|
38
|
+
source?: Source;
|
|
39
|
+
}
|
|
40
|
+
export interface ImageLocal {
|
|
41
|
+
instance: sharp.Sharp;
|
|
42
|
+
size: number;
|
|
43
|
+
format: string;
|
|
44
|
+
path: string;
|
|
45
|
+
newPath: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ImageRemote {
|
|
48
|
+
path: string;
|
|
49
|
+
url: string;
|
|
50
|
+
format?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ImageProps {
|
|
53
|
+
path: string;
|
|
54
|
+
name: string;
|
|
55
|
+
type: string;
|
|
56
|
+
format: string;
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
size: number;
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObject}from"../object/object.js";import{getPath}from"../path/path.js";import{applyFilters}from"../filter/filter.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{isNumber}from"../number/number.js";import{isObjectStrict}from"../object/object.js";import{isString,isStringStrict}from"../string/string.js";import{applyFilters}from"../filter/filter.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)=>{const storeParents=getStoreItem("parents"),parent=storeParents[contentType]?.[id];parent&&(parents.unshift({...parent,contentType:contentType}),getParentSlug(parent.id,contentType,parents))},getSlug=(args,returnParents=!1)=>{const{id:id="",page:page=0,slug:initSlug="",contentType:contentType="page",pageData:pageData}=isObjectStrict(args)?args:{};let slug=initSlug,typeSlug="",taxSlug="",parentSlugs="",parts=[];const{hierarchicalTypes:hierarchicalTypes,typeInSlug:typeInSlug,localeInSlug:localeInSlug,taxonomyInSlug:taxonomyInSlug}=config,pageLocale=pageData?.locale,hasPageLocale=isStringStrict(pageLocale),locale=hasPageLocale?localeInSlug[pageLocale]:"",hasLocale=isStringStrict(locale),taxonomyInfo=getTaxonomyInfo(contentType,pageData),isTaxonomy="taxonomy"===contentType,isTerm="term"===contentType,{id:taxonomyId,slug:taxonomySlug,title:taxonomyTitle,primaryContentType:taxonomyType,usePrimaryContentTypeSlug:taxonomyUseTypeSlug,isPage:taxonomyIsPage}=taxonomyInfo,archiveType=isStringStrict(taxonomyType)?taxonomyType:contentType,archiveInfo=getArchiveInfo(archiveType),{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})),!isTaxonomy&&!isTerm||taxonomyUseTypeSlug||(typeSlug=""),isTerm&&taxonomySlug&&taxonomyId){taxSlug=taxonomySlug;const taxInSlug=taxonomyInSlug[taxSlug];if(isString(taxInSlug)&&(taxSlug=taxInSlug),isObjectStrict(taxInSlug)&&hasPageLocale){const localizedTaxSlug=taxInSlug[pageLocale];isString(localizedTaxSlug)&&(taxSlug=localizedTaxSlug)}taxonomyIsPage&&archiveParents.push({contentType:"taxonomy",title:taxonomyTitle,slug:taxSlug,id:taxonomyId})}const contentTypeInSlug=typeInSlug[archiveType];if(isString(contentTypeInSlug)&&(typeSlug=contentTypeInSlug),isObjectStrict(contentTypeInSlug)&&hasPageLocale){const localizedTypeSlug=contentTypeInSlug[pageLocale];isString(localizedTypeSlug)&&(typeSlug=localizedTypeSlug)}const isHierarchical=hierarchicalTypes.includes(contentType);let parents=[],hasParents=!1;getParentSlug(isHierarchical?id:archiveId,isHierarchical?contentType:archiveContentType,parents),parents.length>0&&(parentSlugs=parents.map((({slug:slug})=>slug)).join("/"),hasParents=!0),parents=isHierarchical?[...archiveParents,...parents]:[...parents,...archiveParents];const isIndex="index"===slug;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);let fullSlug=`${parts.length>0?parts.join("/"):""}${isNumber(page)&&page>1?`/?page=${page}`:""}`;if(fullSlug=applyFilters("slug",fullSlug,args),returnParents){return{slug:fullSlug,parents:parents}}return fullSlug},getPermalink=(slug="",trailingSlash=!0)=>{let url="/";return config.env.prod&&(url=config.env.prodUrl),isString(slug)&&"/"!==slug?`${url}${slug}${""!==slug&&trailingSlash?"/":""}`:url},getLink=(internalLink,externalLink)=>{if(isObjectStrict(internalLink)){const slug=internalLink.slug,res=getSlug({id:internalLink.id,contentType:internalLink.contentType,pageData: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,31 @@
|
|
|
1
|
+
import type { RenderItem } from '../../render/renderTypes.js';
|
|
2
|
+
import type { StoreParent } from '../../store/storeTypes.js';
|
|
3
|
+
export interface LinkSlugArgs {
|
|
4
|
+
id?: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
page?: number;
|
|
7
|
+
contentType?: string;
|
|
8
|
+
pageData?: RenderItem;
|
|
9
|
+
}
|
|
10
|
+
export interface LinkSlugParent extends StoreParent {
|
|
11
|
+
contentType: string;
|
|
12
|
+
}
|
|
13
|
+
export interface LinkSlugReturn {
|
|
14
|
+
slug: string;
|
|
15
|
+
parents: LinkSlugParent[];
|
|
16
|
+
}
|
|
17
|
+
export type LinkSlugReturnType<T extends boolean> = T extends true ? LinkSlugReturn : string;
|
|
18
|
+
export interface LinkShare {
|
|
19
|
+
Facebook: string;
|
|
20
|
+
X: string;
|
|
21
|
+
LinkedIn: string;
|
|
22
|
+
Pinterest: string;
|
|
23
|
+
Reddit: string;
|
|
24
|
+
Email: string;
|
|
25
|
+
}
|
|
26
|
+
export interface LinkShareReturn {
|
|
27
|
+
type: keyof Partial<LinkShare>;
|
|
28
|
+
link: string;
|
|
29
|
+
}
|
|
30
|
+
export type LinkSlugPartsFilter = (parts: string[], args: LinkSlugArgs) => string[];
|
|
31
|
+
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";import{serverlessDir}from"../../serverless/serverless.js";const getPath=(file,type)=>{const root=config.env.dir;if(!isStringStrict(root)||!isStringStrict(file))return"";let append=file;if("store"===type){const dir=storeDir;isStringStrict(dir)&&(append=`${dir}/${file}.json`)}if("serverless"===type){const dir=serverlessDir;isStringStrict(dir)&&(append=`${dir}/${file}.js`)}return`${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,8 @@
|
|
|
1
|
+
import type { Scripts, Styles } from './scriptStyleTypes.js';
|
|
2
|
+
declare const scripts: Scripts;
|
|
3
|
+
declare const styles: Styles;
|
|
4
|
+
declare const addScript: (path: string, deps?: string[]) => boolean;
|
|
5
|
+
declare const addStyle: (path: string, deps?: string[]) => boolean;
|
|
6
|
+
declare const outputScripts: (link: string) => string;
|
|
7
|
+
declare const outputStyles: (link: string) => string;
|
|
8
|
+
export { scripts, styles, addScript, addStyle, outputScripts, outputStyles };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isArrayStrict}from"../array/array.js";import{isStringStrict}from"../string/string.js";import{config}from"../../config/config.js";const scripts={deps:new Map,item:new Map,build:new Map,meta:{}},styles={deps:new Map,item:new Map,build:new Map},addScriptStyle=(type,path,deps=[])=>{if(!isStringStrict(path))return!1;const isScripts="scripts"===type,assets=isScripts?scripts:styles,ext=isScripts?"js":"scss",{inputDir:inputDir,outputDir:outputDir}=config[type],input=`${inputDir}/${path}.${ext}`,output=`${outputDir}/${path}`;return assets.item.set(output,input),assets.build.set(output,input),isArrayStrict(deps)&&deps.forEach((dep=>{const depInput=`${inputDir}/${dep}.${ext}`,depOutput=`${outputDir}/${dep}`;assets.deps.has(output)||assets.deps.set(output,new Set),assets.deps.get(output)?.add(depOutput),assets.item.set(depOutput,depInput),assets.build.set(depOutput,depInput)})),!0},addScript=(path,deps=[])=>addScriptStyle("scripts",path,deps),addStyle=(path,deps=[])=>addScriptStyle("styles",path,deps),outputScriptsStyles=(type,link)=>{if(!isStringStrict(link))return"";const{item:item,deps:deps}="scripts"===type?scripts:styles;if(!item.size)return"";const itemOut=Array.from(item.keys());itemOut.sort(((a,b)=>{const aIsDep=deps.get(b)?.has(a),bIsDep=deps.get(a)?.has(b);return!0===aIsDep?-1:!0===bIsDep?1:0}));let output="";return itemOut.forEach((out=>{"scripts"===type&&(output+=`<script type="module" src="${link}${out}.js"><\/script>`),"styles"===type&&(output+=`<link rel="stylesheet" href="${link}${out}.css" media="all">`)})),output},outputScripts=link=>outputScriptsStyles("scripts",link),outputStyles=link=>outputScriptsStyles("styles",link);export{scripts,styles,addScript,addStyle,outputScripts,outputStyles};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Generic } from '../../global/globalTypes.js';
|
|
2
|
+
export interface Scripts {
|
|
3
|
+
deps: Map<string, Set<string>>;
|
|
4
|
+
item: Map<string, string>;
|
|
5
|
+
build: Map<string, string>;
|
|
6
|
+
meta: Generic;
|
|
7
|
+
}
|
|
8
|
+
export interface Styles {
|
|
9
|
+
deps: Map<string, Set<string>>;
|
|
10
|
+
item: Map<string, string>;
|
|
11
|
+
build: Map<string, string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isSet=value=>value instanceof Set,isSetStrict=value=>isSet(value)&&value.size>0;export{isSet,isSetStrict};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Shortcode, Shortcodes, ShortcodesSet } from './shortcodeTypes.js';
|
|
2
|
+
import type { RenderItem } from '../../render/renderTypes.js';
|
|
3
|
+
declare const shortcodes: Shortcodes;
|
|
4
|
+
declare const addShortcode: <T extends Shortcode>(name: string, shortcode: T) => boolean;
|
|
5
|
+
declare const removeShortcode: (name: string) => boolean;
|
|
6
|
+
declare const doShortcodes: (content: string, pageData?: RenderItem) => Promise<string>;
|
|
7
|
+
declare const resetShortcodes: () => void;
|
|
8
|
+
declare const setShortcodes: <T extends ShortcodesSet>(args: T) => boolean;
|
|
9
|
+
declare const stripShortcodes: (content: string) => string;
|
|
10
|
+
export { shortcodes, addShortcode, removeShortcode, doShortcodes, resetShortcodes, setShortcodes, stripShortcodes };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObjectStrict}from"../object/object.js";import{isArrayStrict}from"../array/array.js";import{isStringStrict}from"../string/string.js";import{isFunction}from"../function/function.js";import{isNumber}from"../number/number.js";import{escape}from"../escape/escape.js";const shortcodes=new Map,attrReg=/[\w-]+=".*?"/g,getShortcodeData=(content,tagNames,props,pageData)=>{if(!isStringStrict(content)||!isStringStrict(tagNames))return[];const reg=new RegExp(String.raw`\[(?:\/)?(?<name>${tagNames})(?:\s[^\]]*?)?\]`,"g"),matches=[...content.matchAll(reg)];if(!matches.length)return[];const data=[];return matches.forEach(((opening,i)=>{const name=opening.groups?.name,tag=opening[0];if(!isStringStrict(name)||tag.startsWith("[/"))return;const info=props||shortcodes.get(name);if(!isObjectStrict(info))return;const child=info.child,hasChild=isStringStrict(child),startIndex=opening.index,startLen=tag.length;let endIndex=startIndex+tag.length,endLen=0;const closingTag=`[/${name}]`,closingMatch=hasChild?matches.find((m=>m[0]===closingTag)):matches[i+1];closingMatch?.[0]===closingTag&&(endIndex=closingMatch.index,endLen=closingTag.length);const attributes={},attributeTypes=isObjectStrict(info.attributeTypes)?info.attributeTypes:{},attr=tag.match(attrReg);isArrayStrict(attr)&&attr.forEach((a=>{const[key,value]=a.split("=");if(!isStringStrict(key)||!isStringStrict(value))return;let val=escape(value.replace(/"/g,""));if(isStringStrict(attributeTypes[key])){const type=attributeTypes[key];if("number"===type){const num=parseInt(val,10);val=isNaN(num)?0:num}"boolean"===type&&(val="true"===val)}attributes[key]=val}));let replaceContent="",innerContent="";isNumber(startIndex)&&isNumber(endIndex)&&(replaceContent=content.slice(startIndex,endIndex+endLen),innerContent=content.slice(startIndex+startLen,endIndex));let children=[];hasChild&&(children=getShortcodeData(innerContent,child,props,pageData)),data.push({name:name,replaceContent:replaceContent,content:innerContent,attributes:attributes,children:children,pageData:pageData})})),data},addShortcode=(name,shortcode)=>!(!isStringStrict(name)||!isObjectStrict(shortcode))&&(shortcodes.set(name,shortcode),!0),removeShortcode=name=>!!isStringStrict(name)&&shortcodes.delete(name),doShortcodes=async(content,pageData)=>{if(!shortcodes.size)return content;const names=[...shortcodes.keys()].join("|"),data=getShortcodeData(content,names,void 0,pageData);if(!data.length)return content;let newContent=content;for(const datum of data){const{name:name,replaceContent:replaceContent}=datum,callback=shortcodes.get(name)?.callback;if(isFunction(callback)){const res=await callback({...datum,pageData:pageData});isStringStrict(res)&&(newContent=newContent.replace(replaceContent,res))}}return newContent},resetShortcodes=()=>{shortcodes.clear()},setShortcodes=args=>{if(!isObjectStrict(args))return!1;const names=Object.entries(args);return!!names.length&&(resetShortcodes(),names.forEach((([name,shortcode])=>{addShortcode(name,shortcode)})),!0)},stripShortcodes=content=>{if(!shortcodes.size)return content;const names=[...shortcodes.keys()].join("|"),reg=new RegExp(String.raw`\[(?:\/)?(?<name>${names})(?:\s[^\]]*?)?\]`,"g");return content.replace(reg,(()=>""))};export{shortcodes,addShortcode,removeShortcode,doShortcodes,resetShortcodes,setShortcodes,stripShortcodes};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GenericStrings } from '../../global/globalTypes.js';
|
|
2
|
+
import type { RenderItem } from '../../render/renderTypes.js';
|
|
3
|
+
export type ShortcodeAttrValue = string | number | boolean | undefined;
|
|
4
|
+
export type ShortcodeAttrs = Record<string, ShortcodeAttrValue>;
|
|
5
|
+
export interface ShortcodeData {
|
|
6
|
+
name: string;
|
|
7
|
+
replaceContent: string;
|
|
8
|
+
content: string;
|
|
9
|
+
attributes: ShortcodeAttrs;
|
|
10
|
+
children: ShortcodeData[];
|
|
11
|
+
pageData?: RenderItem;
|
|
12
|
+
}
|
|
13
|
+
export type ShortcodeCallback = (args: ShortcodeData) => string | Promise<string>;
|
|
14
|
+
export interface Shortcode {
|
|
15
|
+
callback: ShortcodeCallback;
|
|
16
|
+
attributeTypes?: GenericStrings;
|
|
17
|
+
child?: string;
|
|
18
|
+
}
|
|
19
|
+
export type Shortcodes = Map<string, Shortcode>;
|
|
20
|
+
export type ShortcodesSet = Record<string, Shortcode>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -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,name:isStringStrict(tag.name)?tag.name:""},!0)})),tagInfo},tagExists=(item,id)=>null!=getTag(item,id);export{getTag,tagExists};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RenderItem } from '../../render/renderTypes.js';
|
|
2
|
+
export type TagGet = (item: RenderItem, id: string) => TagGetReturn | undefined;
|
|
3
|
+
export type TagExists = (item: RenderItem, id: string) => boolean;
|
|
4
|
+
export interface TagGetReturn {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
@@ -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, RenderItem } from '../render/renderTypes.js';
|
|
3
|
+
declare const getRoute: (type: string) => string;
|
|
4
|
+
declare const getWordPressData: (args: WordPressDataArgs, _page?: number) => Promise<RenderItem[]>;
|
|
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"../utils/filter/filter.js";import{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,meta:meta,fetcher:fetcher=fetch,options:options}=args;if(!isStringStrict(key))throw new Error("No key");const hasMeta=isObjectStrict(meta);if(config.env.cache){const cacheDataFilterArgs={key:key,type:"get"},cacheData=await applyFilters("cacheData",void 0,cacheDataFilterArgs,!0),cacheItems=cacheData?.items,cacheMeta=cacheData?.meta;if(isObjectStrict(cacheMeta)&&hasMeta){const{total:total,totalPages:totalPages}=cacheMeta;meta.total=total,meta.totalPages=totalPages}if(isArray(cacheItems))return structuredClone(cacheItems)}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):1,totalPagesNum=isStringStrict(totalPages)?parseInt(totalPages,10):1;hasMeta&&(meta.total=totalNum,meta.totalPages=totalPagesNum);const dataItems=isArray(data)?data:[data];let newData=normalizeWordPressData(dataItems,route);if(loop&&_page<totalPagesNum){const pagData=await getWordPressData({key:key,route:route,meta:meta,params:{per_page:-1}},_page+1);isArray(pagData)&&(newData=[...newData,...pagData])}if(config.env.cache){const cacheDataFilterArgs={key:key,type:"set",data:data};await applyFilters("cacheData",{items:newData,meta:meta},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];isObjectStrict(item)&&(id=isStringStrict(item.id)?item.id:"",contentType=isStringStrict(item.contentType)?item.contentType:"")}if(isPreview&&(id=previewData.id,contentType=previewData.contentType),id){const key=`serverless_${id}_${contentType}`,data=await getWordPressData({key:key,route:`${getRoute(contentType)}/${id}`});isArray(data)&&(allData.content[contentType]=data)}}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}`;let data=await getWordPressData({key:key,route:getRoute(contentType),params:{per_page:-1}});isMenuItem&&(data=normalizeWordPressMenuItems(data)),isMenu&&(data=normalizeWordPressMenus(data)),data=applyFilters("wordpressData",data,{...wordpressDataFilterArgs,contentType:contentType}),isArray(data)&&(allData[partialType]=data)}}if(!isServerless&&!isPreview){const whole=config.wholeTypes;for(const contentType of whole){allData.content[contentType]=[];const key=`all_${contentType}`;let data=await getWordPressData({key:key,route:getRoute(contentType),params:{per_page:-1}});data=applyFilters("wordpressData",data,{...wordpressDataFilterArgs,contentType:contentType}),isArray(data)&&(allData.content[contentType]=data)}}return allData=applyFilters("allData",allData,{type:"wordpress",serverlessData:serverlessData,previewData:previewData}),allData};export{getRoute,getWordPressData,getAllWordPressData};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WordPressDataItem, WordPressDataMenuItem, WordPressDataMenu } from './wordpressDataTypes.js';
|
|
2
|
+
import type { RenderItem } from '../render/renderTypes.js';
|
|
3
|
+
import type { NavigationList, NavigationItem } from '../components/Navigation/NavigationTypes.js';
|
|
4
|
+
declare const normalRoutes: Map<string, string>;
|
|
5
|
+
declare const normalMetaKeys: Map<string, string>;
|
|
6
|
+
declare const normalizeWordPressMenuItems: (items: WordPressDataMenuItem[]) => NavigationItem[];
|
|
7
|
+
declare const normalizeWordPressMenus: (menus: WordPressDataMenu[]) => NavigationList[];
|
|
8
|
+
declare const normalizeWordPressData: (data: WordPressDataItem[], route?: string, _newData?: RenderItem[]) => RenderItem[];
|
|
9
|
+
export { normalizeWordPressData, normalizeWordPressMenuItems, normalizeWordPressMenus, normalRoutes, normalMetaKeys };
|