Next13 + updated deps + fixed revalidation
This commit is contained in:
		
							parent
							
								
									35b58982d0
								
							
						
					
					
						commit
						c356679813
					
				
							
								
								
									
										1000
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1000
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										32
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								package.json
									
									
									
									
									
								
							| @ -5,7 +5,7 @@ | ||||
|     "dev": "next dev -p 12499", | ||||
|     "precommit": "npm run fetch-local-data && npm run prettier && npm run unused-exports && npm run eslint && npm run tsc && echo ALL PRECOMMIT CHECKS PASSED SUCCESSFULLY, LET\\'S FUCKING GO!", | ||||
|     "unused-exports": "ts-unused-exports ./tsconfig.json --excludePathsFromReport=src/pages --ignoreFiles=generated", | ||||
|     "fetch-local-data": "npm run generate && esrun src/graphql/fetchLocalData.ts", | ||||
|     "fetch-local-data": "npm run generate && esrun src/graphql/fetchLocalData.ts --esrun", | ||||
|     "prebuild": "npm run fetch-local-data", | ||||
|     "build": "next build", | ||||
|     "postbuild": "next-sitemap --config next-sitemap.config.js", | ||||
| @ -27,11 +27,11 @@ | ||||
|     "autoprefixer": "^10.4.13", | ||||
|     "cuid": "^2.1.8", | ||||
|     "graphql-request": "^5.0.0", | ||||
|     "jotai": "^1.9.0", | ||||
|     "jotai": "^1.9.2", | ||||
|     "markdown-to-jsx": "^7.1.7", | ||||
|     "next": "^12.3.1", | ||||
|     "next": "^13.0.3", | ||||
|     "nodemailer": "^6.8.0", | ||||
|     "rc-slider": "^10.0.1", | ||||
|     "rc-slider": "^10.1.0", | ||||
|     "react": "18.2.0", | ||||
|     "react-dom": "18.2.0", | ||||
|     "react-hotkeys-hook": "^3.4.7", | ||||
| @ -46,29 +46,29 @@ | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@digitak/esrun": "^3.2.14", | ||||
|     "@graphql-codegen/cli": "^2.13.8", | ||||
|     "@graphql-codegen/typescript": "2.8.0", | ||||
|     "@graphql-codegen/typescript-graphql-request": "^4.5.7", | ||||
|     "@graphql-codegen/typescript-operations": "^2.5.5", | ||||
|     "@types/node": "18.11.7", | ||||
|     "@graphql-codegen/cli": "^2.13.11", | ||||
|     "@graphql-codegen/typescript": "2.8.1", | ||||
|     "@graphql-codegen/typescript-graphql-request": "^4.5.8", | ||||
|     "@graphql-codegen/typescript-operations": "^2.5.6", | ||||
|     "@types/node": "18.11.9", | ||||
|     "@types/nodemailer": "^6.4.6", | ||||
|     "@types/react": "18.0.22", | ||||
|     "@types/react": "^18.0.22", | ||||
|     "@types/react-dom": "^18.0.8", | ||||
|     "@types/string-natural-compare": "^3.0.2", | ||||
|     "@types/throttle-debounce": "^5.0.0", | ||||
|     "@types/turndown": "^5.0.1", | ||||
|     "@types/ua-parser-js": "^0.7.36", | ||||
|     "@typescript-eslint/eslint-plugin": "^5.41.0", | ||||
|     "@typescript-eslint/parser": "^5.41.0", | ||||
|     "@typescript-eslint/eslint-plugin": "^5.42.1", | ||||
|     "@typescript-eslint/parser": "^5.42.1", | ||||
|     "dotenv": "^16.0.3", | ||||
|     "eslint": "^8.26.0", | ||||
|     "eslint-config-next": "12.3.1", | ||||
|     "eslint": "^8.27.0", | ||||
|     "eslint-config-next": "13.0.3", | ||||
|     "eslint-plugin-import": "^2.26.0", | ||||
|     "graphql": "^16.6.0", | ||||
|     "next-sitemap": "^3.1.29", | ||||
|     "next-sitemap": "^3.1.30", | ||||
|     "prettier": "^2.7.1", | ||||
|     "prettier-plugin-tailwindcss": "^0.1.13", | ||||
|     "tailwindcss": "^3.2.1", | ||||
|     "tailwindcss": "^3.2.4", | ||||
|     "ts-unused-exports": "^8.0.0", | ||||
|     "typescript": "^4.8.4" | ||||
|   }, | ||||
|  | ||||
| @ -1 +1 @@ | ||||
| {"currencies":{"data":[{"id":"1","attributes":{"code":"EUR","symbol":"€","rate_to_usd":1.1062771,"display_decimals":true}},{"id":"2","attributes":{"code":"CAD","symbol":"$","rate_to_usd":0.79319156,"display_decimals":true}},{"id":"3","attributes":{"code":"USD","symbol":"$","rate_to_usd":1,"display_decimals":true}},{"id":"4","attributes":{"code":"JPY","symbol":"¥","rate_to_usd":0.0083864261,"display_decimals":false}},{"id":"5","attributes":{"code":"BRL","symbol":"R$","rate_to_usd":0.19904328,"display_decimals":true}},{"id":"6","attributes":{"code":"GBP","symbol":"£","rate_to_usd":1.3181323,"display_decimals":true}},{"id":"7","attributes":{"code":"AUD","symbol":"$","rate_to_usd":0.7422,"display_decimals":true}},{"id":"8","attributes":{"code":"INR","symbol":"₹","rate_to_usd":0.013162881,"display_decimals":false}},{"id":"9","attributes":{"code":"NZD","symbol":"$","rate_to_usd":0.69089984,"display_decimals":true}},{"id":"10","attributes":{"code":"CHF","symbol":"CHF","rate_to_usd":1.0728706,"display_decimals":true}}]}} | ||||
| {"currencies":{"data":[{"id":"1","attributes":{"code":"EUR","symbol":"€","rate_to_usd":1.036166,"display_decimals":true}},{"id":"2","attributes":{"code":"CAD","symbol":"$","rate_to_usd":0.79319156,"display_decimals":true}},{"id":"3","attributes":{"code":"USD","symbol":"$","rate_to_usd":1,"display_decimals":true}},{"id":"4","attributes":{"code":"JPY","symbol":"¥","rate_to_usd":0.0083864261,"display_decimals":false}},{"id":"5","attributes":{"code":"BRL","symbol":"R$","rate_to_usd":0.19904328,"display_decimals":true}},{"id":"6","attributes":{"code":"GBP","symbol":"£","rate_to_usd":1.3181323,"display_decimals":true}},{"id":"7","attributes":{"code":"AUD","symbol":"$","rate_to_usd":0.7422,"display_decimals":true}},{"id":"8","attributes":{"code":"INR","symbol":"₹","rate_to_usd":0.013162881,"display_decimals":false}},{"id":"9","attributes":{"code":"NZD","symbol":"$","rate_to_usd":0.69089984,"display_decimals":true}},{"id":"10","attributes":{"code":"CHF","symbol":"CHF","rate_to_usd":1.0728706,"display_decimals":true}}]}} | ||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @ -21,13 +21,16 @@ const readLocalData = <T>(name: LocalDataFile): T => { | ||||
|   return JSON.parse(readFileSync(path, { encoding: "utf8" })); | ||||
| }; | ||||
| 
 | ||||
| const sdk = getReadySdk(); | ||||
| 
 | ||||
| (async () => { | ||||
| export const fetchLocalData = async (): Promise<void> => { | ||||
|   const sdk = getReadySdk(); | ||||
|   writeLocalData("websiteInterfaces", await sdk.localDataGetWebsiteInterfaces()); | ||||
|   writeLocalData("currencies", await sdk.localDataGetCurrencies()); | ||||
|   writeLocalData("languages", await sdk.localDataGetLanguages()); | ||||
| })(); | ||||
| }; | ||||
| 
 | ||||
| if (process.argv[2] === "--esrun") { | ||||
|   fetchLocalData(); | ||||
| } | ||||
| 
 | ||||
| // ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
 | ||||
| 
 | ||||
|  | ||||
| @ -0,0 +1,22 @@ | ||||
| query revalidationGetRangedContent($id: ID) { | ||||
|   rangedContent(id: $id) { | ||||
|     data { | ||||
|       attributes { | ||||
|         content { | ||||
|           data { | ||||
|             attributes { | ||||
|               slug | ||||
|             } | ||||
|           } | ||||
|         } | ||||
|         library_item { | ||||
|           data { | ||||
|             attributes { | ||||
|               slug | ||||
|             } | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -1,6 +1,8 @@ | ||||
| import type { NextApiRequest, NextApiResponse } from "next"; | ||||
| import { i18n } from "../../../next.config"; | ||||
| import { cartesianProduct } from "helpers/others"; | ||||
| import { cartesianProduct, filterHasAttributes } from "helpers/others"; | ||||
| import { fetchLocalData } from "graphql/fetchLocalData"; | ||||
| import { getReadySdk } from "graphql/sdk"; | ||||
| 
 | ||||
| type CRUDEvents = "entry.create" | "entry.delete" | "entry.update"; | ||||
| 
 | ||||
| @ -10,6 +12,8 @@ type StrapiEvent = { | ||||
|   entry: Record<string, unknown>; | ||||
| }; | ||||
| 
 | ||||
| type StrapiRelationalField = { count: number }; | ||||
| 
 | ||||
| type RequestProps = | ||||
|   | CustomRequest | ||||
|   | StrapiChronicle | ||||
| @ -17,9 +21,12 @@ type RequestProps = | ||||
|   | StrapiChronology | ||||
|   | StrapiContent | ||||
|   | StrapiContentFolder | ||||
|   | StrapiCurrency | ||||
|   | StrapiLanguage | ||||
|   | StrapiLibraryItem | ||||
|   | StrapiPostContent | ||||
|   | StrapiRangedContent | ||||
|   | StrapiWebsiteInterface | ||||
|   | StrapiWiki; | ||||
| 
 | ||||
| interface CustomRequest { | ||||
| @ -31,12 +38,9 @@ interface StrapiRangedContent extends StrapiEvent { | ||||
|   event: CRUDEvents; | ||||
|   model: "ranged-content"; | ||||
|   entry: { | ||||
|     library_item?: { | ||||
|       slug: string; | ||||
|     }; | ||||
|     content?: { | ||||
|       slug: string; | ||||
|     }; | ||||
|     id: string; | ||||
|     library_item: StrapiRelationalField; | ||||
|     content: StrapiRelationalField; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| @ -44,12 +48,8 @@ interface StrapiContent extends StrapiEvent { | ||||
|   model: "content"; | ||||
|   entry: { | ||||
|     slug: string; | ||||
|     folder?: { | ||||
|       slug: string; | ||||
|     }; | ||||
|     ranged_contents: { | ||||
|       slug: string; | ||||
|     }[]; | ||||
|     folder: StrapiRelationalField; | ||||
|     ranged_contents: StrapiRelationalField; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| @ -61,16 +61,36 @@ interface StrapiPostContent extends StrapiEvent { | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| interface StrapiWebsiteInterface extends StrapiEvent { | ||||
|   event: CRUDEvents; | ||||
|   model: "website-interface"; | ||||
|   entry: { | ||||
|     slug: string; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| interface StrapiLanguage extends StrapiEvent { | ||||
|   event: CRUDEvents; | ||||
|   model: "language"; | ||||
|   entry: { | ||||
|     slug: string; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| interface StrapiCurrency extends StrapiEvent { | ||||
|   event: CRUDEvents; | ||||
|   model: "currency"; | ||||
|   entry: { | ||||
|     slug: string; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| interface StrapiLibraryItem extends StrapiEvent { | ||||
|   event: CRUDEvents; | ||||
|   model: "library-item"; | ||||
|   entry: { | ||||
|     slug: string; | ||||
|     subitem_of: [ | ||||
|       { | ||||
|         slug: string; | ||||
|       } | ||||
|     ]; | ||||
|     subitem_of: StrapiRelationalField; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| @ -79,13 +99,9 @@ interface StrapiContentFolder extends StrapiEvent { | ||||
|   model: "contents-folder"; | ||||
|   entry: { | ||||
|     slug: string; | ||||
|     parent_folder?: { | ||||
|       slug: string; | ||||
|     }; | ||||
|     subfolders: { slug: string }[]; | ||||
|     contents: { | ||||
|       slug: string; | ||||
|     }[]; | ||||
|     parent_folder: StrapiRelationalField; | ||||
|     subfolders: StrapiRelationalField; | ||||
|     contents: StrapiRelationalField; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| @ -118,13 +134,17 @@ interface StrapiChronicleChapter extends StrapiEvent { | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| type ResponseMailProps = { | ||||
| type ResponseProps = { | ||||
|   message: string; | ||||
|   revalidated: boolean; | ||||
| }; | ||||
| 
 | ||||
| const Revalidate = (req: NextApiRequest, res: NextApiResponse<ResponseMailProps>): void => { | ||||
| const Revalidate = async ( | ||||
|   req: NextApiRequest, | ||||
|   res: NextApiResponse<ResponseProps> | ||||
| ): Promise<void> => { | ||||
|   const body = req.body as RequestProps; | ||||
|   const sdk = getReadySdk(); | ||||
| 
 | ||||
|   // Check for secret to confirm this is a valid request
 | ||||
|   if (req.headers.authorization !== `Bearer ${process.env.REVALIDATION_TOKEN}`) { | ||||
| @ -134,6 +154,8 @@ const Revalidate = (req: NextApiRequest, res: NextApiResponse<ResponseMailProps> | ||||
| 
 | ||||
|   const paths: string[] = []; | ||||
| 
 | ||||
|   console.log(body); | ||||
| 
 | ||||
|   switch (body.model) { | ||||
|     case "post": { | ||||
|       paths.push(`/news`); | ||||
| @ -145,9 +167,17 @@ const Revalidate = (req: NextApiRequest, res: NextApiResponse<ResponseMailProps> | ||||
|       paths.push(`/library`); | ||||
|       paths.push(`/library/${body.entry.slug}`); | ||||
|       paths.push(`/library/${body.entry.slug}/reader`); | ||||
|       body.entry.subitem_of.forEach((parentItem) => { | ||||
|         paths.push(`/library/${parentItem.slug}`); | ||||
|       }); | ||||
| 
 | ||||
|       if (body.entry.subitem_of.count > 0) { | ||||
|         const libraryItem = await sdk.getLibraryItem({ | ||||
|           language_code: "en", | ||||
|           slug: body.entry.slug, | ||||
|         }); | ||||
|         filterHasAttributes(libraryItem.libraryItems?.data[0].attributes?.subitem_of?.data, [ | ||||
|           "attributes.slug", | ||||
|         ] as const).forEach((parentItem) => paths.push(`/library/${parentItem.attributes.slug}`)); | ||||
|       } | ||||
| 
 | ||||
|       break; | ||||
|     } | ||||
| 
 | ||||
| @ -155,15 +185,22 @@ const Revalidate = (req: NextApiRequest, res: NextApiResponse<ResponseMailProps> | ||||
|       paths.push(`/contents`); | ||||
|       paths.push(`/contents/all`); | ||||
|       paths.push(`/contents/${body.entry.slug}`); | ||||
|       if (body.entry.folder?.slug) { | ||||
|         paths.push(`/contents/folder/${body.entry.folder.slug}`); | ||||
|       } | ||||
|       if (body.entry.ranged_contents.length > 0) { | ||||
|         body.entry.ranged_contents.forEach((ranged_content) => { | ||||
|           const parentSlug = ranged_content.slug.slice( | ||||
|             0, | ||||
|             ranged_content.slug.length - body.entry.slug.length - 1 | ||||
|           ); | ||||
| 
 | ||||
|       if (body.entry.folder.count > 0 || body.entry.ranged_contents.count > 0) { | ||||
|         const content = await sdk.getContentText({ | ||||
|           language_code: "en", | ||||
|           slug: body.entry.slug, | ||||
|         }); | ||||
| 
 | ||||
|         const folderSlug = content.contents?.data[0].attributes?.folder?.data?.attributes?.slug; | ||||
|         if (folderSlug) { | ||||
|           paths.push(`/contents/folder/${folderSlug}`); | ||||
|         } | ||||
| 
 | ||||
|         filterHasAttributes(content.contents?.data[0].attributes?.ranged_contents?.data, [ | ||||
|           "attributes.library_item.data.attributes.slug", | ||||
|         ] as const).forEach((ranged_content) => { | ||||
|           const parentSlug = ranged_content.attributes.library_item.data.attributes.slug; | ||||
|           paths.push(`/library/${parentSlug}`); | ||||
|           paths.push(`/library/${parentSlug}/reader`); | ||||
|         }); | ||||
| @ -178,12 +215,21 @@ const Revalidate = (req: NextApiRequest, res: NextApiResponse<ResponseMailProps> | ||||
|     } | ||||
| 
 | ||||
|     case "ranged-content": { | ||||
|       if (body.entry.library_item) { | ||||
|         paths.push(`/library/${body.entry.library_item.slug}`); | ||||
|         paths.push(`/library/${body.entry.library_item.slug}/reader`); | ||||
|       } | ||||
|       if (body.entry.content) { | ||||
|         paths.push(`/contents/${body.entry.content.slug}`); | ||||
|       if (body.entry.content.count > 0 || body.entry.library_item.count > 0) { | ||||
|         const rangedContent = await sdk.revalidationGetRangedContent({ | ||||
|           id: body.entry.id, | ||||
|         }); | ||||
|         const libraryItemSlug = | ||||
|           rangedContent.rangedContent?.data?.attributes?.content?.data?.attributes?.slug; | ||||
|         if (libraryItemSlug) { | ||||
|           paths.push(`/library/${libraryItemSlug}`); | ||||
|           paths.push(`/library/${libraryItemSlug}/reader`); | ||||
|         } | ||||
|         const contentSlug = | ||||
|           rangedContent.rangedContent?.data?.attributes?.content?.data?.attributes?.slug; | ||||
|         if (contentSlug) { | ||||
|           paths.push(`/contents/${contentSlug}`); | ||||
|         } | ||||
|       } | ||||
|       break; | ||||
|     } | ||||
| @ -193,13 +239,30 @@ const Revalidate = (req: NextApiRequest, res: NextApiResponse<ResponseMailProps> | ||||
|         paths.push(`/contents`); | ||||
|       } | ||||
|       paths.push(`/contents/folder/${body.entry.slug}`); | ||||
|       if (body.entry.parent_folder) { | ||||
|         paths.push(`/contents/folder/${body.entry.parent_folder.slug}`); | ||||
| 
 | ||||
|       if ( | ||||
|         body.entry.contents.count > 0 || | ||||
|         body.entry.parent_folder.count > 0 || | ||||
|         body.entry.subfolders.count > 0 | ||||
|       ) { | ||||
|         const folder = await sdk.getContentsFolder({ | ||||
|           language_code: "en", | ||||
|           slug: body.entry.slug, | ||||
|         }); | ||||
|         const parentSlug = | ||||
|           folder.contentsFolders?.data[0].attributes?.parent_folder?.data?.attributes?.slug; | ||||
|         if (parentSlug) { | ||||
|           paths.push(`/contents/folder/${parentSlug}`); | ||||
|         } | ||||
|         filterHasAttributes(folder.contentsFolders?.data[0].attributes?.subfolders?.data, [ | ||||
|           "attributes.slug", | ||||
|         ] as const).forEach((subfolder) => | ||||
|           paths.push(`/contents/folder/${subfolder.attributes.slug}`) | ||||
|         ); | ||||
|         filterHasAttributes(folder.contentsFolders?.data[0].attributes?.contents?.data, [ | ||||
|           "attributes.slug", | ||||
|         ] as const).forEach((content) => paths.push(`/contents/${content.attributes.slug}`)); | ||||
|       } | ||||
|       body.entry.subfolders.forEach((subfolder) => | ||||
|         paths.push(`/contents/folder/${subfolder.slug}`) | ||||
|       ); | ||||
|       body.entry.contents.forEach((content) => paths.push(`/contents/${content.slug}`)); | ||||
|       break; | ||||
|     } | ||||
| 
 | ||||
| @ -223,20 +286,27 @@ const Revalidate = (req: NextApiRequest, res: NextApiResponse<ResponseMailProps> | ||||
|       break; | ||||
|     } | ||||
| 
 | ||||
|     case "website-interface": | ||||
|     case "language": | ||||
|     case "currency": { | ||||
|       await fetchLocalData(); | ||||
|       break; | ||||
|     } | ||||
| 
 | ||||
|     case "custom": { | ||||
|       paths.push(`${body.path}`); | ||||
|       break; | ||||
|     } | ||||
| 
 | ||||
|     default: | ||||
|       console.log(body); | ||||
|       console.log("Unknown case"); | ||||
|       break; | ||||
|   } | ||||
| 
 | ||||
|   console.table(paths); | ||||
|   const localizedPaths = cartesianProduct(i18n.locales, paths).map( | ||||
|     ([locale, path]) => `/${locale}${path}` | ||||
|   ); | ||||
|   console.table(localizedPaths); | ||||
| 
 | ||||
|   try { | ||||
|     Promise.all( | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 DrMint
						DrMint