4 def save_signature(name
, link
, author
):
5 with
open(f
"_data/signed/{author}.yaml", "w") as f
:
6 f
.write(f
"name: {name.strip()}\nlink: {link.strip()}\n")
9 # Apparently most people can't follow a two-line template, e.g. miss 'name:' or
10 # 'link:' or use 'site:' instead of 'link:' or use 'mailto:' instead of
11 # 'link: mailto:', etc., so we have to guess in what way their interpretation is
12 # wrong, and try to make the format at least somewhat correct.
13 def import_signature_from_lines(name
, link
, author
):
14 if name
.lower().startswith("name:"):
17 if link
.lower().startswith("link:"):
19 elif link
.lower().startswith("site:"):
21 elif link
.lower().startswith("mail:"):
22 link
= "mailto:" + link
[5:].strip()
23 elif link
.lower().startswith("email:"):
24 link
= "mailto:" + link
[6:].strip()
25 elif link
.lower().startswith("mailto:"):
26 link
= "mailto:" + link
[7:].strip()
29 if "@" in link
or "(at)" in link
or "[at]" in link
:
30 link
= link
.replace("[at]", "@")
31 link
= link
.replace("(at)", "@")
32 link
= link
.replace(" at ", "@")
33 link
= link
.replace("[dot]", ".")
34 link
= link
.replace("(dot)", ".")
35 link
= link
.replace(" dot ", ".")
36 link
= link
.replace(" ", "")
38 # Add protocol to links without it
41 if not link
.startswith("mailto:"):
42 link
= f
"mailto:{link}"
43 elif link
.startswith("www.") or link
.endswith(".com"):
44 link
= f
"https://{link}"
46 if "/" in link
or "@" in link
:
47 save_signature(name
, link
, author
)
50 def parse_and_import_signature(content
, author
):
51 if os
.path
.isfile(f
"_data/signed/{author}.yaml"):
54 content_lines
= [line
.strip() for line
in content
.replace("`", "").strip().split("\n") if line
.strip()]
56 for i
in range(len(content_lines
) - 1):
57 if content_lines
[i
].lower().startswith("name:") and content_lines
[i
+ 1].lower().startswith("link:"):
58 import_signature_from_lines(content_lines
[i
], content_lines
[i
+ 1], author
)
60 if not imported
and len(content_lines
) == 2:
61 import_signature_from_lines(*content_lines
, author
)