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

Unexpected behaviour with page.is_homepage #1919

Closed
StarfallProjects opened this issue Dec 7, 2019 · 1 comment · Fixed by #1921
Closed

Unexpected behaviour with page.is_homepage #1919

StarfallProjects opened this issue Dec 7, 2019 · 1 comment · Fixed by #1921
Labels
Milestone

Comments

@StarfallProjects
Copy link

Starting a new site and rolling my own theme. Came across some slightly odd behaviour.

Mkdocs version 1.0.4
Python version 3.7.1

Expected:
page.is_homepage evaluates to True on the home (index.md) of the site, and false on all other pages.

Actual:
page.is_homepage evaluates to True on the home (index.md), and on any other index.md that is included in the nav object without nesting.

Examples:

The unexpected result:

nav:
  - Home: index.md  <--- page.is_homepage evaluates to True
  - About: about.md <--- page.is_homepage evaluates to False
  - Projects: projects/index.md <--- page.is_homepage evaluates to True

Changing the filename causes it to evaluate to false:

nav:
  - Home: index.md  <--- page.is_homepage evaluates to True
  - About: about.md <--- page.is_homepage evaluates to False
  - Projects: projects/test.md <--- page.is_homepage evaluates to False

If I tweak it a bit, so that the sections are nested, then it evaluates to false as I'd expect:

nav:
  - About: 
      - About: about.md <--- page.is_homepage evaluates to False
  - Projects: 
       - Project home: projects/index.md <--- page.is_homepage evaluates to False

This feels like a bug - especially as simply changing the markdown file name causes the behaviour to change.

@waylan
Copy link
Member

waylan commented Dec 7, 2019

Yes, that's a bug. Thanks for the report.

@property
def is_homepage(self):
return self.is_top_level and self.is_index

We are only checking that the page is an index page at the root of the nav and not looking at the path at all. However, we do not require the nav to match the file structure. We simply need to add a check that the path is at the doc_dir root. Perhaps and '/' not in self.url.

@waylan waylan added the Bug label Dec 7, 2019
@waylan waylan added this to the 1.1 milestone Dec 7, 2019
waylan added a commit that referenced this issue Dec 8, 2019
A user could place a nested (in the file structure) index page on the root level of the nav.
That file should not return `True` for `page.is_homepage`. Fixes #1919.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants