Skip to content

Commit

Permalink
fix: allow multiple/custom index pages to be used (#280)
Browse files Browse the repository at this point in the history
* fix: allow custom index files

* test: include non-cloud library

* test: update goldens

* fix: retrieve markdown files

* test: fix non-cloud setting

* test: remove unnecessary requirements

* test: remove region tags

* Update docfx_yaml/markdown_utils.py

Co-authored-by: Tyler Bui-Palsulich <26876514+tbpg@users.noreply.github.com>

* test: update goldens with proper region tags

* fix: apply review suggestions

---------

Co-authored-by: Tyler Bui-Palsulich <26876514+tbpg@users.noreply.github.com>
  • Loading branch information
dandhlee and tbpg authored Feb 3, 2023
1 parent 2221b48 commit 7ee38d8
Show file tree
Hide file tree
Showing 51 changed files with 8,173 additions and 10 deletions.
31 changes: 22 additions & 9 deletions docfx_yaml/markdown_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ def move_markdown_pages(
# Used to keep track of the index page entry to insert later.
index_page_entry = None

markdown_file_names = {
mdfile.name.lower()
for mdfile in markdown_dir.iterdir()
}

# If there is an index.md and no readme.md, use the index.md. Otherwise, we ignore the index.md.
if ("index.md" in markdown_file_names and
"readme.md" not in markdown_file_names):
files_to_ignore.remove("index.md")

# For each file, if it is a markdown file move to the top level pages.
for mdfile in markdown_dir.iterdir():
if mdfile.is_dir():
Expand Down Expand Up @@ -332,6 +342,9 @@ def move_markdown_pages(
if mdfile_name_to_use in files_to_rename:
mdfile_name_to_use = files_to_rename[mdfile_name_to_use]

if cwd and mdfile_name_to_use == "index.md":
mdfile_name_to_use = f"{'_'.join(cwd)}_{mdfile_name_to_use}"

mdfile_outdir = f"{outdir}/{mdfile_name_to_use}"

shutil.copy(mdfile, mdfile_outdir)
Expand All @@ -340,16 +353,16 @@ def move_markdown_pages(
_highlight_md_codeblocks(mdfile_outdir)
_clean_image_links(mdfile_outdir)

# Use Overview as the name for index file.
if mdfile_name_to_use == 'index.md':
# Save the index page entry.
index_page_entry = {
'name': 'Overview',
'href': 'index.md',
}
continue

if not cwd:
# Use Overview as the name for top-level index file.
if 'index.md' in mdfile_name_to_use:
# Save the index page entry.
index_page_entry = {
'name': 'Overview',
'href': 'index.md',
}
continue

# Use '/' to reserve for top level pages.
app.env.markdown_pages['/'].append({
'name': name,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_goldens.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


@pytest.mark.parametrize(
"test_dir", ["handwritten", "gapic-combo", "gapic-auto"]
"test_dir", ["handwritten", "gapic-combo", "gapic-auto", "non-cloud"]
)
def test_goldens(update_goldens, test_dir):
source_dir = Path("tests/testdata") / test_dir
Expand Down
437 changes: 437 additions & 0 deletions tests/testdata/goldens/non-cloud/api.md

Large diffs are not rendered by default.

Loading

0 comments on commit 7ee38d8

Please sign in to comment.