Spaces:
Paused
Paused
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:] | |
# Split content by H1 headers | |
sections = readme_content.split("\n# ") | |
# Remove the first element as it's empty due to the initial split | |
sections = sections[1:] | |
return sections | |
def main(): | |
st.title("Welcome to My Blog") | |
st.write("This is my blog where I share various topics.") | |
sections = read_readme() | |
# Display links to separate pages for each section | |
st.subheader("Blog Sections:") | |
for section in sections: | |
section_title, *section_content = section.split("\n") | |
section_content = "\n".join(section_content) | |
# Display links to separate pages with the section title as the link text | |
st.markdown(f"- [{section_title.strip('#').strip()}](#{section_title.strip('#').strip().lower().replace(' ', '-')})") | |
# Display the section content on the separate page | |
st.write(f"## {section_title}") | |
st.markdown(section_content, unsafe_allow_html=True) | |
st.write("---") | |
if __name__ == "__main__": | |
main() | |