Last active
March 18, 2021 13:57
-
-
Save pnettto/ca0adc0e8d5550cb34ce5144ec2b305f to your computer and use it in GitHub Desktop.
Hello @Soneji, glad you found it useful :) I'm a little busy at the moment so I won't be able to dive into it (i.e. create a project to test and fiddle with it, etc), but I'd recommend taking a look at the function "write_entry_in_sidebar", since I think that's where the issue is. Good luck! :)
Thank you! I ended up writing my own script based on the original (just like yours), which finds all markdown files recursively and puts them in the sidebar (just with one level of depth). If anybody wants it:
#!/usr/bin/env python3
import glob
import os
PATH = "."
files = []
for x in os.walk(PATH):
for y in glob.glob(os.path.join(x[0], '*.md')):
files.append(y)
files[-1] = files[-1].replace(".", "", 1)
sidebar_file = open('_sidebar.md', 'w')
name = "Home"
file = "/"
sidebar_file.write(f"* [{name}]({file})\n")
try:
files.remove("/README.md")
files.remove("/_sidebar.md")
# put any other files you want to remove here
except:
pass
files.sort()
for file in files:
if ".md" in file:
name = file[1:-3]
name = name.replace("/", "'s ")
name = name.replace("_", " ")
name = name.replace("-", " ")
file = file.replace(" ", "%20")
sidebar_file.write(f"* [{name}]({file})\n")
sidebar_file.close()
print("============================================================")
print("Sidebar:")
print("============================================================")
try:
os.system("cat _sidebar.md")
except:
print("Unable to `cat _sidebar.md`")
print("============================================================")
@Soneji That's so cool! Thanks for sharing :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @brisa-pedronetto
Thank you for this script, it's amazing!
I was wondering if I could have some help because I am running into an issue where the script is using
./folder/file.md
when I want it to use/folder/file.md
. Is there any way to do this?This is an issue because once I navigate to
./folder/file.md
and then click on another file in the same subdirectory it takes me to./folder/file2.md
which leads me towebsite.com/folder/folder/file2.md
which leads to a 404Any help would be appreciated. Thank you!!