💾 Archived View for republic.circumlunar.space › users › luminar › scripts › prepublish.py captured on 2024-07-09 at 03:11:17.

View Raw

More Information

⬅️ Previous capture (2020-10-31)

-=-=-=-=-=-=-

#! scripts/venv/bin/python

"""This scripts contains some cosmetic operations that should be done to each
post before publishing to the gemlog."""

import textwrap
from pathlib import Path
from typing import Callable


def add_footer(text: str) -> str:

    footer = textwrap.dedent(
        """\

        \u2343

        => .. BACK
        """
    )

    return text + footer


def em_dash(text: str) -> str:

    return text.replace("--", "\u2014")


def double_space(text: str) -> str:

    return text.replace("  ", " ")


def apply(text: str, *functions: Callable) -> str:

    for fun in functions:
        text = fun(text)

    return text


def main(file_path: Path):

    text = file_path.read_text()
    updated = apply(text, em_dash, double_space, add_footer)
    file_path.write_text(updated)


if __name__ == "__main__":

    import sys

    if len(sys.argv) > 1:
        main(Path(sys.argv[-1]))
    else:
        exit("Provide a path to file")