๐งญ Emoji + Metadata + Tree Layout
Here's a complete Python script that generates a visually appealing tree structure of your project folder using emoji icons and file metadata. The output is formatted as a Bash-style code block perfect for embedding in Docusaurus.
Full Expressive Python Scriptโ
https://copilot.microsoft.com/shares/B7pvjR59PwjbFEnyQNiEJ
generate_tree_md.py
import os
import datetime
# ๐ง Feature toggles
INCLUDE_EMOJI = True
INCLUDE_METADATA = False
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = False
# ๐๏ธ Manual file comments (extend as needed)
MANUAL_COMMENTS = {
"WebBrowser.js": "Main browser component",
"WebBrowser.module.css": "Browser styles",
"BrowserExamples.js": "Example components (optional)",
"README.md": "Project overview",
"config.json": "Configuration settings"
}
# ๐ญ Emoji mapping by file extension
def emoji_for_file(file_name):
ext = os.path.splitext(file_name)[1].lower()
return {
'.js': '๐',
'.ts': '๐',
'.css': '๐จ',
'.scss': '๐งต',
'.html': '๐',
'.py': '๐',
'.md': '๐',
'.json': '๐ง',
'.jpg': '๐ผ๏ธ',
'.png': '๐ผ๏ธ',
'.txt': '๐',
'.test.js': '๐งช',
'.lock': '๐',
}.get(ext, '๐')
# ๐ Emoji by folder purpose
def emoji_for_folder(folder_name):
mapping = {
'test': '๐งช',
'tests': '๐งช',
'components': '๐งฉ',
'config': 'โ๏ธ',
'public': '๐',
'docs': '๐',
'scripts': '๐',
'assets': '๐จ',
'utils': '๐งฐ',
}
for key, icon in mapping.items():
if key.lower() in folder_name.lower():
return icon
return '๐'
# ๐ Generate metadata comment
def get_file_metadata_comment(file_path):
stats = os.stat(file_path)
size_kb = stats.st_size / 1024
mtime = datetime.datetime.fromtimestamp(stats.st_mtime)
ext = os.path.splitext(file_path)[1].lower().lstrip('.').upper() or "Unknown"
return f"{ext} file, {size_kb:.1f} KB, modified {mtime.strftime('%Y-%m-%d %H:%M')}"
# ๐ณ Recursive folder walker
def map_folder_structure(root_path, indent=""):
lines = []
items = sorted(os.listdir(root_path))
for idx, item in enumerate(items):
item_path = os.path.join(root_path, item)
is_last = idx == len(items) - 1
prefix = "โโโ " if is_last else "โโโ "
line_prefix = indent + prefix
# Folder line
if os.path.isdir(item_path):
folder_emoji = emoji_for_folder(item) if SMART_FOLDER_LABELS and INCLUDE_EMOJI else ('๐' if INCLUDE_EMOJI else '')
spacing = ' ' if INCLUDE_EMOJI else ''
line = f"{line_prefix}{folder_emoji}{spacing}{item}/"
lines.append(line)
new_indent = indent + (" " if is_last else "โ ")
lines.extend(map_folder_structure(item_path, new_indent))
# File line
else:
file_emoji = emoji_for_file(item) if INCLUDE_EMOJI else ''
spacing = ' ' if INCLUDE_EMOJI else ''
comments = []
if INCLUDE_COMMENTS and item in MANUAL_COMMENTS:
comments.append(MANUAL_COMMENTS[item])
if INCLUDE_METADATA:
comments.append(get_file_metadata_comment(item_path))
comment_str = f" # {' | '.join(comments)}" if comments else ''
line = f"{line_prefix}{file_emoji}{spacing}{item}{comment_str}"
lines.append(line)
return lines
# ๐งช Wrap it all for Markdown embedding
def generate_docusaurus_bash_block(root_path):
root_name = os.path.basename(os.path.abspath(root_path))
if SMART_FOLDER_LABELS and INCLUDE_EMOJI:
top_icon = emoji_for_folder(root_name)
elif INCLUDE_EMOJI:
top_icon = '๐'
else:
top_icon = ''
spacing = ' ' if INCLUDE_EMOJI else ''
lines = [f"{top_icon}{spacing}{root_name}/"]
lines.extend(map_folder_structure(root_path))
return "```bash\n" + "\n".join(lines) + "\n```"
# โถ๏ธ Example usage
output = generate_docusaurus_bash_block("src/components")
print(output)
with open("project-structure.md", "w", encoding="utf-8") as f:
f.write("## ๐ Project Structure\n\n")
f.write(output)
๐ Project Structureโ
# ๐ง Feature toggles
INCLUDE_EMOJI = True
INCLUDE_METADATA = True
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = True
๐งฉ components/
โโโ ๐ BashTerminal.js # JS file, 5.3 KB, modified 2025-07-22 08:59
โโโ ๐จ BashTerminal.module.css # CSS file, 3.1 KB, modified 2025-07-22 08:59
โโโ ๐ BrowserExamples.js # Example components (optional) | JS file, 3.5 KB, modified 2025-07-22 08:59
โโโ ๐ BrowserWindow/
โ โโโ ๐ index.js # JS file, 1.1 KB, modified 2025-07-22 08:59
โ โโโ ๐จ styles.module.css # CSS file, 1.6 KB, modified 2025-07-22 08:59
โโโ ๐ HomepageFeatures/
โ โโโ ๐ index.js # JS file, 1.7 KB, modified 2025-07-22 08:59
โ โโโ ๐จ styles.module.css # CSS file, 0.1 KB, modified 2025-07-22 08:59
โโโ ๐ TerminalExamples.js # JS file, 1.4 KB, modified 2025-07-22 08:59
โโโ ๐ WebBrowser.js # Main browser component | JS file, 7.1 KB, modified 2025-07-22 08:59
โโโ ๐จ WebBrowser.module.css # Browser styles | CSS file, 7.0 KB, modified 2025-07-22 08:59
โโโ ๐ YouTubeEmbed.js # JS file, 1.1 KB, modified 2025-07-22 08:59
# ๐ง Feature toggles
INCLUDE_EMOJI = True
INCLUDE_METADATA = False
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = True
๐งฉ components/
โโโ ๐ BashTerminal.js
โโโ ๐จ BashTerminal.module.css
โโโ ๐ BrowserExamples.js # Example components (optional)
โโโ ๐ BrowserWindow/
โ โโโ ๐ index.js
โ โโโ ๐จ styles.module.css
โโโ ๐ HomepageFeatures/
โ โโโ ๐ index.js
โ โโโ ๐จ styles.module.css
โโโ ๐ TerminalExamples.js
โโโ ๐ WebBrowser.js # Main browser component
โโโ ๐จ WebBrowser.module.css # Browser styles
โโโ ๐ YouTubeEmbed.js
# ๐ง Feature toggles
INCLUDE_EMOJI = True
INCLUDE_METADATA = False
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = False
๐ components/
โโโ ๐ BashTerminal.js
โโโ ๐จ BashTerminal.module.css
โโโ ๐ BrowserExamples.js # Example components (optional)
โโโ ๐ BrowserWindow/
โ โโโ ๐ index.js
โ โโโ ๐จ styles.module.css
โโโ ๐ HomepageFeatures/
โ โโโ ๐ index.js
โ โโโ ๐จ styles.module.css
โโโ ๐ TerminalExamples.js
โโโ ๐ WebBrowser.js # Main browser component
โโโ ๐จ WebBrowser.module.css # Browser styles
โโโ ๐ YouTubeEmbed.js
# ๐ง Feature toggles
INCLUDE_EMOJI = False
INCLUDE_METADATA = False
INCLUDE_COMMENTS = True
SMART_FOLDER_LABELS = False
components/
โโโ BashTerminal.js
โโโ BashTerminal.module.css
โโโ BrowserExamples.js # Example components (optional)
โโโ BrowserWindow/
โ โโโ index.js
โ โโโ styles.module.css
โโโ HomepageFeatures/
โ โโโ index.js
โ โโโ styles.module.css
โโโ TerminalExamples.js
โโโ WebBrowser.js # Main browser component
โโโ WebBrowser.module.css # Browser styles
โโโ YouTubeEmbed.js