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

πŸ₯³ Material for MkDocs 9.2 – Beta #5686

Closed
28 tasks done
squidfunk opened this issue Jul 6, 2023 · 69 comments Β· Fixed by #5683
Closed
28 tasks done

πŸ₯³ Material for MkDocs 9.2 – Beta #5686

squidfunk opened this issue Jul 6, 2023 · 69 comments Β· Fixed by #5683
Labels
announcement Issue announces news or new features

Comments

@squidfunk
Copy link
Owner

squidfunk commented Jul 6, 2023

With the help of our awesome sponsors, I'm happy to announce that the 'Piri Piri' funding goal has been reached, which means that amongst other awesome features, the built-in blog plugin is finding its way into the community edition!

If you experience any problems, for now, please report them as a comment in this issue.

Installation

pip install mkdocs-material==9.2.0b3

Note – This is a beta release, so please test thoroughly before deploying to production.

Changes

Beta 0

  • Added blogging support via built-in blog plugin
  • Added Chinese language support to built-in search plugin
  • Added support for annotations (outside of code blocks)
  • Added support for navigation icons
  • Added support for navigation pruning
  • Added support for navigation status
  • Added support for customizing site icons
  • Improved rendering of (code) annotation markers
  • Improved print styles for (code) annotations
  • Improved customizability of navigation tabs
  • Removed Universal Analytics integration
  • Removed ancient polyfills to reduce size of bundled JavaScript by 20%

Beta 1

  • Automatically download ResizeObserver polyfill when necessary – 54bef7b
  • Removed necessity for Array.flat and Array.flatMap polyfill – b37c668
  • Fixed announcement bar button being visible when JavaScript is not available – 320c852
  • Added support for customizing (code) annotation icons – f64d865
  • Added focus outline to admonitions and details – 3e34f6c

Beta 2

  • Fixed rendering of tags when announcement bar is present – ef448ed
  • Improved plugin inter-op with external tools like mike – ab178b2
  • Updated MkDocs to 1.5.0 – 571f129

Beta 3

  • Added support for adding date of last update to blog posts
  • Fixed #5599: Insufficient contrast for default link color

Final

  • Fixed #5826: Blog post drafts with tags show up in tags index – 15c024c
  • Tags index renders links to excluded pages – 15c024c
  • Switched info plugin to importlib to mitigate deprecations – 0be6172
  • Automatically focus and bring up keyboard on touch devices – 50f455e
  • Added prompt for bug report name to info plugin – 554976f
  • Added Luxembourgish translations – 245278b

Upgrading

Changes to mkdocs.yml

None.

Changes to customizations

If you've customized Material for MkDocs with theme overrides, and added your own partials, you need to update the following partials, as they got updated with new functionality. If you don't update them, you'll not be able to use some of the new features:

You can check the full list of changes here:
https://github.com/squidfunk/mkdocs-material/pull/5683/files

Closing thoughts

We're super happy to finally give the built-in blog plugin into the hands of all users, so we can improve it even more. Before issuing the final release, we'll take the opportunity to refactor some edges that need a little polishing and incorporate your feedback.

❀️ ❀️ ❀️

Thanks again to all of our awesome sponsors for making our work on this project possible in the first place! Without you, all of those features would not exist. We hope for your continued support, as it allows us to ship more useful and unique features, like for example the latest improved social plugin, which allows to build entirely custom social cards.

@squidfunk squidfunk pinned this issue Jul 6, 2023
@squidfunk squidfunk changed the title Material for MkDocs 9.2 – Beta πŸ₯³ Material for MkDocs 9.2 – Beta Jul 6, 2023
@squidfunk squidfunk linked a pull request Jul 7, 2023 that will close this issue
@squidfunk squidfunk added the announcement Issue announces news or new features label Jul 7, 2023
@HonkingGoose
Copy link
Contributor

  • Added support for navigation pruning

I tried the 9.2 beta on my simple Git Gosling site, and enabled navigation pruning. The beta "feels slower to load new pages" compared to the production deployment, which uses the latest non-beta. To confirm the new beta slowed things down, I had the beta in production for a short while, which still felt slower than normal.

I don't know how I can quantify this slowdown, or if there really is a slowdown. Or maybe navagation pruning slows down the instant page loading feature.

@squidfunk
Copy link
Owner Author

@HonkingGoose Thanks for the feedback. That's surprising and "feels slower" is hard to quantify. However, there might always be side effects between features, and given that Material for MkDocs has a gazillion of them, anticipating all possible side effects is quite an impossible task. If you deploy the beta without enabling any new features, does it also "feel slower"? Could you try to quantify the slowness? Does the side load longer? Also, what version did you have in production before? I read that you have instant loading enabled, which got a complete rewrite 4 months ago in 9.1.4. Without knowing exactly what changes you applied, we can only guess – as always 😊

If you find the time, a side-by-side comparison with runnable examples would be amazing. I'm sure we can mitigate the issues that you now observe. Additionally, Beta 1 will ship a 20% smaller JavaScript bundle, so our general expectation is that 9.2.0 will feel faster than before. Furthermore, navigation pruning should not impact instant loading in any way. It should actually even speed it up, because the pages to download are smaller due to reduced navigation. Finally, you should measure if navigation pruning is actually benefiting your site, as it hugely depends on your navigation structure.

@vedranmiletic
Copy link
Contributor

I don't know how I can quantify this slowdown, or if there really is a slowdown.

Have you tried measuring the performance via the Network tab in Firefox/Chrome developer tools?

@HonkingGoose
Copy link
Contributor

@HonkingGoose Thanks for the feedback. That's surprising and "feels slower" is hard to quantify. However, there might always be side effects between features, and given that Material for MkDocs has a gazillion of them, anticipating all possible side effects is quite an impossible task. If you deploy the beta without enabling any new features, does it also "feel slower"? Could you try to quantify the slowness? Does the side load longer? Also, what version did you have in production before? I read that you have instant loading enabled, which got a complete rewrite 4 months ago in 9.1.4. Without knowing exactly what changes you applied, we can only guess – as always 😊

Production is currently using these dependencies:

mkdocs-material==9.1.18
mkdocs==1.4.3
Select me to see production mkdocs.yml file
# yaml-language-server: $schema=https://squidfunk.github.io/mkdocs-material/schema.json

site_name: Git Gosling

strict: true

repo_name: HonkingGoose/git-gosling
repo_url: https://github.com/HonkingGoose/git-gosling
edit_uri: edit/main/docs/

theme:
  name: material

  icon:
    repo: fontawesome/brands/github

  features:
    - navigation.top
    - navigation.instant
    - toc.integrate
    - toc.follow
    - content.action.edit
    - navigation.footer

  palette:
    - media: "(prefers-color-scheme: light)"
      scheme: default
      primary: indigo
      accent: indigo
      toggle:
        icon: material/weather-night
        name: Switch to dark mode

    - media: "(prefers-color-scheme: dark)"
      scheme: slate
      primary: light blue
      accent: light blue
      toggle:
        icon: material/weather-sunny
        name: Switch to light mode

markdown_extensions:
  - admonition
  - pymdownx.superfences
  - pymdownx.highlight
  - abbr
  - pymdownx.snippets:
      auto_append:
        - includes/abbreviations.md

nav:
  - Home: "index.md"
  - Git Basics:
      - "git_basics/short_introduction_to_git.md"
  - Getting Started:
      - "getting_started/conventions.md"
      - "getting_started/installing_git.md"
      - "getting_started/create_a_github_account.md"
      - "getting_started/configuring_git.md"
      - "getting_started/getting_help_with_git.md"
  - The Nano text editor:
      - "the_nano_text_editor/introduction_to_the_nano_text_editor.md"
  - Git Sandbox:
      - "git_sandbox/setup_your_git_sandbox.md"
      - "git_sandbox/shell_expansion.md"
      - "git_sandbox/explore_your_git_sandbox.md"
      - "git_sandbox/introduction_to_git_status.md"
      - "git_sandbox/create_a_new_file_and_track_it.md"
      - "git_sandbox/making_your_first_commit.md"
      - "git_sandbox/add_extra_lines_to_file.md"
      - "git_sandbox/use_git_restore_to_undo_things.md"
      - "git_sandbox/create_a_new_branch.md"
      - "git_sandbox/switching_between_branches.md"
      - "git_sandbox/your_first_merge.md"
      - "git_sandbox/create_your_first_github_repo.md"
      - "git_sandbox/editing_a_file_on_github.md"
      - "git_sandbox/merge_pull_request.md"
      - "git_sandbox/fetching_changes_merging_git_pull.md"
      - "git_sandbox/check_the_repository_history_with_git_log.md"
  - Recommendations:
      - "recommendations/use_a_gitignore_file.md"
      - "recommendations/split_up_your_commits.md"
      - "recommendations/write_good_commit_messages.md"
      - "recommendations/git_aliases.md"
      - "recommendations/use_a_linter.md"
      - "recommendations/dealing_with_merges.md"
      - "recommendations/use_a_dependency_bot.md"
      - "recommendations/testing_and_github_actions.md"
  - Advanced Topics:
      - "advanced_topics/working_with_large_files.md"
      - "advanced_topics/advanced_git_configuration.md"
      - "advanced_topics/contribute_to_a_project_by_forking.md"
      - "advanced_topics/clean_up_your_git_history.md"
      - "advanced_topics/use_git_bisect_to_find_bugs.md"
      - "advanced_topics/github_cli.md"
  - Further Resources:
      - "further_resources/recommended_reading.md"
  - License: "license.md"

I created three branches on my git-gosling repository:

  1. reproduction/current-production-frozen-branch, this is my current production site with mkdocs-material==9.1.18
  2. reproduction/material-for-mkdocs-beta-nine-two where I only upgrade to 9.2.0b0
  3. reproduction/upgrade-and-navigation-pruning with the upgrade to 9.2.0b0 plus enabling navigation pruning

The easiest way to test is to use GitHub Codespaces or Gitpod, or you may use a local environment.

Run make to install the dependencies, then after run make serve to get the preview site. You may also combine both steps with make && make serve.

@squidfunk
Copy link
Owner Author

Thanks for the reproductions.

Have you tried measuring the performance via the Network tab in Firefox/Chrome developer tools?

Jup, this is exactly what we need. Some numbers would be amazing, because "feels slow" is not really quantifiable for us. Happy to help, and Material for MkDocs should feel fast at all times, but we need more data 😊

@Valastiri
Copy link

Valastiri commented Jul 11, 2023

Thanks for the reproductions.

Have you tried measuring the performance via the Network tab in Firefox/Chrome developer tools?

Jup, this is exactly what we need. Some numbers would be amazing, because "feels slow" is not really quantifiable for us. Happy to help, and Material for MkDocs should feel fast at all times, but we need more data 😊

I'm unsure if this would be immediately helpful since it's an entirely different project but did a test in a local env using 9.1.18 and 9.2.0b0 with network tab just as a sanity check.

Anecdotally i didn't experience any difference in navigation even on our staging build on vercel. Although I figured a local test would be better to showcase.

Local System

W10
Python 3.10.0 
requirements.txt

mkdocs-material==9.2.0b0 # or set to whatever is required for build
mkdocs-awesome-pages-plugin
mkdocs-git-revision-date-localized-plugin
mkdocs-redirects
mkdocs-embed-external-markdown
mkdocs-video
mkdocs-glightbox
pillow
cairosvg
urllib3<2.0

Page Sample

This is a sample of the page that was loaded and associated navigation strcuture:
image

We are using awesome-pages plugin for our navigation though.

Network tab in Chrome


9.1.18 Local Build
reg-speed

9.2.0b0 Local Build
beta-speed


No Cache

9.1.18 Local Build
reg-nch-speed

9.2.0b0 Local Build
beta--nch-speed

@squidfunk
Copy link
Owner Author

@Valastiri thanks for the benchmarks! What I read from that (no cache case):

  • DOMContentLoaded is faster: 343ms -> 317ms (-8%)
  • Load is faster: 493ms -> 417ms (-16%)

We are using awesome-pages plugin for our navigation though.

That is only relevant during build time, since it assemble your nav entry automatically, but shouldn't have any penalty when navigating in the browser.

@Valastiri
Copy link

Yes apologies I forgot to summarize! It does indeed have better performance based on my tests and I couldn't replicate any perceived slowdowns.

Great to feature to have looking forward to release!

@johnthagen
Copy link
Contributor

@squidfunk Excited for the new page icon support.

Is it possible to use a custom icon? We have a bunch of custom SVG icons that we use in our application and mirror in the user guide.

What I'm imaging is passing a relative path to a small SVG file:

---
icon: ../static/icons/icon.svg
---

Thanks for the consideration!

@squidfunk
Copy link
Owner Author

@johnthagen yes, of course, just set up additional icons and you're good to go!

@johnthagen
Copy link
Contributor

@squidfunk Wow, yep!

In case it is helpful, I might suggest a small admonition/link back to that page from these pages to help others discover it:

Thank you! ❀️

@johnthagen
Copy link
Contributor

@squidfunk Some more feedback, we used to host our custom SVG icons as static files, and we could use them both in the body and page titles so that they would show up at the top of the page next to the title.

When we moved to overrides, we to change the image path from a path to a static folder within docs to the new overrides:

![][custom_icon]{ width=36 } Title

[custom_icon]: ../../overrides/.icons/custom/icon.svg

But this produces a warning:

WARNING  -  Documentation file 'pages/page.md' contains a link to '../overrides/.icons/custom/icon.svg' which is not found in the documentation files.

If we change to

  - pymdownx.emoji:
      emoji_index: !!python/name:materialx.emoji.twemoji
      emoji_generator: !!python/name:materialx.emoji.to_svg
      options:
        custom_icons:
          - overrides/.icons
# :custom-icon: Title

Then the page renders properly (the emoji is in the Title block), but the emoji identifier is in the navigation bar:

Screen Shot 2023-07-11 at 9 14 40 AM

Should emoji identifiers be stripped from the navigation bar?

@squidfunk
Copy link
Owner Author

Using the custom icon integration with the :icon-name: shortcode is the way to go. Regarding icons not showing up in the navigation, you currently have two options:

@johnthagen
Copy link
Contributor

johnthagen commented Jul 11, 2023

Thank for the information and tips.

One other observation I noticed when refactoring to use custom icons, is that :icon-name:'s are stripped from the right hand side table of contents navigation, which is nice, as they can be used within ## section headings without cluttering the table of contents.

Otherwise, you can use the regular page icon integration, which will place the icon left of the title

So that I'm clear, I was trying to use both the new icon: integration and also show the user the icon in the title heading in the page itself, without that :...: showing up in the left side navigation. I can totally understand why this isn't supported out of the box (looks like maybe with typeset in insiders), but I just wanted to make sure I was explaining clearly what I was trying to do.

As always, Material for Mkdocs is awesome. Thank you.

@squidfunk
Copy link
Owner Author

@johnthagen you can override the navigation title, removing the icon code from it, and then set the icon via metadata as well – without the typeset plugin, this is likely going to be the best option:

---
title: Document title
icon: material/pencil
---

# :material-pencil: Document title
...

I agree that this looks a little redundant, but it allows us to annotate the page with a distinct icon, which we can also use in the new social plugin's cards and other parts of the site, e.g.:

diagrams

@johnthagen
Copy link
Contributor

@squidfunk That worked, thanks!

@vedranmiletic
Copy link
Contributor

@squidfunk I think tag styling got broken, but only on individual pages and not on tag index. E.g.

If that would help, I can produce a minimal example for reproduction, optionally in a separate bug report.

@squidfunk
Copy link
Owner Author

@vedranmiletic a reproduction would be great, you can just post it here, thanks!

@vedranmiletic
Copy link
Contributor

Working on it. By the way, unrelated, but when I added - blog under plugins: while mkdocs serve is runing, I got:

INFO     -  [16:11:00] Detected file changes
INFO     -  Building documentation...
Traceback (most recent call last):
  File "/home/vedranm/software/mkdocs-venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/mkdocs/__main__.py", line 234, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 116, in serve
    server.serve()
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/mkdocs/livereload/__init__.py", line 162, in serve
    self._build_loop()
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/mkdocs/livereload/__init__.py", line 184, in _build_loop
    func()
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 76, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 270, in build
    config = config.plugins.run_event('config', config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/mkdocs/plugins.py", line 520, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vedranm/software/mkdocs-venv/lib/python3.11/site-packages/material/plugins/blog/plugin.py", line 128, in on_config
    if self.is_serve and self.config.draft_on_serve:
       ^^^^^^^^^^^^^
AttributeError: 'BlogPlugin' object has no attribute 'is_serve'. Did you mean: 'on_serve'?

Running mkdocs serve afterwards works fine.

@vedranmiletic
Copy link
Contributor

Interesting, minimal example that enables blog plugin doesn't fail. I will need to dig deeper to find out what combination of plugins/features results in this, but for now I noticed that wrongly styled tags use md-tagmaterial/close class, while correctly styled tags use md-tag.

@vedranmiletic
Copy link
Contributor

@squidfunk Here's a minimal example. Overriding announce block via custom_dir and enabling announce.dismiss feature causes the issue with tags; other features and plugins don't matter. I checked and, to the best of my knowledge, you didn't change anything related to the main.html template that would require the changes to the overrides.

Finally, this is a regression from 9.1.8 and it doesn't have anything to do with the blog plugin. (The other issue with blog plugin and serve I described two comments above still stands, of course.)

Minimal example: unstyled-tags.tar.gz

@squidfunk
Copy link
Owner Author

squidfunk commented Jul 18, 2023

Thanks for investigating! If it also happens on 9.1.x, then please create a new issue. This issue is reserved for everything related to the 9.2 and the new beta release. Regarding your other issue:

but when I added - blog under plugins: while mkdocs serve is runing, I got:

This is because when you add configuration while MkDocs is running, the on_startup hook in the plugin is not executed, which is the only place to detect whether you're serving or not before doing a full build. Thus, it is nothing we can fix, and the issue disappears when the server is restarted. You can raise this to the maintainers of MkDocs if you want.

@vedranmiletic
Copy link
Contributor

@squidfunk sorry, I might have not been clear enough. The issue with tag display is a regression compared to 9.1.8, i.e. it does not occur on 9.1.8 and it does occur in 9.2.0b0.

@squidfunk
Copy link
Owner Author

Okay thanks, does it also not occur on 9.1.18? 9.1.8 is quite old.

@vedranmiletic
Copy link
Contributor

I am using Beta 2 (9.2.0b2) and using the search plugin raises this error:

Traceback (most recent call last):
  File "/opt/python/3.10.8/lib/python3.10/site-packages/mkdocs/livereload/__init__.py", line 189, in _build_loop
    func()
  File "/opt/python/3.10.8/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 79, in builder
    build(config, live_server=None if is_clean else server, dirty=is_dirty)
  File "/opt/python/3.10.8/lib/python3.10/site-packages/mkdocs/commands/build.py", line 354, in build
    config.plugins.on_post_build(config=config)
  File "/opt/python/3.10.8/lib/python3.10/site-packages/mkdocs/plugins.py", line 542, in on_post_build
    return self.run_event('post_build', config=config)
  File "/opt/python/3.10.8/lib/python3.10/site-packages/mkdocs/plugins.py", line 509, in run_event
    result = method(**kwargs)
  File "/opt/python/3.10.8/lib/python3.10/site-packages/material/plugins/search/plugin.py", line 124, in on_post_build
    if self.is_dirty:
AttributeError: 'SearchPlugin' object has no attribute 'is_dirty'

To save time, I'm going to ask what I am sure @squidfunk will ask, can you provide a minimal reproduction?

@squidfunk
Copy link
Owner Author

Yes, please provide a minimal reproduction. You can attach it here, you don't need to create a new issue for now.

@jake-anto
Copy link

After rebooting my computer, the issue seems to have resolved itself. Sorry for wasting your time.

@squidfunk
Copy link
Owner Author

No worries, I think I know where this is coming from. It should only happen if you add the search plugin during serve mode. If you restart mkdocs build, it should work again. We'll fix this issue as well.

@squidfunk
Copy link
Owner Author

squidfunk commented Aug 3, 2023

9.2.0b3 was just released. Upgrade with:

pip install mkdocs-material==9.2.0b3

@usulpt
Copy link

usulpt commented Aug 9, 2023

hello! I'm having a weird behavior using navigation.prune, where an internal folder is opened when it's parent folder is selected through the menu. I am attaching a minimal example but I'm unsure as to whether the problem is related to material for mkdocs or awesome-pages, in any case it only started happening after I moved to the beta and used prune (which, by the way, is a life saver) so I decided to post it here under the beta discussion. thanks in advance!
minimal-example.zip

@squidfunk
Copy link
Owner Author

@usulpt we need a reproduction without awesome pages, since we don't have official support for it. Please create a new issue and create a reproduction that does not use awesome pages, so we're sure that the bug is on our side 😊

@usulpt
Copy link

usulpt commented Aug 10, 2023

I found a workaround using awesome-pages and I tried reproducing the issue without awesome-pages and it works fine. sorry to bring this up, carry on the great work! :)

@squidfunk
Copy link
Owner Author

Perfect! Could you please share a little about the problem with awesome pages and the workaround you found? Other users might be impacted, too, so you will do them a great favor ☺️

@usulpt
Copy link

usulpt commented Aug 10, 2023

will do! :)

@squidfunk
Copy link
Owner Author

Update: just to let all of you know, I'm currently doing a deep refactor of the blog plugin to address the remaining issues, primarily remove the limitation that a nav entry must be set to use the blog. This should make it compatible with awesome pages and other plugins. Additionally, MkDocs 1.5 made handling of generated pages much simpler. As the blog plugin has roughly a thousand lines of code, this might take some additional time. No breaking changes in configuration or usage are expected, except for when you customized the templates – those will undergo a refactor as well.

@sheldonhull
Copy link

@squidfunk thanks for this. I was about to report this issue as well on the nav element being required after beating my head against this in a dockerized build for a few hours. The lack of need to specify nav is one of my favorite features for the more complex docs.

I did run into one other behavior and I'm not certain it's expected. Putting under summary section to avoid noise. Please advise if I should open a new discussion or if this is relevant to beta release.

details on the blog posts slug issue I've run into

I try to keep my blog very level in url.
So for instances, the url slug for all my blog posts has no blog prefix. It's just a sheldonhull.com/my-post not sheldonhull.com/blog/my-post. I took this advice from a tech blogger and have found it helpful especially when I reorg physical structure of the posts.

While I see the ability to set the blog directory as ., I think that prohibits me from placing my content in a posts subdirectory. The url schema can eliminate the date prefix, but it assumes the blog/posts prefix from what I see.

For now I can move this to a new discussion item if the behavior is intentional, but thought I'd mention as it impacts the url structure for adoption for me at least.

The posts below are all served with sheldonhull.com/slug no prefix, but you can see I store them in an organized directory structure to avoid having to dig through many posts each year.

image

@squidfunk
Copy link
Owner Author

squidfunk commented Aug 15, 2023

@sheldonhull I'm currently rewriting the plugin from the ground up and the navigation issue is already fixed - there are now no limitations to where you place the blog, or whether you specify nav or not. Please give me some more days to finish the refactoring, since the blog plugin has quite a large code base. The refactored version will also improve interop with other plugins, so they can inspect and alter posts and indexes in any way they like.

Regarding the issue with slugs – you should set blog_dir to . and then put your posts in docs/posts. You can then also put arbitrary pages in docs at locations you wish – the posts directory is essentially just a storage location for pages that are treated as blog posts, and whose URLs are all dynamically computed. Everything else is left untouched. Example:

.
β”œβ”€ docs/
β”‚  β”œβ”€ posts/
β”‚  β”‚  └─ hello-world.md 
β”‚  β”œβ”€ reference/
β”‚  β”‚  β”œβ”€ index.md  # example.com/reference/
β”‚  β”‚  β”œβ”€ foo.md    # example.com/reference/foo/
β”‚  β”‚  └─ bar.md    # example.com/reference/bar/
β”‚  β”œβ”€ baz.md       # example.com/baz/
β”‚  └─ index.md     # example.com/
└─ mkdocs.yml

Note that when there's no blog prefix, you must make sure that your slugs don't collide with URLs of other pages.

@squidfunk
Copy link
Owner Author

Additionally, for the sake of completeness: you can organize your posts as you like – everything in the posts directory receives a computed URL based on the schemes configured, which means that the directory structure is not relevant. This allows you to group your posts as you like, which will also give you the ability to use the meta plugin intelligently.

@do-me
Copy link

do-me commented Aug 16, 2023

Thanks a lot for all the work you put in the blog feature, this is so awesome! For me, mkdocs-material now has finally become a real hugo/jekyll alternative.

I guess this might be the right issue to mention a few missing translation options for the blog. The docs currently only mention easy translation of these parts:

  - blog:
      categories_name: Categories
      archive_name: Archive

but the following are missing (afaik):

image

I guess I could just modify the templates, but it doesn't feel right as the other settings are located in the mkdocs.yml too.

@squidfunk
Copy link
Owner Author

squidfunk commented Aug 16, 2023

Those translations are provided as part of localizations:

"blog.archive": "Archive",
"blog.categories": "Categories",
"blog.categories.in": "in",
"blog.continue": "Continue reading",
"blog.draft": "Draft",
"blog.index": "Back to index",
"blog.meta": "Metadata",
"blog.references": "Related links",

"readtime.one": "1 min read",
"readtime.other": "# min read",

You can override them easily, as mentioned in our docs.

@do-me
Copy link

do-me commented Aug 16, 2023

Thanks for the links!
So the idea is that the options in mkdocs.yml for categories and archive are rather for convenient renaming (e.g. "themes/topics" or similar) than actual translation. Translations should then always go in mkdocs-material/src/partials/languages/ if I get it right.

@squidfunk
Copy link
Owner Author

Yes, exactly, both options are regarded as content and not part of the site structure. They are also part of the translations, so that we can provide good defaults per language. In German, the default will be "Archiv" and "Kategorien".

@ofek
Copy link
Sponsor Collaborator

ofek commented Aug 16, 2023

Hey! We just deployed using the beta and I think perhaps something related to CSS changed https://datadoghq.dev/integrations-core/

The site should be using our branded purple color but it seems like it is not. Did something change that I missed?

@squidfunk
Copy link
Owner Author

@ofek What did you use before? There were no recent changes from 9.1 to 9.2 that could explain the behavior. Looking at your CSS; it looks like you're coming from an older version. You need to adjust the selector when overriding primary colors. This was changed in 8.5.10 (see diff) which was released 9 months ago.

@ofek
Copy link
Sponsor Collaborator

ofek commented Aug 16, 2023

That was it indeed; thank you and sorry for the noise!

@squidfunk
Copy link
Owner Author

No worries, it was a necessary change to make color customization easier, and there are probably some installations (like yours) out there that need updating. However, we can't do a major release for every little bit of customization we change, or we would be at v237 already πŸ˜… Glad we could sort it out so quickly

@squidfunk
Copy link
Owner Author

Material for MkDocs 9.2.0 was just released! It brings many new capabilities and fixes some long standing bugs.

Thank you all for testing the beta releases and for your patience ❀️

@squidfunk squidfunk unpinned this issue Aug 21, 2023
@TimChaubet-I4U
Copy link

TimChaubet-I4U commented Nov 21, 2023

No worries, I think I know where this is coming from. It should only happen if you add the search plugin during serve mode. If you restart mkdocs build, it should work again. We'll fix this issue as well.

This is still an issue in the container version of mkdocs (tested today 2023-11-21).
We fixed it by putting build & serve in the startup script of docker compose.

version = "9.4.8" (material)
mkdocs, version 1.5.3 from /usr/local/lib/python3.11/site-packages/mkdocs (Python 3.11)

@squidfunk
Copy link
Owner Author

squidfunk commented Nov 21, 2023

@TimChaubet-I4U Sorry, I don't know what you mean (I haven't skimmed through all comments here and the quote does not provide enough context). If you're referring to #6364, this is fixed on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
announcement Issue announces news or new features
Projects
None yet
Development

Successfully merging a pull request may close this issue.