From af0866ebb7dde4e6da83f873c9f38cf984f9f826 Mon Sep 17 00:00:00 2001 From: Sabrina Ferguson Date: Wed, 10 Apr 2024 17:05:08 -0400 Subject: [PATCH] feat: create parser for zksync info --- content/_zksync.json | 18 ++++++++++++++++++ server/plugins/parse-zk-tags.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 content/_zksync.json create mode 100644 server/plugins/parse-zk-tags.ts diff --git a/content/_zksync.json b/content/_zksync.json new file mode 100644 index 00000000..9c99d35e --- /dev/null +++ b/content/_zksync.json @@ -0,0 +1,18 @@ +{ + "mainnet": { + "name": "zkSync Era Mainnet", + "rpc_url": "https://mainnet.era.zksync.io", + "websocket_url": "wss://mainnet.era.zksync.io/ws", + "chain_id": 324, + "currency_symbol": "ETH", + "block_explorer_url": "https://explorer.zksync.io/" + }, + "testnet": { + "name": "zkSync Era Testnet", + "rpc_url": "https://testnet.era.zksync.dev", + "websocket_url": "wss://testnet.era.zksync.dev/ws", + "chain_id": 280, + "currency_symbol": "ETH", + "block_explorer_url": "https://sepolia.explorer.zksync.io/" + } +} diff --git a/server/plugins/parse-zk-tags.ts b/server/plugins/parse-zk-tags.ts new file mode 100644 index 00000000..c5f39638 --- /dev/null +++ b/server/plugins/parse-zk-tags.ts @@ -0,0 +1,29 @@ +import zkSyncConfig from '../../content/_zksync.json'; + +const tags: { [key: string]: string } = {}; + +export default defineNitroPlugin((nitroApp) => { + parseConfig(zkSyncConfig, 'zk'); + + nitroApp.hooks.hook('content:file:beforeParse', (file: { _id: string; body: string }) => { + if (file._id.endsWith('.md')) { + Object.keys(tags).forEach((key) => { + file.body = file.body.replace(new RegExp(`%%${key}%%`, 'g'), tags[key]); + }); + } + }); +}); + +function parseConfig(config: any, prefix: string) { + Object.keys(config).forEach((key) => { + const value = config[key]; + const newPrefix = `${prefix}_${key}`; + if (typeof value === 'object' && value !== null) { + parseConfig(value, newPrefix); + } else { + tags[newPrefix] = value; + } + }); + + return tags; +}