#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""manage blogs"""
import hashlib
import os
import random
import string
import sys
import xml.etree.ElementTree as etree
from datetime import datetime
from glob import iglob
from html import escape as html_escape
from re import Match as RegexMatch
from shutil import copy as copy_file
from shutil import rmtree
from tempfile import gettempdir
from threading import Thread
from timeit import default_timer as code_timer
from typing import (Any, Callable, Collection, Dict, List, Optional, Set,
Tuple, Union)
from urllib.parse import quote as encode_url
from warnings import filterwarnings as filter_warnings
import ujson # type: ignore
from css_html_js_minify import html_minify # type: ignore
from css_html_js_minify import process_single_css_file # type: ignore
from markdown import core as markdown_core # type: ignore
from markdown import markdown # type: ignore
from markdown.extensions import Extension # type: ignore
from markdown.inlinepatterns import InlineProcessor # type: ignore
from markdown.treeprocessors import Treeprocessor # type: ignore
from plumbum.commands.processes import ProcessExecutionError # type: ignore
from pyfzf import FzfPrompt # type: ignore
from readtime import of_markdown as read_time_of_markdown # type: ignore
__version__: int = 1
NOT_CI_BUILD: bool = not os.getenv("CI")
if NOT_CI_BUILD:
import readline
from atexit import register as fn_register
EXIT_OK: int = 0
EXIT_ERR: int = 1
DEFAULT_CONFIG: Dict[str, Any] = {
"editor-command": f"{os.environ.get('EDITOR', 'vim')} -- %s",
"blog-dir": "b",
"git-url": "/git",
"py-markdown-extensions": [
"markdown.extensions.abbr",
"markdown.extensions.def_list",
"markdown.extensions.fenced_code",
"markdown.extensions.footnotes",
"markdown.extensions.md_in_html",
"markdown.extensions.tables",
"markdown.extensions.admonition",
"markdown.extensions.sane_lists",
"markdown.extensions.toc",
"markdown.extensions.wikilinks",
"pymdownx.betterem",
"pymdownx.caret",
"pymdownx.magiclink",
"pymdownx.mark",
"pymdownx.tilde",
],
"default-keywords": ["website", "blog", "opinion", "article", "ari-web", "ari"],
"page-title": "Ari::web -> Blog",
"page-description": "my blog page",
"colourscheme-type": "dark",
"short-name": "aris blogs",
"home-keywords": ["ari", "ari-web", "blog", "ari-archer", "foss", "free", "linux"],
"base-homepage": "https://ari-web.xyz/",
"meta-icons": [{"src": "/favicon.ico", "sizes": "128x128", "type": "image/png"}],
"theme-colour": "#f9f6e8",
"background-colour": "#262220",
"full-name": "Ari Archer",
"locale": "en_GB",
"home-page-header": "my blogs",
"comment-url": "/c",
"recents": 16,
"visitor-count": "/visit",
"rss-feed": "rss.xml",
"page-url": "https://blog.ari-web.xyz/",
"blogs": {},
}
DEFAULT_CONFIG_FILE: str = "blog.json"
HISTORY_FILE: str = ".blog_history"
CONTEXT_WORDS: Tuple[str, ...] = (
"the",
"a",
"about",
"etc",
"on",
"at",
"in",
"by",
"its",
"i",
"to",
"my",
"of",
"between",
"because",
"of",
"or",
"how",
"to",
"begin",
"is",
"this",
"person",
"important",
"homework",
"and",
"cause",
"how",
"what",
"for",
)
BLOG_MARKDOWN_TEMPLATE: str = """%s