Last active
March 18, 2021 13:57
-
-
Save pnettto/ca0adc0e8d5550cb34ce5144ec2b305f to your computer and use it in GitHub Desktop.
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
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! :)