File size: 1,914 Bytes
7c062a8
 
 
49bea70
7c062a8
49bea70
 
 
 
 
 
b22e396
49bea70
9b50500
7c062a8
 
f8a5639
7c062a8
49bea70
 
 
 
 
 
 
 
 
 
9b50500
 
 
49bea70
 
 
 
 
 
 
9b50500
49bea70
 
 
 
 
 
9b50500
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
import os

# Improved function to read markdown files with error handling
def load_markdown_file(path):
    try:
        with open(path, 'r', encoding='utf-8') as file:
            content = file.read()
        return content
    except Exception as e:
        return f"Error reading file: {e}"

# Streamlit UI Enhancements
st.title('πŸ“š Documentation')

# Assuming your documentation is in the 'docs' folder
docs_base_path = './docs'

# Enhanced error handling for directory listing
if not os.path.exists(docs_base_path):
    st.error('Documentation directory does not exist.')
else:
    # List categories based on folder names with improved error handling
    try:
        categories = [d for d in os.listdir(docs_base_path) if os.path.isdir(os.path.join(docs_base_path, d))]
        if not categories:
            st.error('No categories found in the documentation directory.')
        else:
            st.sidebar.markdown('## 🧷 Navigation')
            
            category = st.sidebar.selectbox('πŸ“ Select the Space', categories)
            
            # List pages based on markdown files in the selected category folder
            pages_path = os.path.join(docs_base_path, category)
            pages = [f for f in os.listdir(pages_path) if os.path.isfile(os.path.join(pages_path, f)) and f.endswith('.md')]
            if not pages:
                st.error('No markdown pages found in the selected category.')
            else:
                page = st.sidebar.selectbox('πŸ“œ Select the Page', pages)
                
                # Load and display the selected markdown file
                markdown_path = os.path.join(pages_path, page)
                markdown_content = load_markdown_file(markdown_path)
                st.markdown(markdown_content, unsafe_allow_html=True)
    except Exception as e:
        st.error(f"Error listing categories or pages: {e}")