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

feat: use GitHub's default README as index page #255

Merged
merged 2 commits into from
Oct 5, 2022
Merged

Conversation

dandhlee
Copy link
Collaborator

@dandhlee dandhlee commented Oct 5, 2022

Instead of using a custom index page that provided little to no benefit, this PR is incorporating the existing README as the main index page. This was asked by a lot of DPEs for their client libraries' landing page.

The markdown generator unfortunately messed around with the spacing for image links (see tests/markdown_example_bad_image_links.md file for reference), but all other parts I've verified is looking good. (See staged version of the doc for https://cloud.google.com/python/docs/reference/storage/latest). Adding a small parser to help fix that for the index file.

Fixes #105.
Fixes #107.

  • Tests pass

@dandhlee dandhlee requested review from a team as code owners October 5, 2022 05:20
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Oct 5, 2022
"""Cleans extra whitespace that breaks image links in index.html file."""
image_link_pattern='\[\s*!\[image\]\(.*\)\s*\]\(.*\)'
new_lines = []
with open(mdfile_path) as mdfile_iterator:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just name this mdfile? No need for the type suffix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 1438 to 1441
broken_image_links = [
[m.start(), m.end()]
for m in re.finditer(image_link_pattern, file_content)
]
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it could be done in a single loop, rather than creating this list then iterating over it below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. Removed the redundant list.


new_lines.append(file_content[prev_end:])

with open(mdfile_path, 'w') as mdfile_iterator:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same naming comment (especially confusing because this writes to something named iterator, which doesn't really make sense to me).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -1448,16 +1477,16 @@ def prepend_markdown_header(filename: str, mdfile: Iterable[str]):
def find_markdown_pages(app, outdir):
# Use this to ignore markdown files that are unnecessary.
files_to_ignore = [
"index.md", # merge index.md and README.md and index.yaml later.
# See https://github.com/googleapis/sphinx-docfx-yaml/issues/105.
"index.md", # use readme.md instead

"reference.md", # Reference docs overlap with Overview. Will try and incorporate this in later.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still want to ignore this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes - the current setup after running Sphinx build creates index.md and readme.md, the default index.md contains a bit more info than readme.md file that we want to use. So, we'll continue to ignore it, overwrite it with readme.md file instead.


shutil.copy(mdfile, f"{outdir}/{mdfile_name_to_use}")

# Do not add index file to the TOC.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not? Seems like we could set name to Overview here and not need the special handling down below ([{'name': 'Overview', 'href': 'index.md'}] + app.env.markdown_pages + pkg_toc_yaml)?

Perhaps for sorting? Still seems like it would be better to handle all md pages in this function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Putting the handler here did make the order tweak a bit (Overview doesn't always appear at the top). But I agree that the logic should be streamlined. Modified the handler here instead.

# Do not add index file to the TOC.
if mdfile_name_to_use == 'index.md':
# Clean up any broken image links for the index file.
clean_image_links(f"{outdir}/{mdfile_name_to_use}")
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't apply for every md file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've only seen this for the README pages containing the image, but wouldn't hurt to look for in every page. Updated.


[

![image](https://img.shields.io/badge/support-stable-gold.svg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like GitHub doesn't render these properly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently it doesn't because they're broken up - when the whitespaces are all trimmed then it should look fine, see https://github.com/googleapis/sphinx-docfx-yaml/blob/d016f0422bfb829df4eeb9fe8a9d10a5617f0e69/tests/markdown_example_bad_image_links_want.md

Copy link
Collaborator Author

@dandhlee dandhlee left a comment

Choose a reason for hiding this comment

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

Thank you! Please take a look again.

"""Cleans extra whitespace that breaks image links in index.html file."""
image_link_pattern='\[\s*!\[image\]\(.*\)\s*\]\(.*\)'
new_lines = []
with open(mdfile_path) as mdfile_iterator:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 1438 to 1441
broken_image_links = [
[m.start(), m.end()]
for m in re.finditer(image_link_pattern, file_content)
]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. Removed the redundant list.


new_lines.append(file_content[prev_end:])

with open(mdfile_path, 'w') as mdfile_iterator:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -1448,16 +1477,16 @@ def prepend_markdown_header(filename: str, mdfile: Iterable[str]):
def find_markdown_pages(app, outdir):
# Use this to ignore markdown files that are unnecessary.
files_to_ignore = [
"index.md", # merge index.md and README.md and index.yaml later.
# See https://github.com/googleapis/sphinx-docfx-yaml/issues/105.
"index.md", # use readme.md instead

"reference.md", # Reference docs overlap with Overview. Will try and incorporate this in later.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes - the current setup after running Sphinx build creates index.md and readme.md, the default index.md contains a bit more info than readme.md file that we want to use. So, we'll continue to ignore it, overwrite it with readme.md file instead.


[

![image](https://img.shields.io/badge/support-stable-gold.svg)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently it doesn't because they're broken up - when the whitespaces are all trimmed then it should look fine, see https://github.com/googleapis/sphinx-docfx-yaml/blob/d016f0422bfb829df4eeb9fe8a9d10a5617f0e69/tests/markdown_example_bad_image_links_want.md

# Do not add index file to the TOC.
if mdfile_name_to_use == 'index.md':
# Clean up any broken image links for the index file.
clean_image_links(f"{outdir}/{mdfile_name_to_use}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've only seen this for the README pages containing the image, but wouldn't hurt to look for in every page. Updated.


shutil.copy(mdfile, f"{outdir}/{mdfile_name_to_use}")

# Do not add index file to the TOC.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Putting the handler here did make the order tweak a bit (Overview doesn't always appear at the top). But I agree that the logic should be streamlined. Modified the handler here instead.

@dandhlee dandhlee merged commit 17f6ca0 into main Oct 5, 2022
@dandhlee dandhlee deleted the merge_readme branch October 5, 2022 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename README files into another name. Parse index.md files into index.yaml
2 participants