-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
BlogPlugin: handling of generated blog posts #7583
base: master
Are you sure you want to change the base?
Conversation
Thanks! Great work! I'm currently tight on time, but I'll try to get back to this |
afe00a2
to
fe49397
Compare
a minimum code generating blog post. Should fail without my changes and work with them POST_CONTENT="""---
date:
created: {date}
tags:
- generated
title: Generated Blog Post
categories:
- test
---
This post is generated
"""
class BlogPostGeneratingPlugin(BasePlugin):
def on_files(self, files: Files, /, *, config: MkDocsConfig) -> Files | None:
file = File.generated(config=config, src_uri="blog/posts/generated.md", content=POST_CONTENT.format(date=datetime.now()))
files.append(file)
return files Same as ready to launch folder with post generating hook And to illustrate the issue PR solves here is the exception mkdocs throws without my changes
|
As it has been discussed in #7545 I've modified
blog
plugin code to handle generated posts.Now if file
Post
instance is being created from generated content, it reads content withfile.string_content
property (Implementation from master branch used to crash in this case since tried to load non existing file from file system).Error messages are also changed to reference path and plugin that has generated the file.
For case where file is loaded form filesystem the behavior and messages are kept as is to ensure backward compatibility.