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

Regression with nav item direct linking to blog post in 4.40.3 #5949

Closed
4 tasks done
perpil opened this issue Sep 3, 2023 · 8 comments
Closed
4 tasks done

Regression with nav item direct linking to blog post in 4.40.3 #5949

perpil opened this issue Sep 3, 2023 · 8 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@perpil
Copy link
Sponsor Contributor

perpil commented Sep 3, 2023

Context

In a recent change, directly linking to a blog post from the nav exhibits strange behavior. The nav link works, but that specific blog post is missing the metadata sidebar and it is excluded from the blog index.

Bug description

On my site, I link to a specific blog entry under a nav entry called Mission. This normally works fine, but in insiders 9.2.7+4.40.3 I get an error: A reference to 'blog/posts/mission.md' is included in the 'nav' configuration, but this file is excluded from the built site. The nav link works, and it shows the blog entry, but it is missing the blog metadata like date and author. Other posts that aren't linked in the nav show up in the blog index, but the mission.md one is missing.

Related links

Reproduction

9.2.7+insiders.4.40.3-blog-entry-in-nav-not-working.zip

Steps to reproduce

  1. mkdocs serve
  2. See the error A reference to 'blog/posts/mission.md' is included in the 'nav' configuration, but this file is excluded from the built site.
  3. Click the Mission nav item, note it does not have metadata
  4. Click the Blog nav item, note there is no entry for the mission blog post.
  5. Click continue reading and note the post called Entry has metadata.

Browser

No response

Before submitting

@squidfunk
Copy link
Owner

squidfunk commented Sep 3, 2023

Thanks for reporting. What was the last version working? I suspect the warning is caused by the latest refactoring of the plugin, which was necessary to make it work with other third-party plugins like awesome-pages or static-i18n. The blog posts must be temporarily excluded, because, otherwise, MkDocs will add all of them to the navigation. This is unusual for blogs, because blog posts are usually linked from paginated indexes.

We already filed an upstream issue 3 weeks ago, so we could mark posts as "not in nav", but not "excluded":

Until the upstream issue is resolved, fixing the problem reported is blocked, because we currently have to hack around it.

@squidfunk squidfunk added bug Issue reports a bug blocked Issue is blocked by another issue labels Sep 3, 2023
@squidfunk
Copy link
Owner

squidfunk commented Sep 3, 2023

Okay, I have an even better idea now. Fixing the issue mentioned in my last comment will fix the warning that is printed. However, the problem that the page is overwritten stems from the fact that MkDocs will ignore that pages are excluded from the navigation when they are linked in the navigation, and always create (= overwrite in case of blog posts) them. In fact, if the following PR that I proposed several days ago gets merged and released, the problem is gone:

@squidfunk
Copy link
Owner

squidfunk commented Sep 3, 2023

Fixed in 3f87fe0. I've extended the temporary hack that works around the limitations mentioned in mkdocs/mkdocs#3366 and fixed by mkdocs/mkdocs#3367 which we already use for the blog entrypoint. Applying them to posts and views fixes the problem for them as well. Once the mentioned PR is merged, the entire part of the code can be removed.

Note that the problem was not exclusive to Insiders, but applies to the community edition blog as well.

@squidfunk squidfunk added resolved Issue is resolved, yet unreleased if open and removed blocked Issue is blocked by another issue labels Sep 3, 2023
@perpil
Copy link
Sponsor Contributor Author

perpil commented Sep 3, 2023

Thanks for the quick fix! I verified it works, but the nav uses the title of the blog post instead of the nav key. I've attached a repro demonstrating this. Is this change in behavior intentional?

In this repro, the nav previously would be set to Mission, now it is set to The Mission Statement

9.2.7+insiders.4.40.3-nav-using-title.zip

Also per your question above about the last known version this was working. According to the metadata in my published site it was working with: mkdocs-1.5.2, mkdocs-material-9.2.3+insiders-4.39.3

@squidfunk
Copy link
Owner

squidfunk commented Sep 3, 2023

Thanks again for the feedback and reproduction.

Also per your question above about the last known version this was working. According to the metadata in my published site it was working with: mkdocs-1.5.2, mkdocs-material-9.2.3+insiders-4.39.3

If you're referring to the post title being set to the nav key – that is weird, because posts never had explicit titles set as they are not meant to be linked in the navigation, so the fact that this worked before was definitely accidental and not intended. The problem is: we can't allow to link posts in the navigation, because we must process posts before the navigation is constructed because several parts of the blog plugin rely on this information.

This is orthogonal to what you're trying to achieve and the reason why the behavior is not in line with what you'd expect from MkDocs. Once mkdocs/mkdocs#3367 is merged, post titles can't be set in the nav at all, and IMHO that is correct. Thus, we're not considering this a bug but undefined behavior as you're outside of what is supported by the blog plugin.

You can work around this restriction by using a relative link:

nav:
  - Blog:
    - blog/index.md 
  - Mission: blog/2023/09/01/the-mission-statement/
validation:
  nav:
    not_found: ignore

@perpil
Copy link
Sponsor Contributor Author

perpil commented Sep 3, 2023

I thought the key in the nav would set the nav text, so I was a bit surprised that it was resolving to the destination title, but the workaround works for me. Thanks!

@squidfunk
Copy link
Owner

Yes, it sets the nav text, for normal pages. Blog posts are not normal pages, they are excluded from the navigation, because that's usually not how blogs work ☺️ We'll clarify this better in our docs. Glad the workaround works for you!

@squidfunk
Copy link
Owner

Released as part of 9.2.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants