summary.py


Run it


python -m markata.cli.summary

Configuration

There are two main things currently supported by summary, It can count the number of posts based on a filter (filter_count'), and it can automatically list all the values of an attribute and the number of posts that have that attribute (grid_attr`).

grid_attr

grid_attr will map over all posts, find all values for each attribute configured, then report the number of posts for each value.


[markata.summary]
grid_attr = ['tags', 'series']

Example output that will be shown in the summary, counting all posts with each tag value.


TAGS
247  python
90   linux
68   cli
49   kedro
46   bash

filter_counts

filter_count will pass a given filter into markata.map and return the number of posts.


[[markata.summary.filter_count]]
name='drafts'
filter="published == 'False'"
color='red'

[[markata.summary.filter_count]]
name='articles'
color='dark_orange'

[[markata.summary.filter_count]]
name='py_modules'
filter='"plugin" not in slug and "docs" not in str(path)'
color="yellow1"

[markata.summary.filter_count.published]
filter="published == 'True'"
color='green1'

[markata.summary.filter_count.plugins]
filter='"plugin" in slug and "docs" not in str(path)'
color="blue"

[markata.summary.filter_count.docs]
filter="'docs' in str(path)"
color='purple'

Example output might look like this, showing the number of posts that contained within each filter specified.


8 drafts
66 articles
20 py_modules
58 published
38 plugins
8 docs

Function

cli function

Markata hook to implement base cli commands.

cli source


def cli(app: typer.Typer, markata: "Markata") -> None:
    """
    Markata hook to implement base cli commands.
    """
    summary_app = typer.Typer()
    app.add_typer(summary_app, name="summary")

    @summary_app.callback(invoke_without_command=True)
    def summary():
        "show the application summary"
        from rich import print

        markata.console.quiet = True

        print(Summary(markata, simple=True))

Method

get_grid method

create a rich grid to display the summary

get_grid source


def get_grid(self) -> None:
        "create a rich grid to display the summary"
        self.grid = Table.grid(expand=True)

        for filter_count in self.m.config.summary.filter_count:
            self.filter_count(filter_count)

        for attr in self.m.config.summary.grid_attr:
            self.grid_attr(attr)

        return self.grid

Method

filter_count method

add a row in the grid for the number of items in a filter config

filter_count source


def filter_count(
        self,
        fc: FilterCount,
    ) -> None:
        "add a row in the grid for the number of items in a filter config"
        self.grid.add_row(
            f"[{fc.color}]{len(self.m.map(filter=fc.filter))}[/] {fc.name}"
        )

Method

grid_attr method

add attribute the the object grid

grid_attr source


def grid_attr(self, attr: str) -> None:
        "add attribute the the object grid"
        posts = list(
            flatten(
                [
                    tags if isinstance(tags, list) else [tags]
                    for a in self.m.posts
                    if (tags := a.get(attr, None)) is not None
                ],
            ),
        )
        if len(posts) > 0:
            self.grid.add_row()
            self.grid.add_row(f"[bold gold1]{attr.upper()}[/]")
            for post, count in Counter(posts).most_common():
                self.grid.add_row(f"{count} {' ' * (3 - len(str(count)))} {post}")

Function

summary function

show the application summary

summary source


def summary():
        "show the application summary"
        from rich import print

        markata.console.quiet = True

        print(Summary(markata, simple=True))