update @ Mon 31 Oct 16:50:02 EET 2022

Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
This commit is contained in:
Ari Archer 2022-10-31 16:50:02 +02:00
parent 483fc41c0b
commit 14b0e75426
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 70 additions and 24 deletions

View file

@ -5,7 +5,7 @@ _blog() {
_init_completion -s || return
COMPREPLY=($(compgen -W "help new build ls\
rm edit defcfg clean metadata static" -- "$cur"))
rm edit defcfg clean metadata static css" -- "$cur"))
} && complete -F _blog -o bashdefault -o default blog

View file

@ -43,7 +43,7 @@
scroll-behavior: smooth;
outline-offset: 3px;
outline-offset: 4px;
}
::-webkit-scrollbar,
@ -180,9 +180,31 @@ blockquote * {
color: var(--clr-blockquote-fg);
}
a[data-pl] {
margin-right: 0.3em;
float: left !important;
*[data-pl] {
padding-top: 0.06em;
padding-bottom: 0.06em;
}
*[data-pl] * {
display: inline;
font-size: inherit !important;
}
*[data-pl] a {
padding-right: 0.3em;
opacity: 0.3;
transition: opacity 0.1s ease-in-out;
}
*[data-pl]:hover a,
*[data-pl]:focus a {
opacity: 1;
}
@media only screen and (max-width: 1360px) {
*[data-pl] a {
opacity: 1;
}
}
@media (prefers-reduced-motion: reduce) {

View file

@ -16,7 +16,7 @@ from shutil import rmtree
from tempfile import gettempdir
from threading import Thread
from timeit import default_timer as code_timer
from typing import Callable, Dict, Iterable, List, Set, Tuple
from typing import Callable, Dict, Iterable, List, Set, Tuple, Union
from warnings import filterwarnings as filter_warnings
import ujson # type: ignore
@ -249,27 +249,51 @@ def truncate_str(string: str, length: int) -> str:
class AddHeaderLinks(Treeprocessor):
def run(self, root):
self.ids: List[str] = []
ids: List[str] = []
heading_sizes_em: Dict[str, Union[float, int]] = {
"h1": 1.52,
"h2": 1.32,
"h3": 1.15,
"h4": 1,
"h5": 0.87,
"h6": 0.76,
}
all_headings: Tuple[str] = tuple(f"h{hl}" for hl in range(2, 7))
for h_level in range(2, 7):
for h in root.findall(f"h{h_level}"):
gen_id: str = sanitise_title(h.text, self.ids)
self.ids.append(gen_id)
for idx, elem in enumerate(root):
if elem.tag not in all_headings:
continue
link = h.makeelement(
gen_id: str = sanitise_title(elem.text, ids)
ids.append(gen_id)
heading_parent = elem.makeelement(
"div",
{
"data-pl": "",
"style": f"font-size:{heading_sizes_em[elem.tag] + 0.1}em",
},
)
heading = heading_parent.makeelement(elem.tag, {"id": gen_id})
link = heading.makeelement(
"a",
{
"href": f"#{gen_id}",
"data-pl": "",
"aria-hidden": "true",
"focusable": "false",
"tabindex": "-1",
},
)
link.text = "#"
h.append(link)
h.set("id", gen_id)
link.text = "#"
heading_parent.append(link)
heading.text = elem.text
heading_parent.append(heading)
root.remove(elem)
root.insert(idx, heading_parent)
class AddHeaderLinksExt(Extension):