diff --git a/README.md b/README.md index 7394e36..a9151f2 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,11 @@ to save time on some operations that are useless in that context, for example sorting blogs. `CI_BUILD` can have any value. + +## The API and hidden blogs + +Some blogs might be hidden for a day or two if +I'm working on it or just need to hide it to +not show some stuff on the main page, though +nobody is stopping you from using the static API, +it's located at [/blog.json](https://blog.ari-web.xyz/blog.json) diff --git a/blog.json b/blog.json index f09cc6a..c4fa64f 100644 --- a/blog.json +++ b/blog.json @@ -57,7 +57,8 @@ "version": 1, "time": 1646996956.328543, "keywords": "management linux http-redirect new", - "minimise": true + "minimise": true, + "hidden": false }, "happy-pi-e--day": { "title": "SGFwcHkgcGkoZSkgZGF5", @@ -65,7 +66,8 @@ "version": 1, "time": 1647291763.684886, "keywords": "pi pi-day piday math einstein 3.14159 \u03c0", - "minimise": true + "minimise": true, + "hidden": false }, "i-m-tired-of-being-the-lab-rat-": { "title": "SSdtIHRpcmVkIG9mIGJlaW5nIHRoZSBsYWIgcmF0Lg==", @@ -73,7 +75,8 @@ "version": 1, "time": 1650399078.538313, "keywords": "", - "minimise": true + "minimise": true, + "hidden": false }, "how-to-print-coloured-text-in-c-and-c--": { "title": "SG93IHRvIHByaW50IGNvbG91cmVkIHRleHQgaW4gQyBhbmQgQysr", @@ -81,7 +84,8 @@ "version": 1, "time": 1652041043.26174, "keywords": "colour C++ C code gcc clang g++ clang++ ansi linux colors terminal", - "minimise": false + "minimise": false, + "hidden": false }, "should-i-tell-the-truth-": { "title": "U2hvdWxkIEkgdGVsbCB0aGUgdHJ1dGg/", @@ -89,7 +93,8 @@ "version": 1, "time": 1652799531.935402, "keywords": "mental health psychiatrist psychologist", - "minimise": true + "minimise": true, + "hidden": false }, "shutdown-of-my-tcl--tiny-core-linux--mirror": { "title": "U2h1dGRvd24gb2YgbXkgVENMICh0aW55IGNvcmUgbGludXgpIG1pcnJvcg==", @@ -97,7 +102,8 @@ "version": 1, "time": 1653077097.618588, "keywords": "tinycore tcl tiny-core-linux foss open source mirror", - "minimise": true + "minimise": true, + "hidden": false }, "is-assembly-bloated-": { "title": "SXMgYXNzZW1ibHkgYmxvYXRlZD8=", @@ -105,7 +111,8 @@ "version": 1, "time": 1653146701.325321, "keywords": "nasm assembly bloat C programming elf elf64 binary python github", - "minimise": true + "minimise": true, + "hidden": false }, "my-gentoo-linux-setup": { "title": "TXkgZ2VudG9vIGxpbnV4IHNldHVw", @@ -113,7 +120,8 @@ "version": 1, "time": 1653498902.254038, "keywords": "dotfiles linux gentoo-linux gnu gnu-linux theme clang C++ developer dev vim vi", - "minimise": true + "minimise": true, + "hidden": false }, "user-opinion-and-comments-site-is-now-up---": { "title": "VXNlciBvcGluaW9uIGFuZCBjb21tZW50cyBzaXRlIGlzIG5vdyB1cCA6KQ==", @@ -121,7 +129,8 @@ "version": 1, "time": 1653591701.315394, "keywords": "comment opinion utterances privacy github git lightweight typescript", - "minimise": true + "minimise": true, + "hidden": false }, "introducing-the-ari-web-api-": { "title": "SW50cm9kdWNpbmcgdGhlIGFyaS13ZWIgQVBJIQ==", @@ -129,7 +138,8 @@ "version": 1, "time": 1653602912.809375, "keywords": "api json json-api developer domain", - "minimise": true + "minimise": true, + "hidden": false }, "being-mentally-ill-is-a-pain-in-the-ass": { "title": "QmVpbmcgbWVudGFsbHkgaWxsIGlzIGEgcGFpbiBpbiB0aGUgYXNz", @@ -137,7 +147,8 @@ "version": 1, "time": 1653662984.808034, "keywords": "mental psychology exhausting", - "minimise": true + "minimise": true, + "hidden": false }, "happy--almost--pride-month---": { "title": "SGFwcHkgKGFsbW9zdCkgcHJpZGUgbW9udGggOik=", @@ -145,7 +156,8 @@ "version": 1, "time": 1653913182.303729, "keywords": "gay lgbt lgbt-pride pride-month june pride", - "minimise": true + "minimise": true, + "hidden": false }, "wtf-is-going-on-and-why-is-my-site-blowing-up": { "title": "V3RmIGlzIGdvaW5nIG9uIGFuZCB3aHkgaXMgbXkgc2l0ZSBibG93aW5nIHVw", @@ -153,7 +165,8 @@ "version": 1, "time": 1653927309.556282, "keywords": "excited goal netlify happy stats", - "minimise": true + "minimise": true, + "hidden": false }, "pride-month-just-started-and-i-m-already-in-pain": { "title": "UHJpZGUgbW9udGgganVzdCBzdGFydGVkIGFuZCBJJ20gYWxyZWFkeSBpbiBwYWlu", @@ -161,7 +174,8 @@ "version": 1, "time": 1654079876.56532, "keywords": "pain pride lgbt mother stupid", - "minimise": true + "minimise": true, + "hidden": false }, "i-got-outted-by-my-classmate--on-pride-month--fun": { "title": "SSBnb3Qgb3V0dGVkIGJ5IG15IGNsYXNzbWF0ZSwgb24gcHJpZGUgbW9udGgsIGZ1bg==", @@ -169,7 +183,8 @@ "version": 1, "time": 1654084744.300839, "keywords": "gay lgbt trans transgender out outted bitch classmate class school", - "minimise": true + "minimise": true, + "hidden": false } } } \ No newline at end of file diff --git a/scripts/blog b/scripts/blog index 3ea7a44..68721b7 100755 --- a/scripts/blog +++ b/scripts/blog @@ -132,6 +132,10 @@ def log(message: str, header: str = "ERROR", code: int = EXIT_ERR) -> int: return code +def yesno(cond: bool) -> str: + return "Yes" if cond else "No" + + def sanitise_title(title: str, titleset: Dict) -> str: _title: str = "" @@ -168,6 +172,16 @@ def iinput(prompt: str, default_text: str = "") -> str: return user_inpt +def yn(prompt: str, default: str = "y", current_value: str = "") -> bool: + return ( + iinput( + f"{prompt}? ({'y/n'.replace(default.lower(), default.upper())})", + current_value, + ) + + default + ).lower()[0] == "y" + + def new_config() -> None: log("Making new config...", "INFO") @@ -237,7 +251,8 @@ def new_blog(config: Dict) -> Tuple[int, Dict]: readline.add_history(user_keywords) blog["keywords"] = html_escape(user_keywords) - blog["minimise"] = (iinput("Minimise blog? (Y/n)") + "y").lower()[0] == "y" + blog["minimise"] = yn("Minimise blog") + blog["hidden"] = yn("Hide blog", "n") blog["time"] = datetime.now().timestamp() config["blogs"][s_title] = blog @@ -274,14 +289,14 @@ def build(config: Dict) -> Tuple[int, Dict]: log("Building blogs...", "INFO") - def thread(blog_name: str, blog_meta: Dict): + def thread(blog_id: str, blog_meta: Dict): if blog_meta["version"] != BLOG_VERSION: log( - f"{blog_name}: unmatching version between {blog_meta['version']} and {BLOG_VERSION}", + f"{blog_id}: unmatching version between {blog_meta['version']} and {BLOG_VERSION}", "WARNING", ) - blog_dir: str = os.path.join(config["blog-dir"], blog_name) + blog_dir: str = os.path.join(config["blog-dir"], blog_id) os.makedirs(blog_dir, exist_ok=True) with open(os.path.join(blog_dir, "index.html"), "w") as blog_html: @@ -314,18 +329,22 @@ def build(config: Dict) -> Tuple[int, Dict]: ) if blog_meta["minimise"]: - log(f"Minifying {blog_name!r} HTML", "MINIFY") + log(f"Minifying {blog_id!r} HTML", "MINIFY") blog_html_full = html_minify(blog_html_full) - log(f"Done minifying the HTML of {blog_name!r}", "MINIFY") + log(f"Done minifying the HTML of {blog_id!r}", "MINIFY") blog_html.write(blog_html_full) - log(f"Finished building blog {blog_name!r}", "BUILD") + log(f"Finished building blog {blog_id!r}", "BUILD") _tmp_threads: List = [] - for blog_name, blog_meta in config["blogs"].items(): - t: Thread = Thread(target=thread, args=(blog_name, blog_meta), daemon=True) + for blog_id, blog_meta in config["blogs"].items(): + if blog_meta["hidden"]: + log(f"Hidden blog: {blog_id!r}", "HIDE") + continue + + t: Thread = Thread(target=thread, args=(blog_id, blog_meta), daemon=True) _tmp_threads.append(t) t.start() @@ -343,7 +362,15 @@ def build(config: Dict) -> Tuple[int, Dict]: blog_list = "" @@ -380,9 +407,10 @@ def list_blogs(config: Dict) -> Tuple[int, Dict]: f"""ID: {blog_id} Title: {b64decode(blog_meta['title']).decode()!r} Version: {blog_meta['version']} -Time of creation: {format_time(blog_meta['time'])} +Time_of_creation: {format_time(blog_meta['time'])} Keywords: {blog_meta['keywords'].replace(' ', ', ')} -Minimise: {'Yes' if blog_meta['minimise'] else 'No'} +Minimise: {yesno(blog_meta['minimise'])} +Hidden: {yesno(blog_meta['hidden'])} """ ) @@ -459,13 +487,20 @@ def edit_content(blog: str, config: Dict) -> int: def edit_minimise(blog: str, config: Dict) -> int: minimise: bool = config["blogs"][blog]["minimise"] + str_minimise: str = "y" if minimise else "n" - config["blogs"][blog]["minimise"] = ( - iinput( - f"Minimise this blog's HTML? [{minimise}] (y/n)", "y" if minimise else "n" - ) - + "y" - ).lower()[0] == "y" + config["blogs"][blog]["minimise"] = yn( + "Minimise this blog's HTML", str_minimise, str_minimise + ) + + return EXIT_OK + + +def edit_hidden(blog: str, config: Dict) -> int: + hidden: bool = config["blogs"][blog]["hidden"] + str_hidden: str = "y" if hidden else "n" + + config["blogs"][blog]["hidden"] = yn("Hide this blog", str_hidden, str_hidden) return EXIT_OK @@ -476,6 +511,7 @@ EDIT_HOOKS: Dict = { "keywords": edit_keywords, "content": edit_content, "minimise": edit_minimise, + "hidden": edit_hidden, } @@ -500,7 +536,7 @@ def edit(config: Dict) -> Tuple[int, Dict]: EDIT_HOOKS[hook](blog_id, config) except ProcessExecutionError: - return log("Fzf unexpectedly exited"), config + return log("No blog selected"), config return EXIT_OK, config