-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-cheatsheet-tool-links.py
More file actions
122 lines (106 loc) · 3.62 KB
/
add-cheatsheet-tool-links.py
File metadata and controls
122 lines (106 loc) · 3.62 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
"""Add tool links to cheat sheet 'Related Resources' sections."""
import os
CS_DIR = "/var/www/web-ceo/cheatsheets"
# Map: cheatsheet filename -> tool links to add
TOOL_LINKS = {
"bash-shortcuts.html": [
("/tools/cron-parser", "Cron Parser"),
("/tools/text-case-converter", "Text Case Converter"),
],
"docker-commands.html": [
("/tools/yaml-validator", "YAML Validator"),
("/tools/json-formatter", "JSON Formatter"),
],
"javascript-array-methods.html": [
("/tools/json-formatter", "JSON Formatter"),
("/tools/json-path-finder", "JSON Path Finder"),
],
"linux-permissions.html": [
("/tools/number-base-converter", "Number Base Converter"),
],
"typescript-types.html": [
("/tools/json-schema-validator", "JSON Schema Validator"),
("/tools/json-formatter", "JSON Formatter"),
],
"vim-shortcuts.html": [
("/tools/regex-tester", "Regex Tester"),
("/tools/diff-checker", "Diff Checker"),
],
"python-string-methods.html": [
("/tools/regex-tester", "Regex Tester"),
],
"css-flexbox.html": [
("/tools/css-gradient", "CSS Gradient Generator"),
("/tools/box-shadow", "Box Shadow Generator"),
],
"css-grid.html": [
("/tools/css-gradient", "CSS Gradient Generator"),
("/tools/css-minifier", "CSS Minifier"),
],
"sql-basics.html": [
("/tools/sql-formatter", "SQL Formatter"),
("/tools/json-to-csv", "JSON to CSV Converter"),
],
"http-status-codes.html": [
("/tools/http-tester", "HTTP Request Tester"),
],
"git-commands.html": [
("/tools/diff-checker", "Diff Checker"),
],
"react-hooks.html": [
("/tools/json-formatter", "JSON Formatter"),
],
"kubernetes-commands.html": [
("/tools/yaml-validator", "YAML Validator"),
],
}
def add_tool_links(filepath, links):
"""Add tool card links to the Related Resources section."""
with open(filepath, 'r') as f:
content = f.read()
added = 0
for url, title in links:
# Check if this link already exists
if url in content:
continue
# Find the end of the Related Resources grid div
# Look for </div> after "Related Resources"
related_pos = content.find('Related Resources')
if related_pos == -1:
continue
# Find the closing </div> of the grid
grid_start = content.find('<div class="grid">', related_pos)
if grid_start == -1:
continue
# Find the </div> that closes the grid
grid_end = content.find('</div>', grid_start + 18)
if grid_end == -1:
continue
# Insert new card before the closing </div>
card = f''' <a href="{url}" class="tool-card">
<h3>{title}</h3>
</a>
'''
content = content[:grid_end] + card + content[grid_end:]
added += 1
if added > 0:
with open(filepath, 'w') as f:
f.write(content)
print(f" Added {added} tool links to {os.path.basename(filepath)}")
return True
else:
print(f" SKIP (already linked): {os.path.basename(filepath)}")
return False
def main():
count = 0
for filename, links in TOOL_LINKS.items():
filepath = os.path.join(CS_DIR, filename)
if os.path.exists(filepath):
if add_tool_links(filepath, links):
count += 1
else:
print(f" NOT FOUND: {filepath}")
print(f"\nDone! Updated {count} cheat sheet pages with tool links.")
if __name__ == '__main__':
main()