From 41ef6b68ef7616b869e5b46a3f6229a42a5efcbf Mon Sep 17 00:00:00 2001 From: Ari Archer Date: Thu, 7 Apr 2022 22:32:55 +0300 Subject: [PATCH] update @ Thu 7 Apr 22:32:55 EEST 2022 Signed-off-by: Ari Archer --- .github/workflows/build.yml | 2 +- README.md | 29 +++++++++++++++++++++++++++++ completions/blog.bash | 12 ++++++++++++ netlify.toml | 2 +- scripts/blog | 31 +++++++++++++++++++++++++------ 5 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 completions/blog.bash diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f721b4e..86df39e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,4 +27,4 @@ jobs: - name: Build static site run: | - python3 scripts/blog static + CI_BUILD=1 python3 scripts/blog static diff --git a/README.md b/README.md index 8ee91aa..ede5b90 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,32 @@ Or ```sh $ python3 -m pip install --user -r requirements.txt ``` + +## Completions + +- Bash + +```bash +$ . completions/blog.bash +``` + +## Building + +- Generate full-on static site + +```bash +$ CI_BUILD=1 ./scripts/blog static +``` + +- Only build blogs + +```bash +$ CI_BUILD=1 ./scripts/blog static +``` + +`CI_BUILD` environment variable is optional, +though setting it in a build/ci environment is good +to save time on some operations that are useless +in that context, for example sorting blogs. + +`CI_BUILD` can have any value. diff --git a/completions/blog.bash b/completions/blog.bash new file mode 100644 index 0000000..ef7c0fb --- /dev/null +++ b/completions/blog.bash @@ -0,0 +1,12 @@ +# blog completion -*- shell-script -*- + +_blog() { + local cur + + _init_completion -s || return + COMPREPLY=($(compgen -W "help new build list\ + rm edit new-config clean metadata static" -- "$cur")) + +} && complete -F _blog -o bashdefault -o default blog + +# ex: filetype=sh diff --git a/netlify.toml b/netlify.toml index f2a713d..1be4839 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,5 +1,5 @@ [build] - command = "python3 ./scripts/blog static" + command = "CI_BUILD=1 python3 ./scripts/blog static" [[redirects]] from = "/git/*" diff --git a/scripts/blog b/scripts/blog index 4707244..beedc88 100755 --- a/scripts/blog +++ b/scripts/blog @@ -223,6 +223,8 @@ def new_blog(config: Dict) -> Tuple[int, Dict]: """Make a new blog""" if title := iinput("blog title"): + readline.add_history(title) + us_title: str = title s_title: str = sanitise_title(us_title, config["blogs"]) @@ -250,10 +252,11 @@ def new_blog(config: Dict) -> Tuple[int, Dict]: if not blog["content"].strip(): # type: ignore return log("Blog cannot be empty"), config + user_keywords: str = iinput("keywords (seperated by spaces)") + readline.add_history(user_keywords) + blog["keywords"] = html_escape( - iinput("keywords (seperated by spaces)") - + " " - + " ".join(config["default-keywords"]) + user_keywords + " " + " ".join(config["default-keywords"]) ) blog["time"] = datetime.now().timestamp() @@ -628,6 +631,8 @@ def main() -> int: readline.read_history_file(HISTORY_FILE) readline.set_history_length(5000) + readline.set_auto_history(False) + if not os.path.isfile(DEFAULT_CONFIG_FILE): new_config() return EXIT_ERR @@ -649,8 +654,13 @@ def main() -> int: "TIME", ) - if config["blogs"]: + not_ci_build = not os.getenv("CI_BUILD") + + if config["blogs"] and not_ci_build: log("Sorting blogs by creation time...", "CLEANUP") + + sort_timer = code_timer() + config["blogs"] = dict( map( lambda k: (k, config["blogs"][k]), @@ -658,8 +668,17 @@ def main() -> int: ) ) - with open(DEFAULT_CONFIG_FILE, "w") as dcfg: - json.dump(config, dcfg, indent=4) + log(f"Sorted in {code_timer() - sort_timer} seconds", "TIME") + + if not_ci_build: + log("Redumping config", "CONFIG") + + dump_timer = code_timer() + + with open(DEFAULT_CONFIG_FILE, "w") as dcfg: + json.dump(config, dcfg, indent=4) + + log(f"Dumped config in {code_timer() - dump_timer} seconds", "TIME") return code