Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: include root index.html in --html output #104

Closed

Conversation

ryangalamb
Copy link

@ryangalamb ryangalamb commented Aug 29, 2019

Implements #101 .

It adds the root index.html from the --http mode to the static --html output.

To avoid breaking people's automations, I've put this feature behind a flag (--html-index) and left the default behavior alone.

I also added the breadcrumbs to the module pages when --html-index is active.

You can use as much or as little of this as you want. I did this in several small commits so you can see all the options side-by-side.

What's left

  • put the feature behind a flag
  • check for file existence like the rest of the files do
  • write tests for the new flag
  • include breadcrumbs

pdoc/cli.py Outdated
@@ -487,6 +487,25 @@ def docfilter(obj, _filters=args.filter.strip().split(',')):
# Two blank lines between two modules' texts
sys.stdout.write(os.linesep * (1 + 2 * int(module != modules[-1])))

# Add the root index.html at the top level
if args.html:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is adapted from WebDoc.do_GET on "/". That one doesn't use the pydoc.Module class for the root index. It uses args.modules and imports the modules to get the name and docstring.

When I tried doing it in the same way here, there were some inconsistencies with the rest of the --html behavior that was causing some weird breakages and test errors. Otherwise, I would have pulled the logic out into a helper function.

modules=module_tuples,
**template_config)
index_file = path.join(args.output_dir, 'index.html')
try:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this logic is adapted from write_files. I couldn't use it directly, since it expects a pdoc.Module as input, so I just copy-pasted. I can go back and refactor that to be more DRY if you prefer.

@@ -487,6 +492,25 @@ def docfilter(obj, _filters=args.filter.strip().split(',')):
# Two blank lines between two modules' texts
sys.stdout.write(os.linesep * (1 + 2 * int(module != modules[-1])))

if args.html and args.html_index:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll name the arg whatever you want, but this is the general idea.

@ryangalamb
Copy link
Author

To my point about breaking automation: The CI build was failing for "Deploy" with my initial PR, but it's passing now that I've put the feature behind a flag.

@ryangalamb ryangalamb marked this pull request as ready for review August 30, 2019 01:18
@kernc
Copy link
Member

kernc commented Jan 11, 2020

Let's discuss this back in #101.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants