Skip to content

Commit

Permalink
Add additional optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandapip1 committed May 15, 2023
1 parent 00e7916 commit 67a6a88
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions .vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const logger = createLogger('info', true);

logger.info('Fetching EIPs', { timestamp: true });
const eips = await fetchEips();
const eipsSpread = {};
for (let eip of eips) {
eipsSpread[eip.eip] = eip;
}
logger.info('Fetched EIPs', { timestamp: true });

async function copyDirectory(from, to) {
Expand Down Expand Up @@ -83,8 +87,11 @@ export default withPwa(defineConfig({
if (pageData.relativePath.match(/EIPS\/eip-\w+\.md/)) {
logger.info(`Generating Metadata for ${pageData.relativePath}`);

let eipN = filenameToEipNumber(pageData.relativePath.split('/')[1]);
let frontmatter = eips.find(eip => eip.eip === eipN);
let eipN = await filenameToEipNumber(pageData.relativePath.split('/')[1]);
if (!eipN) {
throw new Error(`EIP ${pageData.relativePath} not found`);
}
let frontmatter = eipsSpread[eipN];
if (!frontmatter) {
throw new Error(`EIP ${eipN} not found`);
}
Expand Down Expand Up @@ -148,13 +155,18 @@ export default withPwa(defineConfig({

if (pageData.relativePath.match(/EIPS\/eip-\w+\.md/)) {
pageData = { ...pageData };
let eipN = filenameToEipNumber(pageData.relativePath.split('/')[1]);
pageData.frontmatter = eips.find(eip => eip.eip === eipN);

if (!pageData.frontmatter) {

let eipN = await filenameToEipNumber(pageData.relativePath.split('/')[1]);
if (!eipN) {
throw new Error(`EIP ${pageData.relativePath} not found`);
}
let frontmatter = eipsSpread[eipN];
if (!frontmatter) {
throw new Error(`EIP ${eipN} not found`);
}

pageData.frontmatter = frontmatter;

logger.info(`Transformed ${pageData.relativePath} (EIP)`, { timestamp: true });
return pageData;
} else if (pageData.frontmatter.listing) {
Expand Down

0 comments on commit 67a6a88

Please sign in to comment.