to shorten all titles in the .rst source files. If anyone knows of a better/cleaner way to do this, please let me know!
# Recursively crawl through source directory and shorten titles in .rst files
def crawl_source_shorten_titles(path):
# List files in directory
for file_name in os.listdir(path):
# Build path to file
file_path = os.path.join(path, file_name)
# Recursively crawl to next directory level
if os.path.isdir(file_path):
crawl_source_shorten_titles(file_path)
# Modify .rst source file title
else:
_, extension = os.path.splitext(file_path)
if extension == ".rst":
# Read file, modify title, write back to file
with open(file_path, 'r') as file:
lines = file.readlines()
lines[0] = lines[0].split('.')[-1]
lines[1] = ("=" * (len(lines[0]) - 1)) + "\n"
with open(file_path, 'w') as file:
file.writelines(lines)
# Remove parents from titles in all .rst files
if not show_title_parents:
crawl_source_shorten_titles(source_path)