Here's my quick and dirty script that I added to *conf.py* 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)
On Thursday, August 17, 2023 at 1:02:53 PM UTC-6 Shawn Hymel wrote:

> The closest I could find was to go through each .rst file and remove the 
> package/module parents from the title. For example, in the file 
> *edgeimpulse_api.api.admin_api.rst*, I changed:
>
> edgeimpulse\_api.api.auth\_api module
> =====================================
>
> to:
>
> auth\_api module
> ================
>
> That helped make some of the longer titles much easier to read on the left 
> sidebar and on the page itself (see screenshot, using Furo theme).
>
> Is there any way to change the title like this automatically (either in 
> sphinx-apidoc or sphinx-build) without needing to manually edit every .rst 
> file? My search through docs and forums has not turned up anything. My 
> backup plan is to create a pre-processing script that runs between 
> sphinx-apidoc and sphinx-build to modify the titles in all .rst files (not 
> pretty, so I'm hoping to avoid this option).
>

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sphinx-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/76a190b8-500d-4acc-8eee-ccc67290074cn%40googlegroups.com.

Reply via email to