mirror of
https://git.ari.lt/ari.lt/blog.ari.lt.git
synced 2025-02-04 09:39:25 +01:00
update @ Thu 7 Apr 22:32:55 EEST 2022
Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
This commit is contained in:
parent
2a401cad35
commit
41ef6b68ef
5 changed files with 68 additions and 8 deletions
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
@ -27,4 +27,4 @@ jobs:
|
|||
|
||||
- name: Build static site
|
||||
run: |
|
||||
python3 scripts/blog static
|
||||
CI_BUILD=1 python3 scripts/blog static
|
||||
|
|
29
README.md
29
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.
|
||||
|
|
12
completions/blog.bash
Normal file
12
completions/blog.bash
Normal 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
|
|
@ -1,5 +1,5 @@
|
|||
[build]
|
||||
command = "python3 ./scripts/blog static"
|
||||
command = "CI_BUILD=1 python3 ./scripts/blog static"
|
||||
|
||||
[[redirects]]
|
||||
from = "/git/*"
|
||||
|
|
31
scripts/blog
31
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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue