-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Incompatibility with Mkdocs Material Blog plugin? #283
Comments
I'm having the same error, please help! Big thanks! |
Yes this is a known incompatibility unfortunately, mkdocs-material broke support when they rewrote the blog plugin and I've been unable to fix that since. That's on my TODO list but can't share any ETA tbh. |
I just added an
This makes the build succeed but the blog is still empty. |
I have met the same problem. |
In the Gothic Modding Community we finally decided we need the blog plugin to allow for more flexibility when adding non-documentation pages. We kept putting it off, because of the incompatibility here. However, one of the maintainers mentioned that our website is used primarily by the Here is the extracted hook from all of my hacky changes: Hook"""MkDocs hook that hides the blog files from the i18n plugin
MIT Licence 2024 Kamil Krzyśków (HRY) for Gothic Modding Community (https://gothic-modding-community.github.io/)
"""
from mkdocs import plugins
from mkdocs.structure.files import Files
BLOG_FILES = None
"""
List of files that belong to a blog. They will be temporarily removed and added back to hide them
from the i18n plugin. Set later for mkdocs serve to work properly.
"""
@plugins.event_priority(-95)
def _on_files_disconnect_blog_files(files: Files, config, *_, **__):
"""Disconnect blog files before on_files from the i18n plugin runs (-100) after blog (-50)"""
global BLOG_FILES
BLOG_FILES = []
non_blog_files: list[File] = []
blog_prefixes = []
for name, instance in config.plugins.items():
if name.startswith("material/blog"):
blog_prefixes.append(instance.config.blog_dir)
blog_prefixes = tuple(map(lambda x: x.rstrip("/") + "/", blog_prefixes))
# i18n blog prefix awareness can be used in overrides templates
config.extra.i18n_blog_prefixes = blog_prefixes
for file in files:
if file.src_uri.startswith(blog_prefixes):
BLOG_FILES.append(file)
else:
non_blog_files.append(file)
return Files(non_blog_files)
@plugins.event_priority(-105)
def _on_files_connect_blog_files(files: Files, *_, **__):
"""Breaking the convention of a minimal -100. Restore blog files after i18n on_files"""
for file in BLOG_FILES:
files.append(file)
return files
on_files = plugins.CombinedEvent(_on_files_disconnect_blog_files, _on_files_connect_blog_files) Here is a mini example I tested: Reference: Note I updated the hook above after the initial comment, so please update it if you used it ✌️ |
For the blog I am fine with the default language too so this is really great. Since it occured to me too, you need to update to the latest i18n, mkdocs and material for above script to work. |
@kamilkrzyskow I tried your script, and it can solve the part problem. But it displays blogs in all languages simultaneously. Normally, when I choose English, the page only displays the English version of the blog. I choose Chinese, and the page only displays the Chinese version of the blog. Here is a mini example I tested: |
Hi @SWHL, Currently the i18n plugin doesn't support the blog plugin at all, so it's empty, no posts are shown. ❗ This hook doesn't fix the lack of i18n support for the blog, via this plugin. |
@kamilkrzyskow Thank you for your reply, I did misunderstand. |
Tested with mkdocs-static.i18n 1.2.0 and mkdocs-material 9.5.2-insiders.4.47.1:
Whenever I add the
blog
plugin with a post, I get the following error attempting to runmkdocs serve
:site_url
is definitely set in my mkdocs.yml:janvanveldhuizen has the same issue as per this comment: #268 (comment)
The text was updated successfully, but these errors were encountered: