update @ Thu 7 Apr 22:32:55 EEST 2022

Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
This commit is contained in:
Ari Archer 2022-04-07 22:32:55 +03:00
parent 2a401cad35
commit 41ef6b68ef
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: A50D5B4B599AF8A2
5 changed files with 68 additions and 8 deletions

View file

@ -27,4 +27,4 @@ jobs:
- name: Build static site - name: Build static site
run: | run: |
python3 scripts/blog static CI_BUILD=1 python3 scripts/blog static

View file

@ -23,3 +23,32 @@ Or
```sh ```sh
$ python3 -m pip install --user -r requirements.txt $ 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.

12
completions/blog.bash Normal file
View file

@ -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

View file

@ -1,5 +1,5 @@
[build] [build]
command = "python3 ./scripts/blog static" command = "CI_BUILD=1 python3 ./scripts/blog static"
[[redirects]] [[redirects]]
from = "/git/*" from = "/git/*"

View file

@ -223,6 +223,8 @@ def new_blog(config: Dict) -> Tuple[int, Dict]:
"""Make a new blog""" """Make a new blog"""
if title := iinput("blog title"): if title := iinput("blog title"):
readline.add_history(title)
us_title: str = title us_title: str = title
s_title: str = sanitise_title(us_title, config["blogs"]) 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 if not blog["content"].strip(): # type: ignore
return log("Blog cannot be empty"), config return log("Blog cannot be empty"), config
user_keywords: str = iinput("keywords (seperated by spaces)")
readline.add_history(user_keywords)
blog["keywords"] = html_escape( blog["keywords"] = html_escape(
iinput("keywords (seperated by spaces)") user_keywords + " " + " ".join(config["default-keywords"])
+ " "
+ " ".join(config["default-keywords"])
) )
blog["time"] = datetime.now().timestamp() blog["time"] = datetime.now().timestamp()
@ -628,6 +631,8 @@ def main() -> int:
readline.read_history_file(HISTORY_FILE) readline.read_history_file(HISTORY_FILE)
readline.set_history_length(5000) readline.set_history_length(5000)
readline.set_auto_history(False)
if not os.path.isfile(DEFAULT_CONFIG_FILE): if not os.path.isfile(DEFAULT_CONFIG_FILE):
new_config() new_config()
return EXIT_ERR return EXIT_ERR
@ -649,8 +654,13 @@ def main() -> int:
"TIME", "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") log("Sorting blogs by creation time...", "CLEANUP")
sort_timer = code_timer()
config["blogs"] = dict( config["blogs"] = dict(
map( map(
lambda k: (k, config["blogs"][k]), lambda k: (k, config["blogs"][k]),
@ -658,8 +668,17 @@ def main() -> int:
) )
) )
with open(DEFAULT_CONFIG_FILE, "w") as dcfg: log(f"Sorted in {code_timer() - sort_timer} seconds", "TIME")
json.dump(config, dcfg, indent=4)
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 return code