Load.Py
Default load plugin.
!! class
ValidationError class
ValidationError source
class ValidationError(ValueError): ...
!! function
load function
load source
def load(markata: "MarkataMarkdown") -> None: Progress( BarColumn(bar_width=None), transient=True, console=markata.console, ) markata.console.log(f"found {len(markata.files)} posts") post_futures = [get_post(article, markata) for article in markata.files] posts = [post.result() for post in post_futures if post is not None] markata.posts_obj = markata.Posts.parse_obj( {"posts": posts}, ) markata.posts = markata.posts_obj.posts markata.articles = markata.posts
!! function
get_post function
get_post source
def get_post(path: Path, markata: "Markata") -> Optional[Callable]: if markata.Post: post = pydantic_get_post(path=path, markata=markata) return post else: return legacy_get_post(path=path, markata=markata)
!! function
get_models function
get_models source
def get_models(markata: "Markata", error: pydantic.ValidationError) -> List: fields = [] for err in error.errors(): fields.extend(err["loc"]) models = {field: f"{field} used by " for field in fields} for field, model in set( itertools.product( fields, markata.post_models, ), ): if field in model.__fields__: models[field] += f"'{model.__module__}.{model.__name__}'" return models
!! function
pydantic_get_post function
pydantic_get_post source
def pydantic_get_post(path: Path, markata: "Markata") -> Optional[Callable]: try: post = markata.Post.parse_file(markata=markata, path=path) markata.Post.validate(post) except pydantic.ValidationError as e: models = get_models(markata=markata, error=e) models = list(models.values()) models = "\n".join(models) raise ValidationError(f"{e}\n\n{models}\nfailed to load {path}") from e return post
!! function
legacy_get_post function
legacy_get_post source
def legacy_get_post(path: Path, markata: "Markata") -> Optional[Callable]: default = { "cover": "", "title": "", "tags": [], "published": "False", "templateKey": "", "path": str(path), "description": "", "content": "", } try: post: "Post" = frontmatter.load(path) post.metadata = {**default, **post.metadata} post["content"] = post.content except ParserError: return None post = default except ValueError: return None post = default post.metadata["path"] = str(path) post["edit_link"] = ( markata.config.repo_url + "edit/" + markata.config.repo_branch + "/" + post.path ) return post
!! class
MarkataMarkdown class
MarkataMarkdown source
class MarkataMarkdown(Markata): articles: List = []