Skip to content

Commit

Permalink
🚧 Stop for hackathon
Browse files Browse the repository at this point in the history
  • Loading branch information
roninjin10 committed Oct 18, 2024
1 parent 1a2b543 commit dd93c28
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 36 deletions.
197 changes: 177 additions & 20 deletions docs/astro.sidebar.config.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,179 @@
import starlightTypeDoc, { typeDocSidebarGroup } from 'starlight-typedoc';

export const sidebarConfig = [
{
label: 'Getting Started',
items: [{ label: 'Getting Started Guide', link: '/getting-started/getting-started/' }],
},
{
label: 'Learn',
items: [
{ label: 'Clients', link: '/learn/clients/' },
{ label: 'Actions', link: '/learn/actions/' },
{ label: 'Low-level API', link: '/learn/low-level-api/' },
{ label: 'JSON RPC', link: '/learn/json-rpc/' },
{ label: 'Contracts', link: '/learn/contracts/' },
{ label: 'Bundler', link: '/learn/solidity-imports/' },
{ label: 'Advanced Scripting', link: '/learn/scripting/' },
{ label: 'Reference', link: '/learn/reference/' },
],
},
typeDocSidebarGroug,
];
"label": "Learn",
"items": [
{
"label": "getting-started",
"link": "",
"items": [
{
"label": "Getting started guide",
"link": "/getting-started/getting-started/"
}
]
},
{
"label": "why",
"link": "",
"items": [
{
"label": "Slow waterfall calls",
"link": "/why/avoid-waterfalls/"
},
{
"label": "Advanced gas estimation",
"link": "/why/advanced-gas-estimation/"
},
{
"label": "Writing tests",
"link": "/why/writing-tests/"
},
{
"label": "Writing UI in solidity",
"link": "/why/write-ui-in-solidity/"
},
{
"label": "Optimistic UI",
"link": "/why/reuse-solidity/"
},
{
"label": "Why Tevm",
"link": "/why/"
},
{
"label": "Optimistic UI",
"link": "/why/optimistic-updates/"
}
]
},
{
"label": "learn",
"link": "",
"items": [
{
"label": "solidity-imports",
"link": "",
"items": [
{
"label": "Bundler Guide",
"link": "/learn/solidity-imports/"
}
]
},
{
"label": "reference",
"link": "",
"items": [
{
"label": "Tevm reference",
"link": "/learn/reference/"
}
]
},
{
"label": "actions",
"link": "",
"items": [
{
"label": "Actions",
"link": "/learn/actions/"
}
]
},
{
"label": "viem",
"link": "",
"items": [
{
"label": "Tevm clients guide",
"link": "/learn/viem/"
}
]
},
{
"label": "cli",
"link": "",
"items": [
{
"label": "Cli",
"link": "/learn/cli/"
}
]
},
{
"label": "json-rpc",
"link": "",
"items": [
{
"label": "JSON-RPC",
"link": "/learn/json-rpc/"
}
]
},
{
"label": "contracts",
"link": "",
"items": [
{
"label": "Contract action creators",
"link": "/learn/contracts/"
}
]
},
{
"label": "tevm-node",
"link": "",
"items": [
{
"label": "TevmNode api",
"link": "/learn/tevm-node/vm/"
},
{
"label": "TevmNode api",
"link": "/learn/tevm-node/installation/"
},
{
"label": "TevmNode api",
"link": "/learn/tevm-node/txpool/"
},
{
"label": "TevmNode api",
"link": "/learn/tevm-node/create-tevm-node/"
},
{
"label": "TevmNode api",
"link": "/learn/tevm-node/"
},
{
"label": "TevmNode api",
"link": "/learn/tevm-node/receipts-manager/"
},
{
"label": "TevmNode api",
"link": "/learn/tevm-node/filters/"
},
{
"label": "TevmNode api",
"link": "/learn/tevm-node/copying-or-forking/"
},
{
"label": "TevmNode api",
"link": "/learn/tevm-node/using-jsonrpc/"
}
]
},
{
"label": "scripting",
"link": "",
"items": [
{
"label": "Advanced scripting guide",
"link": "/learn/scripting/"
}
]
}
]
}
]
}
];
3 changes: 3 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "bun run build:app",
"build:app": "astro check && astro build",
"dev": "astro dev",
"generate:sidebar": "bun run scripts/generateSidebar.ts",
"preview": "astro preview",
"start": "astro dev"
},
Expand All @@ -22,6 +23,8 @@
"devDependencies": {
"@tevm/memory-client": "workspace:^",
"@tevm/viem": "workspace:^",
"@types/glob": "^8.1.0",
"glob": "^11.0.0",
"gray-matter": "^4.0.3",
"tevm": "workspace:^"
}
Expand Down
57 changes: 41 additions & 16 deletions docs/scripts/generateSidebar.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,76 @@
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
import { glob } from 'glob';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const docsDir = path.join(__dirname, '../src/content/docs');
const sidebarConfigPath = path.join(__dirname, '../astro.sidebar.config.mjs');

interface SidebarItem {
label: string;
link: string;
items?: SidebarItem[];
}

interface SidebarConfig {
label: string;
items: SidebarItem[];
}

function generateSidebarConfig(dir: string): SidebarItem[] {
function generateSidebarConfig(): SidebarItem[] {
const items: SidebarItem[] = [];

fs.readdirSync(dir).forEach(file => {
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
// Use glob to find all markdown and mdx files, excluding specific directories and files
const files = glob.sync('**/*.{md,mdx}', {
cwd: docsDir,
ignore: ['reference/**', 'blog/**', 'index.mdx'],
});

console.log(`Found markdown and mdx files: ${files}`);

files.forEach(file => {
const fullPath = path.join(docsDir, file);
const { data } = matter(fs.readFileSync(fullPath, 'utf8'));
const fileName = path.basename(file, path.extname(file));
const dirName = path.dirname(file);

if (stat.isDirectory()) {
const indexPath = path.join(fullPath, 'index.md');
if (fs.existsSync(indexPath)) {
const { data } = matter(fs.readFileSync(indexPath, 'utf8'));
items.push({ label: data.title || file, link: `/learn/${file}/` });
// Split the directory path to create nested structure
const pathParts = dirName.split(path.sep);

// Create a nested structure based on the directory path
let currentLevel = items;
pathParts.forEach((part) => {
let existingItem = currentLevel.find(item => item.label === part);
if (!existingItem) {
existingItem = { label: part, link: '', items: [] };
currentLevel.push(existingItem);
}
if (existingItem.items) {
currentLevel = existingItem.items;
}
} else if (file.endsWith('.md')) {
const { data } = matter(fs.readFileSync(fullPath, 'utf8'));
const fileName = path.basename(file, '.md');
items.push({ label: data.title || fileName, link: `/learn/${fileName}/` });
}
});

// Add the file to the appropriate level
const linkPath = fileName === 'index' ? `/${dirName}/` : `/${dirName}/${fileName}/`;
currentLevel.push({ label: data.title || fileName, link: linkPath });
console.log(`Added item: ${data.title || fileName} with link: ${linkPath}`);
});

console.log(`Generated items: ${JSON.stringify(items, null, 2)}`);
return items;
}

const sidebarConfig: SidebarConfig[] = [
{
label: 'Learn',
items: generateSidebarConfig(docsDir),
items: generateSidebarConfig(),
},
];

fs.writeFileSync(sidebarConfigPath, `export const sidebarConfig = ${JSON.stringify(sidebarConfig, null, 4)};`);

console.log('Sidebar configuration generated successfully.');

1 change: 1 addition & 0 deletions docs/src/content/docs/why/advanced-gas-estimation.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Advanced gas estimation
description: Tevm advanced contract simulation and gas estimation use case
position: 3
---

## TODO
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/why/avoid-waterfalls.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Slow waterfall calls
description: Avoiding slow UI using Tevm bring your own view function
position: 1
---
# Slow to load UI from waterfall calls

Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/why/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Why Tevm
description: Explanation of Tevm and it's use case
position: 0
---

# Why Tevm
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/why/optimistic-updates.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Optimistic UI
description: Implementing robust optimistic ui
position: 4
---
# Implementing Robust Optimistic UI

Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/why/reuse-solidity.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Optimistic UI
description: Implementing robust optimistic ui
position: 2
---
# Reusing solidity logic

Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/why/write-ui-in-solidity.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Writing UI in solidity
description: Implementing anything in solidity via bring your own cheat codes
position: 5
---
## TODO

Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/why/writing-tests.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Writing tests
description: Using Tevm to write tests
position: 6
---
## Problem

Expand Down

0 comments on commit dd93c28

Please sign in to comment.