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

File not found errors caused by blog plugin #13

Open
landmaj opened this issue May 7, 2024 · 16 comments
Open

File not found errors caused by blog plugin #13

landmaj opened this issue May 7, 2024 · 16 comments

Comments

@landmaj
Copy link
Owner

landmaj commented May 7, 2024

Material for MkDocs blog plugin copies markdown files to create excerpts but it does not copy assets alongside them. This causes "file not found" errors.

For context: #11

@landmaj
Copy link
Owner Author

landmaj commented May 7, 2024

There are two ways to solve this:

  1. Find the original file
  2. Allow specifying diagram source directory in config, essentially pointing to assets directory where blog plugin copies all assets

I don't know if the first option is even possible, so number two seems like a more likely solution.

@Karreg
Copy link
Contributor

Karreg commented May 7, 2024

I'm not sure 2. is a good idea. One of the good side of MkDocs versus Jekyll or Hugo, is the ease to target resources without specifying where they are. Especially with preview. Also, it breaks the way the plugin is working now, i.e. handling d2 files as if they were images. It's intuitive.

Isn't there a way to force the sequence of plugin execution? The issue here is that the blog plugin is executed before the d2 plugin.

@landmaj
Copy link
Owner Author

landmaj commented May 7, 2024

I just tested and it wouldn't work anyway since .d2 files are not copied to assets directory. Back to the drawing board.

Your plugin priority suggestion might work, I will test it.

@Karreg
Copy link
Contributor

Karreg commented May 7, 2024

Order is documented here. Note sure we can do much. In my sample, the blog plugin is defined after the d2 plugin, but it's still executed before...

It would be worth the try to open a issue on material, I can do that.

@Karreg
Copy link
Contributor

Karreg commented May 7, 2024

I just tested and it wouldn't work anyway since .d2 files are not copied to assets directory. Back to the drawing board.

Your plugin priority suggestion might work, I will test it.

Oh I missed that! 🤞

@landmaj
Copy link
Owner Author

landmaj commented May 7, 2024

I fixed the issue by rewriting all relative links to absolute links before blog plugin copies the files. I'm not merging it yet because I still need to make sure it doesn't break anything.

https://github.com/landmaj/mkdocs-d2-plugin/pull/15/files

@landmaj
Copy link
Owner Author

landmaj commented May 8, 2024

Please test version 1.4.0rc1 and let me know if it works for you.

@Karreg
Copy link
Contributor

Karreg commented May 12, 2024

Sure, will do and get back to you as soon as possible :)

@Karreg
Copy link
Contributor

Karreg commented May 13, 2024

I have tested it on my blog and it's indeed breaking with other plugins. I have isolated one, the git plugin:

WARNING -  [git-revision-date-localized-plugin] Unable to find a git directory and/or git is not installed. To ignore this error, set option 'fallback_to_build_date: true'
ERROR   -  Error reading page 'blog/index.md': /tmp/tmpor6ev5i5
Traceback (most recent call last):
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs/livereload/__init__.py", line 211, in _build_loop
    self.builder()
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, serve_url=None if is_clean else serve_url, dirty=is_dirty)
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs/commands/build.py", line 310, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs/commands/build.py", line 163, in _populate_page
    page.markdown = config.plugins.on_page_markdown(
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs/plugins.py", line 635, in on_page_markdown
    return self.run_event('page_markdown', markdown, page=page, config=config, files=files)
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs/plugins.py", line 566, in run_event
    result = method(item, **kwargs)
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs_git_revision_date_localized_plugin/plugin.py", line 202, in on_page_markdown
    last_revision_timestamp = self.util.get_git_commit_timestamp(
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 110, in get_git_commit_timestamp
    raise err
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 81, in get_git_commit_timestamp
    git = self._get_repo(realpath)
  File "/home/gitpod/.local/lib/python3.10/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 40, in _get_repo
    self.repo_cache[path] = Repo(path, search_parent_directories=True).git
  File "/home/gitpod/.local/lib/python3.10/site-packages/git/repo/base.py", line 289, in __init__
    raise InvalidGitRepositoryError(epath)
git.exc.InvalidGitRepositoryError: /tmp/tmpor6ev5i5
ERROR   -  [15:16:13] An error happened during the rebuild. The server will appear stuck until build errors are resolved.

I don't understand how the d2 plugin version could impact the path for the git plugin to find the git binary, but with version 1.3.3 it's working fine.

I have updated the test project to get the 1.4.0rc1 version and activate the git plugin: https://github.com/Karreg/mkdocs-d2-plugin-playground

To test with the previous version, you just need to force the version to 1.3.3 and call .devcontainer/post_attach.sh again, that is if you are using the devcontainer...

@landmaj
Copy link
Owner Author

landmaj commented May 13, 2024

It's probably because I had to change abs_src_path and it no longer points to a git directory. I guess the solution would be to execute my plugin as late as possible but before the blog plugin.

@landmaj
Copy link
Owner Author

landmaj commented May 13, 2024

Yup, I was right - squidfunk/mkdocs-material#5336

@landmaj
Copy link
Owner Author

landmaj commented May 13, 2024

Changing plugin execution order does not solve the issue and I can't find a way to alter the Markdown without affecting other plugins, because files created by the blog plugin during on_files event have placeholder content. I started a discussion in the Material for MkDocs repo.

@Karreg
Copy link
Contributor

Karreg commented May 14, 2024

It's probably because I had to change abs_src_path and it no longer points to a git directory. I guess the solution would be to execute my plugin as late as possible but before the blog plugin.

Maybe you can change it before executing your plugin, and set it back to its previous value just after? This way you don't have effect on other plugins, and whatever the order as long as it's before the blog plugin?

@Karreg
Copy link
Contributor

Karreg commented May 14, 2024

I will check if the issue happens with drawio too. If not, maybe they have a way to work around this issue.

@Karreg
Copy link
Contributor

Karreg commented May 14, 2024

I confirm the issue is also there with the drawio exporter. With blog plugin, image generation is broken, without blog plugin, it's working.

(I have added it to the playground project)

@Karreg
Copy link
Contributor

Karreg commented May 14, 2024

Wouldn't this setup interesting to work around the issue? squidfunk/mkdocs-material#5336 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants