@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,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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parse}from"@wordpress/block-serialization-default-parser";import{normalizeContentType}from"../utils/contentType/contentType.js";import{getObjectKeys}from"../utils/object/objectUtils.js";import{getStoreItem,setStoreItem}from"../store/store.js";import{isString,isStringStrict}from"../utils/string/string.js";import{isArrayStrict}from"../utils/array/array.js";import{isObjectStrict}from"../utils/object/object.js";import{isNumber}from"../utils/number/number.js";import{config}from"../config/config.js";const normalRoutes=new Map([["page","pages"],["post","posts"],["taxonomy","taxonomies"],["category","categories"],["tag","tags"],["attachment","media"],["nav_menu","menus"],["nav_menu_item","menu-items"]]),normalMetaKeys=new Map,menusById=new Map,excludeProps=["_links","auto_add"],getTaxonomy=id=>{const taxonomy=getStoreItem("taxonomies")[id],{title:title="",slug:slug="",contentTypes:contentTypes=[]}=isObjectStrict(taxonomy)?taxonomy:{};return{id:id,title:title,slug:slug,contentTypes:contentTypes}},normalizeFile=file=>{const{url:url,filename:filename,alt:alt,width:width,height:height,filesizeInBytes:filesizeInBytes,subtype:subtype,mime:mime,sizes:sizes}=file;let newSizes;if(isObjectStrict(sizes)){newSizes={};for(const[,value]of Object.entries(sizes)){const{width:width,source_url:src}=value;let{url:url}=value;isStringStrict(src)&&(url=src),isNumber(width)&&isStringStrict(url)&&(newSizes[width]=url)}}return{url:isString(url)?url:"",name:isString(filename)?filename:"",alt:isString(alt)?alt:"",width:isNumber(width)?width:0,height:isNumber(height)?height:0,size:isNumber(filesizeInBytes)?filesizeInBytes:0,format:"jpeg"===subtype?"jpg":subtype,type:mime,sizes:newSizes}},normalizeEmbedded=(value,item,newItem)=>{getObjectKeys(value).forEach(k=>{const embeds=value[k];if(isArrayStrict(embeds)){if("author"===k){const exclude=[...excludeProps,"id","avatar_urls"];embeds.forEach(embed=>{if(!isObjectStrict(embed))return;const{id:id}=embed;if(item.author!==id)return;const newAuthor={id:id.toString()};Object.entries(embed).forEach(([key,val])=>{exclude.includes(key)||(newAuthor[key]=val)}),newItem.author=newAuthor})}if("up"===k&&embeds.forEach(embed=>{if(!isObjectStrict(embed))return;const{id:id,title:parentTitle,name:name,type:type,taxonomy:taxonomy,slug:slug}=embed;if(item.parent!==id)return;let title="";isString(parentTitle?.rendered)&&(title=parentTitle.rendered),isString(name)&&(title=name),newItem.parent={id:id.toString(),contentType:isString(taxonomy)?"term":type,title:title,slug:slug}}),"wp:featuredmedia"===k&&embeds.forEach(embed=>{if(!isObjectStrict(embed))return;const{id:id,source_url:url,media_details:details,mime_type:mimeType,alt_text:alt}=embed;if(!isObjectStrict(details))return;const{file:file,filesize:filesize,width:width,height:height,sizes:sizes}=details;item.featured_media===id&&(newItem.featured_media=normalizeFile({url:url,filename:file?.split("/").pop(),alt:alt,width:width,height:height,filesizeInBytes:filesize,subtype:mimeType?.split("/").pop(),mime:mimeType,sizes:sizes}))}),"wp:term"===k){const exclude=[...excludeProps,"id","name","taxonomy"];embeds.forEach(embed=>{isArrayStrict(embed)&&embed.forEach(e=>{if(!isObjectStrict(e))return;const{id:id,name:name,taxonomy:taxonomy=""}=e;let taxonomyLookup=taxonomy;"category"===taxonomy&&(taxonomyLookup="categories"),"post_tag"===taxonomy&&(taxonomyLookup="tags");const itemTaxonomy=newItem[taxonomyLookup]??item[taxonomyLookup];isArrayStrict(itemTaxonomy)&&(newItem[taxonomyLookup]=itemTaxonomy.map(taxonomyId=>{if(taxonomyId!==id)return taxonomyId;const newTerm={id:id.toString(),title:name,contentType:"term",taxonomy:getTaxonomy(taxonomy)};return Object.entries(e).forEach(([key,val])=>{exclude.includes(key)||(newTerm[key]=val)}),newTerm}))})})}}})},normalizeBlocks=blocks=>{const newItems=[];return blocks.forEach(block=>{const{blockName:blockName,attrs:attrs,innerBlocks:innerBlocks}=block,contentType=blockName;if(!isStringStrict(contentType))return;const{isItem:isItem}=attrs,attrItemArr=(isStringStrict(isItem)?isItem:"").split(","),attrItemExists=attrItemArr.length;for(const[key,value]of Object.entries(attrs))if(isObjectStrict(value)){if(attrItemExists&&attrItemArr.includes(key)){const itemValue=normalizeItem(value);itemValue.content=void 0,attrs[key]=itemValue}isStringStrict(value.mime)&&(attrs[key]=normalizeFile(value))}const newItem={contentType:contentType,...attrs},renderType=config.renderTypes[contentType];return isString(renderType)&&(newItem.renderType=renderType),isArrayStrict(innerBlocks)&&(newItem.content=normalizeBlocks(innerBlocks)),newItems.push(newItem)}),newItems},normalizeItem=item=>{const newItem={};for(const[key,value]of Object.entries(item)){if(excludeProps.includes(key))continue;let val=value,k=key;const isObj=isObjectStrict(value),isStr=isStringStrict(value);if("id"!==key&&"object_id"!==k||(val=value?.toString()),"type"===key&&isStr)newItem.contentType=normalizeContentType(value),isString(config.renderTypes[value])&&(newItem.renderType=config.renderTypes[value]);else{if("types"===key&&(k="contentTypes"),isObj){const{rendered:rendered}=value;isString(rendered)&&(val=rendered)}if("name"===key&&(k="title"),"_embedded"===key&&isObj)normalizeEmbedded(value,item,newItem);else{if(isStringStrict(val)){if("excerpt"===key&&(val=val.replace(/<[^>]*>|\[.*?\]/g,"").trim()),"content"===key){const normalVal=normalizeBlocks(parse(val));val=normalVal.length?normalVal:val}"taxonomy"===key&&(newItem.contentType="term",val=getTaxonomy(val))}if("meta"===key&&isObj)for(const[metaKey,metaValue]of Object.entries(val)){newItem[normalMetaKeys.get(metaKey)??metaKey]=metaValue}else{if("media_details"===k&&isObj){const valObj=val,valFull=valObj.sizes?.full,sourceUrl=item.source_url,mimeType=item.mime_type;val=normalizeFile({url:sourceUrl,filename:sourceUrl?.split("/").pop(),alt:item.alt_text,width:valFull?.width,height:valFull?.height,filesizeInBytes:valObj.filesize,subtype:mimeType?.split("/")[1],mime:mimeType,sizes:valObj.sizes})}newItem[k]=val}}}}return newItem},normalizeWordPressMenuItems=items=>{const itemsObj=Object.fromEntries(items.map(item=>[item.id,item]));menusById.clear(),items.forEach(item=>{const{id:id="",title:title="",menu_order:menu_order=0,menus:menus=0}=item,parent=item.parent,hasMenuOrder=isNumber(menu_order);if(hasMenuOrder&&isObjectStrict(itemsObj[parent])&&(null==itemsObj[parent].children&&(itemsObj[parent].children=[]),itemsObj[parent].children.push({id:id,menu_order:menu_order,title:title})),hasMenuOrder&&isNumber(menus)&&0===parent){const menuId=menus.toString();null==menusById.get(menuId)&&menusById.set(menuId,[]),menusById.get(menuId)?.push({id:id,menu_order:menu_order,title:title})}});const newItems=[];for(const[id,obj]of Object.entries(itemsObj)){const{url:url="",title:title="",contentType:contentType="",children:children=[],object:object="",object_id:object_id="",locale:locale=""}=obj;if(!isString(url)||!isStringStrict(title))continue;const newItem={id:id,title:title},isCustom="custom"===contentType;if(!isCustom&&isStringStrict(object)&&isStringStrict(object_id)){const isTerm="taxonomy"===contentType,internalLink={contentType:isTerm?"term":object,id:object_id,slug:url.split("/").filter(Boolean).pop()};isTerm&&(internalLink.taxonomy=getTaxonomy(object)),isStringStrict(locale)&&(internalLink.locale=locale),newItem.link=url,newItem.internalLink=internalLink}if(isCustom){url.startsWith("http")&&!url.startsWith(config.env.prodUrl)?newItem.externalLink=url:newItem.link=url}isArrayStrict(children)&&(newItem.children=children.sort((a,b)=>a.menu_order-b.menu_order));const exclude=[...excludeProps,"url","type","type_label","object","object_id","invalid","meta","menu_order","menus","parent","contentType","status"];Object.entries(obj).forEach(([key,val])=>{exclude.includes(key)||(newItem[key]=val)}),newItems.push(newItem)}return newItems},normalizeWordPressMenus=menus=>{const newMenus=[];return menus.forEach(menu=>{const{id:id="",title:title="",description:description="",locations:locations=[],meta:meta=[]}=menu,newMenu={id:id,title:title,description:description,meta:meta,location:locations,items:menusById.get(id)?.sort((a,b)=>a.menu_order-b.menu_order)??[]};newMenus.push(newMenu)}),newMenus},normalizeWordPressData=(data,route,_newData=[])=>isArrayStrict(data)?("taxonomies"===route&&(data=Object.entries(data[0]).map(([key,value])=>({id:key,type:"taxonomy",...value}))),data.forEach(item=>{isObjectStrict(item)&&_newData.push(normalizeItem(item))}),"taxonomies"===route&&_newData.forEach(item=>{setStoreItem("taxonomies",item,item.id)}),_newData):[];export{normalizeWordPressData,normalizeWordPressMenuItems,normalizeWordPressMenus,normalRoutes,normalMetaKeys};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import type { Generic, GenericStrings } from '../global/globalTypes.js';
|
|
2
|
+
import type { NavigationItem } from '../components/Navigation/NavigationTypes.js';
|
|
3
|
+
import type { RenderServerlessData, RenderPreviewData, RenderItem } from '../render/renderTypes.js';
|
|
4
|
+
export type WordPressDataParams = Record<string, string | number | boolean>;
|
|
5
|
+
interface WordPressDataErrorData {
|
|
6
|
+
status?: number;
|
|
7
|
+
params?: GenericStrings;
|
|
8
|
+
details?: Generic;
|
|
9
|
+
}
|
|
10
|
+
export interface WordPressDataError {
|
|
11
|
+
code?: string;
|
|
12
|
+
message?: string;
|
|
13
|
+
data?: WordPressDataErrorData;
|
|
14
|
+
}
|
|
15
|
+
export type WordPressDataStatus = 'publish' | 'draft' | 'future' | 'pending' | 'private' | 'trash' | 'auto-draft' | 'inherit';
|
|
16
|
+
export interface WordPressDataRendered {
|
|
17
|
+
rendered?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface WordPressDataRenderedProtected {
|
|
20
|
+
rendered?: string;
|
|
21
|
+
protected?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface WordPressDataMenuChild extends NavigationItem {
|
|
24
|
+
menu_order: number;
|
|
25
|
+
}
|
|
26
|
+
export interface WordPressDataMenuItem extends RenderItem {
|
|
27
|
+
children?: WordPressDataMenuChild[];
|
|
28
|
+
}
|
|
29
|
+
export interface WordPressDataMenu extends RenderItem {
|
|
30
|
+
name?: string;
|
|
31
|
+
locations?: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface WordPressDataAuthor {
|
|
34
|
+
id: number;
|
|
35
|
+
name?: string;
|
|
36
|
+
url?: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
link?: string;
|
|
39
|
+
slug?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface WordPressDataMediaDetails {
|
|
42
|
+
width?: number;
|
|
43
|
+
height?: number;
|
|
44
|
+
filesize?: number;
|
|
45
|
+
file?: string;
|
|
46
|
+
sizes?: Record<string, WordPressDataMediaSize>;
|
|
47
|
+
}
|
|
48
|
+
export interface WordPressDataMediaSize {
|
|
49
|
+
source_url?: string;
|
|
50
|
+
mime_type?: string;
|
|
51
|
+
file?: string;
|
|
52
|
+
filesize?: number;
|
|
53
|
+
width?: number;
|
|
54
|
+
height?: number;
|
|
55
|
+
}
|
|
56
|
+
export interface WordPressDataFeaturedMedia {
|
|
57
|
+
id: number;
|
|
58
|
+
source_url?: string;
|
|
59
|
+
alt_text?: string;
|
|
60
|
+
caption?: WordPressDataRendered;
|
|
61
|
+
media_type?: string;
|
|
62
|
+
mime_type?: string;
|
|
63
|
+
media_details?: WordPressDataMediaDetails;
|
|
64
|
+
}
|
|
65
|
+
export interface WordPressDataTerm {
|
|
66
|
+
id: number;
|
|
67
|
+
link?: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
slug?: string;
|
|
70
|
+
taxonomy?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface WordPressDataAttachment {
|
|
73
|
+
id: number;
|
|
74
|
+
source_url?: string;
|
|
75
|
+
title?: WordPressDataRendered;
|
|
76
|
+
media_type?: string;
|
|
77
|
+
mime_type?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface WordPressDataParent {
|
|
80
|
+
id: number;
|
|
81
|
+
title?: WordPressDataRendered;
|
|
82
|
+
excerpt?: WordPressDataRendered;
|
|
83
|
+
slug?: string;
|
|
84
|
+
type?: string;
|
|
85
|
+
link?: string;
|
|
86
|
+
author?: number;
|
|
87
|
+
featured_media?: number;
|
|
88
|
+
name?: string;
|
|
89
|
+
taxonomy?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface WordPressDataEmbedded {
|
|
92
|
+
author?: WordPressDataAuthor[];
|
|
93
|
+
up?: WordPressDataParent[];
|
|
94
|
+
'wp:featuredmedia'?: WordPressDataFeaturedMedia[];
|
|
95
|
+
'wp:attachment'?: WordPressDataAttachment[];
|
|
96
|
+
'wp:term'?: WordPressDataTerm[][];
|
|
97
|
+
}
|
|
98
|
+
export interface WordPressDataLink {
|
|
99
|
+
href: string;
|
|
100
|
+
name?: string;
|
|
101
|
+
templated?: boolean;
|
|
102
|
+
count?: number;
|
|
103
|
+
taxonomy?: string;
|
|
104
|
+
embeddable?: boolean;
|
|
105
|
+
}
|
|
106
|
+
export interface WordPressDataLinks {
|
|
107
|
+
self: WordPressDataLink[];
|
|
108
|
+
collection: WordPressDataLink[];
|
|
109
|
+
about: WordPressDataLink[];
|
|
110
|
+
'version-history': WordPressDataLink[];
|
|
111
|
+
'wp:attachment': WordPressDataLink[];
|
|
112
|
+
'wp:term': WordPressDataLink[];
|
|
113
|
+
curies: WordPressDataLink[];
|
|
114
|
+
}
|
|
115
|
+
export interface WordPressDataFileSize {
|
|
116
|
+
height?: number;
|
|
117
|
+
width?: number;
|
|
118
|
+
url?: string;
|
|
119
|
+
source_url?: string;
|
|
120
|
+
orientation?: string;
|
|
121
|
+
}
|
|
122
|
+
interface WordPressDataFileNonces {
|
|
123
|
+
update: string;
|
|
124
|
+
delete: string;
|
|
125
|
+
edit: string;
|
|
126
|
+
}
|
|
127
|
+
export interface WordPressDataFile {
|
|
128
|
+
contentType?: string;
|
|
129
|
+
id?: number;
|
|
130
|
+
title?: string;
|
|
131
|
+
filename?: string;
|
|
132
|
+
url?: string;
|
|
133
|
+
link?: string;
|
|
134
|
+
alt?: string;
|
|
135
|
+
author?: string;
|
|
136
|
+
description?: string;
|
|
137
|
+
caption?: string;
|
|
138
|
+
name?: string;
|
|
139
|
+
status?: string;
|
|
140
|
+
uploadedTo?: number;
|
|
141
|
+
date?: string;
|
|
142
|
+
modified?: string;
|
|
143
|
+
menuOrder?: number;
|
|
144
|
+
mime?: string;
|
|
145
|
+
type?: string;
|
|
146
|
+
subtype?: string;
|
|
147
|
+
icon?: string;
|
|
148
|
+
dateFormatted?: string;
|
|
149
|
+
nonces?: WordPressDataFileNonces;
|
|
150
|
+
editLink?: string;
|
|
151
|
+
meta?: boolean;
|
|
152
|
+
authorName?: string;
|
|
153
|
+
authorLink?: string;
|
|
154
|
+
filesizeInBytes?: number;
|
|
155
|
+
filesizeHumanReadable?: string;
|
|
156
|
+
context?: string;
|
|
157
|
+
height?: number;
|
|
158
|
+
width?: number;
|
|
159
|
+
orientation?: string;
|
|
160
|
+
sizes?: Record<string, WordPressDataFileSize>;
|
|
161
|
+
}
|
|
162
|
+
export interface WordPressDataMeta extends Generic {
|
|
163
|
+
footnotes?: string;
|
|
164
|
+
}
|
|
165
|
+
export interface WordPressDataItem extends Partial<WordPressDataFeaturedMedia>, Generic {
|
|
166
|
+
id?: number;
|
|
167
|
+
date?: string;
|
|
168
|
+
date_gmt?: string;
|
|
169
|
+
guid?: WordPressDataRendered;
|
|
170
|
+
modified?: string;
|
|
171
|
+
modified_gmt?: string;
|
|
172
|
+
slug?: string;
|
|
173
|
+
status?: WordPressDataStatus;
|
|
174
|
+
type?: string;
|
|
175
|
+
link?: string;
|
|
176
|
+
title?: WordPressDataRendered;
|
|
177
|
+
content?: WordPressDataRenderedProtected;
|
|
178
|
+
excerpt?: WordPressDataRenderedProtected;
|
|
179
|
+
author?: number;
|
|
180
|
+
featured_media?: number;
|
|
181
|
+
parent?: number;
|
|
182
|
+
menu_order?: number;
|
|
183
|
+
comment_status?: string;
|
|
184
|
+
ping_status?: string;
|
|
185
|
+
sticky?: boolean;
|
|
186
|
+
template?: string;
|
|
187
|
+
format?: string;
|
|
188
|
+
meta?: WordPressDataMeta;
|
|
189
|
+
categories?: number[];
|
|
190
|
+
tags?: number[];
|
|
191
|
+
class_list?: string[];
|
|
192
|
+
taxonomy?: string;
|
|
193
|
+
name?: string;
|
|
194
|
+
_links?: WordPressDataLinks;
|
|
195
|
+
_embedded?: WordPressDataEmbedded;
|
|
196
|
+
}
|
|
197
|
+
export interface WordPressDataArgs {
|
|
198
|
+
key: string;
|
|
199
|
+
route: string;
|
|
200
|
+
params?: WordPressDataParams;
|
|
201
|
+
fetcher?: typeof fetch;
|
|
202
|
+
options?: RequestInit;
|
|
203
|
+
}
|
|
204
|
+
export interface AllWordPressDataArgs {
|
|
205
|
+
serverlessData?: RenderServerlessData;
|
|
206
|
+
previewData?: RenderPreviewData;
|
|
207
|
+
}
|
|
208
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alanizcreative/formation-static",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Minimal static-site HTML renderer from JSON, Contentful, or WordPress data",
|
|
5
|
+
"main": "./lib/config/config.js",
|
|
6
|
+
"packageManager": "pnpm@10.23.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"./lib",
|
|
10
|
+
"./cjs"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
"./*": {
|
|
14
|
+
"import": "./lib/*",
|
|
15
|
+
"require": "./cjs/*"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build:lib": "npx tsc --project tsconfig.build.json",
|
|
23
|
+
"build:cjs": "npx tsc --project tsconfig.build.json --moduleResolution node --module commonjs --esModuleInterop --outDir cjs/",
|
|
24
|
+
"build": "pnpm build:lib && pnpm build:cjs && node scripts/packageFile.js && pnpm minify",
|
|
25
|
+
"minify": "find lib cjs -name \"*.js\" -exec terser {} -o {} --compress \\;",
|
|
26
|
+
"test": "vitest --run --reporter verbose --coverage",
|
|
27
|
+
"lint": "npx eslint .",
|
|
28
|
+
"release": "release-it"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"static-site",
|
|
32
|
+
"renderer",
|
|
33
|
+
"html",
|
|
34
|
+
"nodejs"
|
|
35
|
+
],
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/galaniz/formation-static.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/galaniz/formation-static/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/galaniz/formation-static#readme",
|
|
44
|
+
"author": "Graciela Alaniz (https://alanizcreative.com/)",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/contentful-resolve-response": "^0.1.33",
|
|
48
|
+
"@types/node": "^24.10.1",
|
|
49
|
+
"@vitest/coverage-v8": "^4.0.13",
|
|
50
|
+
"eslint": "9.39.1",
|
|
51
|
+
"memfs": "4.51.0",
|
|
52
|
+
"release-it": "^19.0.6",
|
|
53
|
+
"terser": "5.44.1",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
|
+
"typescript-eslint": "8.47.0",
|
|
56
|
+
"vitest": "^4.0.13"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"uuid": "^13.0.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@wordpress/block-serialization-default-parser": "^5.25.0",
|
|
63
|
+
"contentful-resolve-response": "^1.9.3",
|
|
64
|
+
"sharp": "0.34.2"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"@wordpress/block-serialization-default-parser": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"contentful-resolve-response": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"sharp": {
|
|
74
|
+
"optional": true
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"release-it": {
|
|
78
|
+
"git": {
|
|
79
|
+
"requireCommits": true,
|
|
80
|
+
"commitMessage": "chore: release ${version} [ci skip]",
|
|
81
|
+
"tag": true,
|
|
82
|
+
"push": true
|
|
83
|
+
},
|
|
84
|
+
"github": {
|
|
85
|
+
"release": true
|
|
86
|
+
},
|
|
87
|
+
"npm": {
|
|
88
|
+
"publish": true,
|
|
89
|
+
"skipChecks": true
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"publishConfig": {
|
|
93
|
+
"access": "public",
|
|
94
|
+
"provenance": true
|
|
95
|
+
}
|
|
96
|
+
}
|