2023-06-25 16:05:15 -06:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
from datetime import datetime
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
root = Path(__file__).parent.parent
|
|
|
|
about = re.sub(r'\s+', ' ', """
|
|
|
|
Hola, soy perro tuerto. Mi formación académica es en Filosofía, mi
|
|
|
|
profesión es la edición de publicaciones (libros, fanzines, revistas, etc.)
|
|
|
|
y mi programación se enfoca en el desarrollo de metodologías libres para la
|
|
|
|
publicación. Soy fan de las humanidades, la paleoantropología y las
|
|
|
|
ciencias de la computación, así como soy voluntario en organizaciones sobre
|
|
|
|
edición, <i>software</i> y cultura libres, como Miau, Cuates o Wikipedia.
|
|
|
|
Doy soporte técnico a la Academia Mexicana de la Lengua y puedo ayudarte
|
|
|
|
en tus proyectos. <b>En este espacio comparto enlaces que me parecen
|
|
|
|
chéveres.</b>
|
|
|
|
""").strip()
|
|
|
|
contact = {
|
|
|
|
"site": "https://perrotuerto.blog",
|
|
|
|
"gitlab": "https://gitlab.com/perrotuerto",
|
|
|
|
"cuates": "https://git.cuates.net/perro",
|
|
|
|
"wikipedia": "https://es.wikipedia.org/wiki/Usuario:Perrotuerto",
|
|
|
|
"github": "https://github.com/perrotuerto",
|
|
|
|
"email": "hi@perrotuerto.blog",
|
|
|
|
}
|
2023-06-26 10:29:22 -06:00
|
|
|
json_file = Path(sys.argv[1])
|
|
|
|
links = json.loads(json_file.read_text())
|
2023-06-25 16:05:15 -06:00
|
|
|
data = {"acerca": about, "contacto": contact, "links": links["results"]}
|
|
|
|
index = root / "public" / "index.html"
|
|
|
|
template = (root / "src" / "template.html").read_text()
|
|
|
|
body = ""
|
|
|
|
|
|
|
|
for key, val in data.items():
|
|
|
|
if key == "contacto":
|
|
|
|
for name, url in val.items():
|
|
|
|
template = re.sub(f'#{name.upper()}#', url, template)
|
|
|
|
continue
|
|
|
|
body += f'\n<section id="{key}">'
|
|
|
|
body += f'\n<h1>{key.capitalize()}</h1>'
|
|
|
|
if isinstance(val, str):
|
|
|
|
body += f'\n{val}'
|
|
|
|
else:
|
|
|
|
body += '<ul class="list">'
|
|
|
|
for link in val:
|
2023-06-26 10:18:09 -06:00
|
|
|
date1 = "%Y-%m-%dT%H:%M:%S.%fZ"
|
|
|
|
date2 = "%d/%m/%Y"
|
2023-06-25 16:05:15 -06:00
|
|
|
url = link["url"]
|
|
|
|
created = link["date_added"]
|
|
|
|
updated = link["date_modified"]
|
2023-06-26 10:29:22 -06:00
|
|
|
created = datetime.strptime(created, date1).strftime(date2)
|
|
|
|
updated = datetime.strptime(updated, date1).strftime(date2)
|
2023-06-25 16:05:15 -06:00
|
|
|
tags = filter(lambda x: x != "blog", link["tag_names"])
|
|
|
|
tags = map(lambda x: f'<span class="tag">#{x}</span>', tags)
|
|
|
|
tags = map(lambda x: f'<a>{x}</a>', tags)
|
|
|
|
body += f'\n<li class="link" id="{link["id"]}">'
|
2023-06-25 16:06:33 -06:00
|
|
|
body += f'\n<h1><a target="_blank" class="anchor" href="#{link["id"]}">⚓</a>'
|
2023-06-25 16:05:15 -06:00
|
|
|
body += f'<a class="name" href="{url}">{link["title"]}</a></h1>'
|
|
|
|
body += f'\n<p class="description">{link["description"]}</p>'
|
|
|
|
body += f'\n<p class="tags">{" ".join(tags)}</p>'
|
|
|
|
body += '\n<p class="dates">'
|
|
|
|
body += f'<span class="created">{created}</span>'
|
|
|
|
body += f'<span class="updated">{updated}</span></p>'
|
|
|
|
if "notes" in link.keys():
|
|
|
|
blocks = map(lambda x: x.strip(), link["notes"].split("\n"))
|
|
|
|
blocks = list(filter(None, blocks))
|
|
|
|
for i, block in enumerate(blocks):
|
|
|
|
block = re.sub(r'\*\*\*(.+)\*\*\*', r'<b><i>\1</i></b>', block)
|
|
|
|
block = re.sub(r'\*\*(.+)\*\*', r'<b>\1</b>', block)
|
|
|
|
block = re.sub(r'\*(.+)\*', r'<i>\1</i>', block)
|
|
|
|
block = re.sub(r'\[(.+)\]\((.+)\)', r'<a target="_blank" href="\2">\1</a>', block)
|
|
|
|
header = r'(#+)\s*(.+)'
|
|
|
|
if re.match(header, block):
|
|
|
|
groups = re.match(header, block).groups()
|
|
|
|
tag = "h" + str(len(groups[0]))
|
|
|
|
blocks[i] = f"<{tag}>{groups[1]}</{tag}>"
|
|
|
|
else:
|
|
|
|
blocks[i] = f"<p>{block}</p>"
|
|
|
|
body += '\n<details class="info">'
|
|
|
|
body += '\n<summary>Leer más</summary>'
|
|
|
|
body += "\n".join(blocks)
|
|
|
|
body += '\n</details>'
|
|
|
|
body += '\n</li>'
|
|
|
|
body += "</ul>"
|
|
|
|
body += '\n</section>'
|
|
|
|
|
|
|
|
index.write_text(re.sub('#LINKS#', body, template))
|
2023-06-26 10:29:22 -06:00
|
|
|
json_file.write_text(json.dumps(data))
|