update @ Wed 1 Jun 16:19:08 EEST 2022

Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
This commit is contained in:
Ari Archer 2022-06-01 16:19:08 +03:00
parent 0fc8f4367b
commit 8ab23a8273
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
3 changed files with 93 additions and 34 deletions

View file

@ -54,3 +54,11 @@ to save time on some operations that are useless
in that context, for example sorting blogs. in that context, for example sorting blogs.
`CI_BUILD` can have any value. `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)

View file

@ -57,7 +57,8 @@
"version": 1, "version": 1,
"time": 1646996956.328543, "time": 1646996956.328543,
"keywords": "management linux http-redirect new", "keywords": "management linux http-redirect new",
"minimise": true "minimise": true,
"hidden": false
}, },
"happy-pi-e--day": { "happy-pi-e--day": {
"title": "SGFwcHkgcGkoZSkgZGF5", "title": "SGFwcHkgcGkoZSkgZGF5",
@ -65,7 +66,8 @@
"version": 1, "version": 1,
"time": 1647291763.684886, "time": 1647291763.684886,
"keywords": "pi pi-day piday math einstein 3.14159 \u03c0", "keywords": "pi pi-day piday math einstein 3.14159 \u03c0",
"minimise": true "minimise": true,
"hidden": false
}, },
"i-m-tired-of-being-the-lab-rat-": { "i-m-tired-of-being-the-lab-rat-": {
"title": "SSdtIHRpcmVkIG9mIGJlaW5nIHRoZSBsYWIgcmF0Lg==", "title": "SSdtIHRpcmVkIG9mIGJlaW5nIHRoZSBsYWIgcmF0Lg==",
@ -73,7 +75,8 @@
"version": 1, "version": 1,
"time": 1650399078.538313, "time": 1650399078.538313,
"keywords": "", "keywords": "",
"minimise": true "minimise": true,
"hidden": false
}, },
"how-to-print-coloured-text-in-c-and-c--": { "how-to-print-coloured-text-in-c-and-c--": {
"title": "SG93IHRvIHByaW50IGNvbG91cmVkIHRleHQgaW4gQyBhbmQgQysr", "title": "SG93IHRvIHByaW50IGNvbG91cmVkIHRleHQgaW4gQyBhbmQgQysr",
@ -81,7 +84,8 @@
"version": 1, "version": 1,
"time": 1652041043.26174, "time": 1652041043.26174,
"keywords": "colour C++ C code gcc clang g++ clang++ ansi linux colors terminal", "keywords": "colour C++ C code gcc clang g++ clang++ ansi linux colors terminal",
"minimise": false "minimise": false,
"hidden": false
}, },
"should-i-tell-the-truth-": { "should-i-tell-the-truth-": {
"title": "U2hvdWxkIEkgdGVsbCB0aGUgdHJ1dGg/", "title": "U2hvdWxkIEkgdGVsbCB0aGUgdHJ1dGg/",
@ -89,7 +93,8 @@
"version": 1, "version": 1,
"time": 1652799531.935402, "time": 1652799531.935402,
"keywords": "mental health psychiatrist psychologist", "keywords": "mental health psychiatrist psychologist",
"minimise": true "minimise": true,
"hidden": false
}, },
"shutdown-of-my-tcl--tiny-core-linux--mirror": { "shutdown-of-my-tcl--tiny-core-linux--mirror": {
"title": "U2h1dGRvd24gb2YgbXkgVENMICh0aW55IGNvcmUgbGludXgpIG1pcnJvcg==", "title": "U2h1dGRvd24gb2YgbXkgVENMICh0aW55IGNvcmUgbGludXgpIG1pcnJvcg==",
@ -97,7 +102,8 @@
"version": 1, "version": 1,
"time": 1653077097.618588, "time": 1653077097.618588,
"keywords": "tinycore tcl tiny-core-linux foss open source mirror", "keywords": "tinycore tcl tiny-core-linux foss open source mirror",
"minimise": true "minimise": true,
"hidden": false
}, },
"is-assembly-bloated-": { "is-assembly-bloated-": {
"title": "SXMgYXNzZW1ibHkgYmxvYXRlZD8=", "title": "SXMgYXNzZW1ibHkgYmxvYXRlZD8=",
@ -105,7 +111,8 @@
"version": 1, "version": 1,
"time": 1653146701.325321, "time": 1653146701.325321,
"keywords": "nasm assembly bloat C programming elf elf64 binary python github", "keywords": "nasm assembly bloat C programming elf elf64 binary python github",
"minimise": true "minimise": true,
"hidden": false
}, },
"my-gentoo-linux-setup": { "my-gentoo-linux-setup": {
"title": "TXkgZ2VudG9vIGxpbnV4IHNldHVw", "title": "TXkgZ2VudG9vIGxpbnV4IHNldHVw",
@ -113,7 +120,8 @@
"version": 1, "version": 1,
"time": 1653498902.254038, "time": 1653498902.254038,
"keywords": "dotfiles linux gentoo-linux gnu gnu-linux theme clang C++ developer dev vim vi", "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---": { "user-opinion-and-comments-site-is-now-up---": {
"title": "VXNlciBvcGluaW9uIGFuZCBjb21tZW50cyBzaXRlIGlzIG5vdyB1cCA6KQ==", "title": "VXNlciBvcGluaW9uIGFuZCBjb21tZW50cyBzaXRlIGlzIG5vdyB1cCA6KQ==",
@ -121,7 +129,8 @@
"version": 1, "version": 1,
"time": 1653591701.315394, "time": 1653591701.315394,
"keywords": "comment opinion utterances privacy github git lightweight typescript", "keywords": "comment opinion utterances privacy github git lightweight typescript",
"minimise": true "minimise": true,
"hidden": false
}, },
"introducing-the-ari-web-api-": { "introducing-the-ari-web-api-": {
"title": "SW50cm9kdWNpbmcgdGhlIGFyaS13ZWIgQVBJIQ==", "title": "SW50cm9kdWNpbmcgdGhlIGFyaS13ZWIgQVBJIQ==",
@ -129,7 +138,8 @@
"version": 1, "version": 1,
"time": 1653602912.809375, "time": 1653602912.809375,
"keywords": "api json json-api developer domain", "keywords": "api json json-api developer domain",
"minimise": true "minimise": true,
"hidden": false
}, },
"being-mentally-ill-is-a-pain-in-the-ass": { "being-mentally-ill-is-a-pain-in-the-ass": {
"title": "QmVpbmcgbWVudGFsbHkgaWxsIGlzIGEgcGFpbiBpbiB0aGUgYXNz", "title": "QmVpbmcgbWVudGFsbHkgaWxsIGlzIGEgcGFpbiBpbiB0aGUgYXNz",
@ -137,7 +147,8 @@
"version": 1, "version": 1,
"time": 1653662984.808034, "time": 1653662984.808034,
"keywords": "mental psychology exhausting", "keywords": "mental psychology exhausting",
"minimise": true "minimise": true,
"hidden": false
}, },
"happy--almost--pride-month---": { "happy--almost--pride-month---": {
"title": "SGFwcHkgKGFsbW9zdCkgcHJpZGUgbW9udGggOik=", "title": "SGFwcHkgKGFsbW9zdCkgcHJpZGUgbW9udGggOik=",
@ -145,7 +156,8 @@
"version": 1, "version": 1,
"time": 1653913182.303729, "time": 1653913182.303729,
"keywords": "gay lgbt lgbt-pride pride-month june pride", "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": { "wtf-is-going-on-and-why-is-my-site-blowing-up": {
"title": "V3RmIGlzIGdvaW5nIG9uIGFuZCB3aHkgaXMgbXkgc2l0ZSBibG93aW5nIHVw", "title": "V3RmIGlzIGdvaW5nIG9uIGFuZCB3aHkgaXMgbXkgc2l0ZSBibG93aW5nIHVw",
@ -153,7 +165,8 @@
"version": 1, "version": 1,
"time": 1653927309.556282, "time": 1653927309.556282,
"keywords": "excited goal netlify happy stats", "keywords": "excited goal netlify happy stats",
"minimise": true "minimise": true,
"hidden": false
}, },
"pride-month-just-started-and-i-m-already-in-pain": { "pride-month-just-started-and-i-m-already-in-pain": {
"title": "UHJpZGUgbW9udGgganVzdCBzdGFydGVkIGFuZCBJJ20gYWxyZWFkeSBpbiBwYWlu", "title": "UHJpZGUgbW9udGgganVzdCBzdGFydGVkIGFuZCBJJ20gYWxyZWFkeSBpbiBwYWlu",
@ -161,7 +174,8 @@
"version": 1, "version": 1,
"time": 1654079876.56532, "time": 1654079876.56532,
"keywords": "pain pride lgbt mother stupid", "keywords": "pain pride lgbt mother stupid",
"minimise": true "minimise": true,
"hidden": false
}, },
"i-got-outted-by-my-classmate--on-pride-month--fun": { "i-got-outted-by-my-classmate--on-pride-month--fun": {
"title": "SSBnb3Qgb3V0dGVkIGJ5IG15IGNsYXNzbWF0ZSwgb24gcHJpZGUgbW9udGgsIGZ1bg==", "title": "SSBnb3Qgb3V0dGVkIGJ5IG15IGNsYXNzbWF0ZSwgb24gcHJpZGUgbW9udGgsIGZ1bg==",
@ -169,7 +183,8 @@
"version": 1, "version": 1,
"time": 1654084744.300839, "time": 1654084744.300839,
"keywords": "gay lgbt trans transgender out outted bitch classmate class school", "keywords": "gay lgbt trans transgender out outted bitch classmate class school",
"minimise": true "minimise": true,
"hidden": false
} }
} }
} }

View file

@ -132,6 +132,10 @@ def log(message: str, header: str = "ERROR", code: int = EXIT_ERR) -> int:
return code return code
def yesno(cond: bool) -> str:
return "Yes" if cond else "No"
def sanitise_title(title: str, titleset: Dict) -> str: def sanitise_title(title: str, titleset: Dict) -> str:
_title: str = "" _title: str = ""
@ -168,6 +172,16 @@ def iinput(prompt: str, default_text: str = "") -> str:
return user_inpt 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: def new_config() -> None:
log("Making new config...", "INFO") log("Making new config...", "INFO")
@ -237,7 +251,8 @@ def new_blog(config: Dict) -> Tuple[int, Dict]:
readline.add_history(user_keywords) readline.add_history(user_keywords)
blog["keywords"] = html_escape(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() blog["time"] = datetime.now().timestamp()
config["blogs"][s_title] = blog config["blogs"][s_title] = blog
@ -274,14 +289,14 @@ def build(config: Dict) -> Tuple[int, Dict]:
log("Building blogs...", "INFO") 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: if blog_meta["version"] != BLOG_VERSION:
log( 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", "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) os.makedirs(blog_dir, exist_ok=True)
with open(os.path.join(blog_dir, "index.html"), "w") as blog_html: 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"]: 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) 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) 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 = [] _tmp_threads: List = []
for blog_name, blog_meta in config["blogs"].items(): for blog_id, blog_meta in config["blogs"].items():
t: Thread = Thread(target=thread, args=(blog_name, blog_meta), daemon=True) 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) _tmp_threads.append(t)
t.start() t.start()
@ -343,7 +362,15 @@ def build(config: Dict) -> Tuple[int, Dict]:
blog_list = "<ul>" blog_list = "<ul>"
for blog_id, blog_meta in reversed(config["blogs"].items()): for blog_id, blog_meta in reversed(config["blogs"].items()):
blog_list += f'<li><a href="{os.path.join(config["blog-dir"], blog_id)}">{html_escape(b64decode(blog_meta["title"]).decode())}</a></li>' blog_list += "<li>"
if blog_meta["hidden"]:
blog_list += "<i>Blog hidden by the owner</i>"
continue
blog_list += f'<a href="{os.path.join(config["blog-dir"], blog_id)}">{html_escape(b64decode(blog_meta["title"]).decode())}</a>'
blog_list += "</li>"
blog_list += "</ul>" blog_list += "</ul>"
@ -380,9 +407,10 @@ def list_blogs(config: Dict) -> Tuple[int, Dict]:
f"""ID: {blog_id} f"""ID: {blog_id}
Title: {b64decode(blog_meta['title']).decode()!r} Title: {b64decode(blog_meta['title']).decode()!r}
Version: {blog_meta['version']} 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(' ', ', ')} 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: def edit_minimise(blog: str, config: Dict) -> int:
minimise: bool = config["blogs"][blog]["minimise"] minimise: bool = config["blogs"][blog]["minimise"]
str_minimise: str = "y" if minimise else "n"
config["blogs"][blog]["minimise"] = ( config["blogs"][blog]["minimise"] = yn(
iinput( "Minimise this blog's HTML", str_minimise, str_minimise
f"Minimise this blog's HTML? [{minimise}] (y/n)", "y" if minimise else "n" )
)
+ "y" return EXIT_OK
).lower()[0] == "y"
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 return EXIT_OK
@ -476,6 +511,7 @@ EDIT_HOOKS: Dict = {
"keywords": edit_keywords, "keywords": edit_keywords,
"content": edit_content, "content": edit_content,
"minimise": edit_minimise, "minimise": edit_minimise,
"hidden": edit_hidden,
} }
@ -500,7 +536,7 @@ def edit(config: Dict) -> Tuple[int, Dict]:
EDIT_HOOKS[hook](blog_id, config) EDIT_HOOKS[hook](blog_id, config)
except ProcessExecutionError: except ProcessExecutionError:
return log("Fzf unexpectedly exited"), config return log("No blog selected"), config
return EXIT_OK, config return EXIT_OK, config