Repository navigation
Expand file tree
/
Copy pathbuild_wiki.py
More file actions
72 lines (58 loc) · 2.45 KB
/
Copy pathbuild_wiki.py
File metadata and controls
72 lines (58 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json
import os
import html
from urllib.parse import urlparse
def get_site_name(url):
"""Extrait un nom lisible à partir de l'URL."""
try:
path = urlparse(url).path
if path and path != "/":
# On prend la dernière partie du chemin (ex: /DeepFaceLive -> DeepFaceLive)
name = path.split('/')[-1]
if not name: # cas où ça finit par /
name = path.split('/')[-2]
else:
# Sinon on prend le nom de domaine (ex: google.com -> Google)
name = urlparse(url).netloc.replace('www.', '').split('.')[0]
return name.replace('-', ' ').replace('_', ' ').capitalize()
except:
return "Lien"
def super_sanitize(text):
if not text or text == "None":
return "Pas de description."
text = html.escape(str(text))
replacements = {'{': '{', '}': '}', '<': '<', '>': '>', '$': '$'}
for char, escape in replacements.items():
text = text.replace(char, escape)
return text
# Charger les données
with open('links_final.json', 'r', encoding='utf-8') as f:
links = json.load(f)
os.makedirs('docs/categories', exist_ok=True)
grouped = {}
for item in links:
cat = item.get('category', 'divers').lower().strip()
if cat not in grouped: grouped[cat] = []
grouped[cat].append(item)
for cat, items in grouped.items():
safe_name = "".join([c for c in cat if c.isalnum() or c in ('-', '_')])
filename = f"docs/categories/{safe_name}.md"
with open(filename, 'w', encoding='utf-8') as f:
f.write(f"---\ntitle: 📁 {cat.upper()}\n---\n\n")
f.write(f"# {cat.upper()}\n\n")
for link in items:
url = link.get('url', '#')
site_name = get_site_name(url)
fr = super_sanitize(link.get('descriptionFR', ''))
en = super_sanitize(link.get('descriptionEN', ''))
# Titre avec le nom du site
f.write(f"### 🔗 [{site_name}]({url})\n\n")
# Affichage de l'URL brute
f.write(f"**Lien :** `{url}`\n\n")
# Bloc d'info (Admonition) corrigé avec les bons sauts de ligne
f.write(f"info Descriptions\n\n")
f.write(f"**FR :** {fr}\n\n")
f.write(f"**EN :** {en}\n\n")
f.write(f"\n\n")
f.write("---\n\n")
print(f"✅ Wiki mis à jour avec les noms de sites et formatage corrigé.")