Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gitbook generation #72

Merged
merged 12 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/generate-md.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Generate Markdown on Merge

on:
merge_group:
push:
branches:
- main

concurrency:
group: ${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

permissions:
packages: write
contents: write

jobs:
generate-md:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

# - name: Install dependencies
# run: pip install --no-cache-dir -r requirements.txt

- name: Run Markdown generation script
run: python scripts/gen-tools-md.py

- name: Commit generated Markdown files
run: |
git config user.name "GitHub Action"
git config user.email "[email protected]"
git add -A
git commit -m "Update generated Markdown files"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/validate-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Validate PR

on:
pull_request:
branches:
- main

jobs:
validate-script:
name: Can merge
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

# - name: Install dependencies
# run: pip install --no-cache-dir -r requirements.txt

- name: Run Markdown generation script
run: python scripts/gen-tools-md.py
15 changes: 15 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# user-and-dev-tools Json to Markdown

This script iterates through the `user-and-dev-tools/{testnet|mainnet}` directories and generates a corresponding markdown file from
each json file (placing them in a subdirectory `MD`).

By default, all json files and all keys in the json files are included. You can exclude keys from a file, or the entire file, by editing
`files_keys_exclude.json`, for example:

```
{
"explorers.json": ["Short Description", "GitHub Account"],
"masp-indexers.json": ["*"]
}
```
Will omit the given keys/values from `explorers.md`, and will skip generating `masp-indexers.md` entirely.
3 changes: 3 additions & 0 deletions scripts/files_keys_exclude.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
129 changes: 129 additions & 0 deletions scripts/gen-tools-md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import os
import json
import shutil

def remove_existing_markdown_files(base_dir, gitbook_dir, subdirs):
"""Remove all existing markdown files in the gitbook directories."""
for subdir in subdirs:
md_dir = os.path.join(base_dir, gitbook_dir, subdir)
if os.path.exists(md_dir):
shutil.rmtree(md_dir)
os.makedirs(md_dir, exist_ok=True)

def generate_summary_file(base_dir, gitbook_dir, subdirs, resources_links):
"""Generate the SUMMARY.md file."""
summary_path = os.path.join(base_dir, gitbook_dir, "SUMMARY.md")
summary_content = "# Summary\n\n## About\n\n* [Home](./README.md)\n* [FAQ](./faq.md)\n\n## Resources\n"

for subdir, links in resources_links.items():
summary_content += f"* [{subdir.title()} Resources](./{subdir}/README.md)\n"
for title, path in links:
summary_content += f" * [{title}](./{path})\n"

try:
with open(summary_path, "w") as summary_file:
summary_file.write(summary_content)
print(f"Generated {summary_path}")
except IOError as e:
print(f"Error writing to {summary_path}: {e}")

def generate_markdown_files(files_keys_exclude):
"""
Generate markdown files from the Json input files.
Takes a list of files and their keys to exclude from the generated markdown.
"""
subdirs = ["mainnet", "testnet"]
base_dir = "user-and-dev-tools"
gitbook_dir = "gitbook"
base_url = "https://luminara-namada.gitbook.io/namada-ecosystem/resources"

# Remove any existing markdown files
remove_existing_markdown_files(base_dir, gitbook_dir, subdirs)

resources_links = {subdir: [] for subdir in subdirs}

for subdir in subdirs:
json_dir = os.path.join(base_dir, subdir)
md_dir = os.path.join(base_dir, gitbook_dir, subdir)
os.makedirs(md_dir, exist_ok=True)

readme_content = f"# {subdir.title()} Resources\n\n"

for file_name in os.listdir(json_dir):
if not file_name.endswith(".json"):
continue

json_path = os.path.join(json_dir, file_name)

# If a file is passed with exclude equals "*", skip it entirely
if file_name in files_keys_exclude and "*" in files_keys_exclude[file_name]:
print(f"Skipping entire file: {file_name}")
continue

try:
with open(json_path, "r") as f:
data = json.load(f)
except json.JSONDecodeError as e:
print(f"Error decoding {json_path}: {e}")
continue

# Generate markdown content
markdown_content = f"# {file_name.replace('.json', '').title()}\n\n"
excluded_keys = files_keys_exclude.get(file_name, [])

# Iterate over each object in JSON array
if isinstance(data, list):
for idx, obj in enumerate(data, start=1):
if idx != 1:
markdown_content += f"---\n"
for key, value in obj.items():
if key in excluded_keys:
continue
markdown_content += f"- **{key}**: {value if value else 'N/A'}\n"
markdown_content += "\n"

# Write markdown file
md_file_name = file_name.replace(".json", ".md")
md_file_path = os.path.join(md_dir, md_file_name)
try:
with open(md_file_path, "w") as md_file:
md_file.write(markdown_content)
print(f"Generated {md_file_path}")

# Add link to README content
link = f"{base_url}/{subdir}/{md_file_name.replace('.md', '')}"
readme_content += f"- [{md_file_name.replace('.md', '').title()}]({link})\n"

# Add link to resources for SUMMARY.md
resources_links[subdir].append((md_file_name.replace('.md', '').title(), f"{subdir}/{md_file_name}"))
except IOError as e:
print(f"Error writing to {md_file_path}: {e}")

# Write README.md file
readme_file_path = os.path.join(md_dir, "README.md")
try:
with open(readme_file_path, "w") as readme_file:
readme_file.write(readme_content)
print(f"Generated {readme_file_path}")
except IOError as e:
print(f"Error writing to {readme_file_path}: {e}")

# Generate the SUMMARY.md file
generate_summary_file(base_dir, gitbook_dir, subdirs, resources_links)

if __name__ == "__main__":
# Load the list of files and keys to exclude from the markdown
script_dir = os.path.dirname(os.path.abspath(__file__))
exclude_file_path = os.path.join(script_dir, "files_keys_exclude.json")

try:
with open(exclude_file_path, "r") as f:
files_keys_exclude = json.load(f)
except FileNotFoundError:
print(f"Error: {exclude_file_path} not found.")
exit(1)
except json.JSONDecodeError as e:
print(f"Error decoding {exclude_file_path}: {e}")
exit(1)

generate_markdown_files(files_keys_exclude)
19 changes: 19 additions & 0 deletions user-and-dev-tools/gitbook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Namada Ecosystem - User and Dev Tools

This repo holds a list of Namada resources for both mainnet and testnet, operated by [Luminara](https://luminara.icu), the Namada community collective.

Here, you can find an up-to-date registry of:

- RPCs
- Explorers
- Namadillo Interfaces
- Other community-made tools
- and more 🙂

**Are you hosting infra or some other tool?** Get listed here by making a PR to this repo! Just find and update the relevant json file in the [user-and-dev-tools](https://github.com/Luminara-Hub/namada-ecosystem/tree/main/user-and-dev-tools) directory with your info.

---

These docs are publicly hosted on GitBook at https://luminara-namada.gitbook.io/namada-ecosystem.

Suggest improvements by creating an issue or pull request at the [namada-ecosystem](https://github.com/Luminara-Hub/namada-ecosystem) repo.
34 changes: 34 additions & 0 deletions user-and-dev-tools/gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Summary

## About

* [Home](./README.md)
* [FAQ](./faq.md)

## Resources
* [Mainnet Resources](./mainnet/README.md)
* [Ibc-Relayers](./mainnet/ibc-relayers.md)
* [Explorers](./mainnet/explorers.md)
* [Namada-Indexers](./mainnet/namada-indexers.md)
* [Seeds](./mainnet/seeds.md)
* [Monitoring-And-Dashboards](./mainnet/monitoring-and-dashboards.md)
* [Snapshots](./mainnet/snapshots.md)
* [Tooling-And-Scripts](./mainnet/tooling-and-scripts.md)
* [Rpc](./mainnet/rpc.md)
* [Peers](./mainnet/peers.md)
* [Masp-Indexers](./mainnet/masp-indexers.md)
* [Signers-Wallets](./mainnet/signers-wallets.md)
* [Interfaces](./mainnet/interfaces.md)
* [Testnet Resources](./testnet/README.md)
* [Ibc-Relayers](./testnet/ibc-relayers.md)
* [Explorers](./testnet/explorers.md)
* [Namada-Indexers](./testnet/namada-indexers.md)
* [Seeds](./testnet/seeds.md)
* [Monitoring-And-Dashboards](./testnet/monitoring-and-dashboards.md)
* [Snapshots](./testnet/snapshots.md)
* [Tooling-And-Scripts](./testnet/tooling-and-scripts.md)
* [Rpc](./testnet/rpc.md)
* [Peers](./testnet/peers.md)
* [Masp-Indexers](./testnet/masp-indexers.md)
* [Signers-Wallets](./testnet/signers-wallets.md)
* [Interfaces](./testnet/interfaces.md)
17 changes: 17 additions & 0 deletions user-and-dev-tools/gitbook/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# FAQ

**What is Namada?**
Namada is an L1 Proof-of-Stake chain with a focus on data protection and a multi-asset shielded pool. While Namada is not a Cosmos SDK chain, it has close ties to that ecosystem and is fully IBC compatible, allowing full interoperability with Cosmos SDK chains.

**Where can I find info about the Namada mainnet?**
The Namada mainnet is currently live after having been launched on December 3 @ 15:00 UTC, with chain-id `namada.5f5de2dd1b88cba30586420`.

For further instructions on running a node on Namada mainnet, see the docs: https://docs.namada.net/networks/mainnets

**Where can I find info about the Namada testnet?**
Namada's permanent testnet (aka: Housefire) is currently live with chain-id `housefire-alpaca.cc0d3e0c033be`.

For further instructions on running a node on Namada testnet, see the docs: https://docs.namada.net/networks/testnets

**How can I get my tool listed here?**
You can become listed here as a tool or infra provider by making a Pull Request to this repo after adding your info to the corresponding json file in `user-and-dev-tools/{mainnet | testnet}`. For help or for any questions, please reach out to `@CryptoDruide | Crypto_Universe` in the Namada Discord!
14 changes: 14 additions & 0 deletions user-and-dev-tools/gitbook/mainnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Mainnet Resources

- [Ibc-Relayers](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/ibc-relayers)
- [Explorers](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/explorers)
- [Namada-Indexers](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/namada-indexers)
- [Seeds](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/seeds)
- [Monitoring-And-Dashboards](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/monitoring-and-dashboards)
- [Snapshots](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/snapshots)
- [Tooling-And-Scripts](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/tooling-and-scripts)
- [Rpc](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/rpc)
- [Peers](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/peers)
- [Masp-Indexers](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/masp-indexers)
- [Signers-Wallets](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/signers-wallets)
- [Interfaces](https://luminara-namada.gitbook.io/namada-ecosystem/resources/mainnet/interfaces)
36 changes: 36 additions & 0 deletions user-and-dev-tools/gitbook/mainnet/explorers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Explorers

- **Explorer Name**: Valopers
- **URL**: https://namada.valopers.com/
- **Short Description**: N/A
- **Team or Contributor Name**: Bitszn
- **GitHub Account**: N/A

---
- **Explorer Name**: Shielded.Live
- **URL**: https://shielded.live/
- **Short Description**: N/A
- **Team or Contributor Name**: Mandragora
- **GitHub Account**: https://github.com/McDaan

---
- **Explorer Name**: explorer75
- **URL**: https://explorer75.org/namada
- **Short Description**: N/A
- **Team or Contributor Name**: pro-nodes75
- **GitHub Account**: https://github.com/the-node75

---
- **Explorer Name**: Namada Explorer
- **URL**: https://namada-explorer.sproutstake.space/
- **Short Description**: N/A
- **Team or Contributor Name**: Sproutstake
- **GitHub Account**: N/A

---
- **Explorer Name**: Namada Explorer
- **URL**: https://namada.explorers.guru/
- **Short Description**: N/A
- **Team or Contributor Name**: Nodes.Guru
- **GitHub Account**: https://github.com/nodesguru

10 changes: 10 additions & 0 deletions user-and-dev-tools/gitbook/mainnet/ibc-relayers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ibc-Relayers

- **Network A**: N/A
- **Network B**: N/A
- **A to B Channel ID**: N/A
- **B to A Channel ID**: N/A
- **Team or Contributor Name**: N/A
- **Discord UserName**: N/A
- **GitHub Account**: N/A

Loading
Loading