Blog / app.py
ArthurFischel's picture
Update app.py
287969e
raw
history blame
1.26 kB
import streamlit as st
def read_readme():
with open("README.md", "r") as f:
readme_content = f.read()
# Find the start and end of the block to remove
start_marker = "---\n"
end_marker = "\n---"
start_index = readme_content.find(start_marker)
end_index = readme_content.find(end_marker) + len(end_marker)
# Remove the block if found
if start_index != -1 and end_index != -1:
readme_content = readme_content[:start_index] + readme_content[end_index:]
return readme_content
def create_pages(content):
pages = content.split("# ")
# Remove the first element as it contains the intro
intro = pages.pop(0)
return intro, pages
def main():
readme_content = read_readme()
intro, pages = create_pages(readme_content)
st.title("Welcome to My Blog")
st.markdown(intro)
st.sidebar.title("Sections")
for index, page in enumerate(pages):
page_title = page.split("\n", 1)[0]
st.sidebar.markdown(f"[{page_title}](#{index})")
for index, page in enumerate(pages):
st.markdown(f"## {page}")
st.markdown(page, unsafe_allow_html=True)
st.sidebar.markdown(f"[Back to Top](#{index})")
if __name__ == "__main__":
main()