-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_images.py
More file actions
78 lines (72 loc) · 2.89 KB
/
add_images.py
File metadata and controls
78 lines (72 loc) · 2.89 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
73
74
75
76
77
78
import os
count = 0
for root, dirs, files in os.walk('.'):
# Skip .git and worktrees to avoid clutter
if '.git' in root or '.worktrees' in root:
continue
for file in files:
if file.endswith('.md'):
md_path = os.path.join(root, file)
base_name = os.path.splitext(file)[0]
img_tag = f""
try:
with open(md_path, 'r', encoding='utf-8') as f:
content = f.read()
# Check if this specific file already has its image tag
if f"![{base_name}]" not in content and f"![{base_name.lower()}]" not in content:
with open(md_path, 'w', encoding='utf-8') as f:
f.write(img_tag + "\n\n" + content)
print(f"Added image tag to: {md_path}")
count += 1
except Exception as e:
print(f"Error reimport os
count = 0
for roo")
count =f"\for rootdd # Skip .git and worktrees to avois. if '.git' in root or '.worktrees' in rootma python3 -c '
import os
count = 0
for root, dirs, files in os.walk("."):
if ".git" in root or ".worktrees" in root:
continue
for file in files:
if file.endswith(".md"):
md_path = os.path.join(root, file)
base_name = os.path.splitext(file)[0]
img_tag = f""
try:
with open(md_path, "r", encoding="utf-8") as f:
content = f.read()
if f"![{base_name}]" not in content and f"![{base_name.lower()}]" not in content:
with open(md_path, "w", encoding="utf-8") as f:
f.write(img_tag + "\n\n" + content)
print(f"Added image tag to {md_path}")
count += 1
except Exception as e:
pass
print(f"DONE. Found and injected {count} missing images.")
'
EOF
python3 -c '
import os
count = 0
for root, dirs, files in os.walk("."):
if ".git" in root or ".worktrees" in root:
continue
for file in files:
if file.endswith(".md"):
md_path = os.path.join(root, file)
base_name = os.path.splitext(file)[0]
img_tag = f""
try:
with open(md_path, "r", encoding="utf-8") as f:
content = f.read()
if f"![{base_name}]" not in content and f"![{base_name.lower()}]" not in content:
with open(md_path, "w", encoding="utf-8") as f:
f.write(img_tag + "\n\n" + content)
print(f"Added image tag to {md_path}")
count += 1
except Exception as e:
pass
print(f"DONE. Found and injected {count} missing images.")
'
EOF