ArthurFischel commited on
Commit
0febb3e
1 Parent(s): 91b65b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -22
app.py CHANGED
@@ -1,43 +1,48 @@
1
  import streamlit as st
2
 
 
3
  def read_readme():
4
  with open("README.md", "r") as f:
5
  readme_content = f.read()
6
-
7
  # Find the start and end of the block to remove
8
  start_marker = "---\n"
9
  end_marker = "\n---"
10
  start_index = readme_content.find(start_marker)
11
  end_index = readme_content.find(end_marker) + len(end_marker)
12
-
13
  # Remove the block if found
14
  if start_index != -1 and end_index != -1:
15
  readme_content = readme_content[:start_index] + readme_content[end_index:]
 
 
 
16
 
17
- return readme_content
 
18
 
19
- def create_pages(content):
20
- pages = content.split("# ")
21
- # Remove the first element as it contains the intro
22
- intro = pages.pop(0)
23
- return intro, pages
24
 
25
- def main():
26
- readme_content = read_readme()
27
- intro, pages = create_pages(readme_content)
28
 
 
29
  st.title("Welcome to My Blog")
30
- st.markdown(intro)
31
-
32
- st.sidebar.title("Sections")
33
- for index, page in enumerate(pages):
34
- page_title = page.split("\n", 1)[0]
35
- st.sidebar.markdown(f"[{page_title}](#{index})")
36
-
37
- for index, page in enumerate(pages):
38
- st.markdown(f"## {page}")
39
- st.markdown(page, unsafe_allow_html=True)
40
- st.sidebar.markdown(f"[Back to Top](#{index})")
 
 
 
 
 
 
41
 
42
 
43
  if __name__ == "__main__":
 
1
  import streamlit as st
2
 
3
+
4
  def read_readme():
5
  with open("README.md", "r") as f:
6
  readme_content = f.read()
7
+
8
  # Find the start and end of the block to remove
9
  start_marker = "---\n"
10
  end_marker = "\n---"
11
  start_index = readme_content.find(start_marker)
12
  end_index = readme_content.find(end_marker) + len(end_marker)
13
+
14
  # Remove the block if found
15
  if start_index != -1 and end_index != -1:
16
  readme_content = readme_content[:start_index] + readme_content[end_index:]
17
+
18
+ # Split content by H1 headers
19
+ sections = readme_content.split("\n# ")
20
 
21
+ # Remove the first element as it's empty due to the initial split
22
+ sections = sections[1:]
23
 
24
+ return sections
 
 
 
 
25
 
 
 
 
26
 
27
+ def main():
28
  st.title("Welcome to My Blog")
29
+ st.write("This is my blog where I share various topics.")
30
+
31
+ sections = read_readme()
32
+
33
+ # Display links to separate pages for each section
34
+ st.subheader("Blog Sections:")
35
+ for section in sections:
36
+ section_title, *section_content = section.split("\n")
37
+ section_content = "\n".join(section_content)
38
+
39
+ # Display links to separate pages with the section title as the link text
40
+ st.markdown(f"- [{section_title.strip('#').strip()}](#{section_title.strip('#').strip().lower().replace(' ', '-')})")
41
+
42
+ # Display the section content on the separate page
43
+ st.write(f"## {section_title}")
44
+ st.markdown(section_content, unsafe_allow_html=True)
45
+ st.write("---")
46
 
47
 
48
  if __name__ == "__main__":