Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd0005f

Browse files
committed
Refactor build process to fetch Linux commands from API, update HTML metadata for 2025, and revise sitemap with new last modified dates
1 parent 7c1bb46 commit bd0005f

File tree

4 files changed

+620
-1089
lines changed

4 files changed

+620
-1089
lines changed

‎build.py

Lines changed: 113 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
import re
22
import os
3+
import requests
34

45

5-
# 解析 Markdown 文件
6-
def parse_markdown(file_path):
6+
# 使用 API 获取数据
7+
def fetch_commands_from_api():
8+
url = "https://labex.io/api/v2/courses/linux-commands-cheatsheet/labs"
9+
print(f"Fetching commands from {url}...")
10+
try:
11+
response = requests.get(url, timeout=10)
12+
response.raise_for_status() # Will raise an HTTPError for bad responses (4xx or 5xx)
13+
api_data = response.json()
14+
except requests.exceptions.RequestException as e:
15+
print(f"Error fetching data from API: {e}")
16+
return []
17+
718
commands = []
8-
with open(file_path, "r", encoding="utf-8") as file:
9-
content = file.read()
10-
sections = re.split(r"^#\s", content, flags=re.M)[1:] # 按一级标题分割
11-
for section in sections:
12-
category, *lines = section.splitlines()
13-
table_lines = [line for line in lines if "|" in line]
14-
if table_lines:
15-
for row in table_lines[2:]: # 跳过表头
16-
cols = [col.strip() for col in row.split("|")[1:-1]]
17-
if len(cols) == 2:
18-
command_link = re.search(r"\((.*?)\)", cols[0])
19-
command_name = re.sub(r"\[|\]\(.*?\)", "", cols[0]).strip()
20-
commands.append(
21-
{
22-
"category": category.strip(),
23-
"name": command_name,
24-
"link": command_link.group(1) if command_link else "#",
25-
"description": cols[1],
26-
}
27-
)
19+
for stage in api_data.get("stages", []):
20+
category = stage.get("name")
21+
for lab in stage.get("labs", []):
22+
lab_name = lab.get("name")
23+
lab_alias = lab.get("alias")
24+
25+
if not all([lab_name, lab_alias]):
26+
continue
27+
28+
# Parse command name from lab name
29+
# e.g. "Linux ls Command with Practical Examples" -> "ls"
30+
command_parts = lab_name.split()
31+
if len(command_parts) > 1 and command_parts[0] == "Linux":
32+
command_name = command_parts[1]
33+
else:
34+
command_name = lab_name # Fallback to full name
35+
36+
commands.append(
37+
{
38+
"category": category,
39+
"name": command_name,
40+
"link": f"https://labex.io/tutorials/{lab_alias}",
41+
"description": lab.get("description"),
42+
}
43+
)
2844
return commands
2945

3046

@@ -36,33 +52,60 @@ def render_html(commands):
3652
<!DOCTYPE html>
3753
<html lang="en">
3854
<head>
39-
<meta charset="UTF-8">
40-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
41-
<title>Linux Commands Cheat Sheet - Full List - 2024 | LabEx</title>
42-
<meta name="description" content="A full list of essential Linux commands with detailed explanations and examples. Best linux commands cheat sheet for beginners and advanced users.">
43-
<meta name="keywords" content="Linux commands, Linux cheat sheet, command-line guide, Linux tips, Linux reference, Linux tutorials">
44-
<meta name="author" content="labex.io">
45-
<meta name="robots" content="index, follow">
46-
<link rel="canonical" href="https://linux-commands.labex.io">
55+
<meta charset="UTF-8" />
56+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
57+
<title>Linux Commands Cheat Sheet PDF - 2025 | LabEx</title>
58+
<meta
59+
name="description"
60+
content="A full list of essential Linux commands with detailed explanations and examples. Download the best linux commands cheat sheet PDF for beginners and advanced users."
61+
/>
62+
<meta
63+
name="keywords"
64+
content="Linux commands, Linux cheat sheet, linux commands cheat sheet pdf, command-line guide, Linux tips, Linux reference, Linux tutorials"
65+
/>
66+
<meta name="author" content="labex.io" />
67+
<meta name="robots" content="index, follow" />
68+
<link rel="canonical" href="https://linux-commands.labex.io" />
4769
4870
<!-- Open Graph Tags -->
49-
<meta property="og:title" content="Linux Commands Cheat Sheet - Full List - 2024 | LabEx">
50-
<meta property="og:description" content="A full list of essential Linux commands with detailed explanations and examples. Best linux commands cheat sheet for beginners and advanced users.">
51-
<meta property="og:type" content="website">
52-
<meta property="og:url" content="https://linux-commands.labex.io">
53-
<meta property="og:image" content="https://linux-commands.labex.io/assets/og-image.png">
54-
<meta property="og:site_name" content="Linux Commands Cheat Sheet">
71+
<meta
72+
property="og:title"
73+
content="Linux Commands Cheat Sheet PDF - 2025 | LabEx"
74+
/>
75+
<meta
76+
property="og:description"
77+
content="A full list of essential Linux commands with detailed explanations and examples. Download the best linux commands cheat sheet PDF for beginners and advanced users."
78+
/>
79+
<meta property="og:type" content="website" />
80+
<meta property="og:url" content="https://linux-commands.labex.io" />
81+
<meta
82+
property="og:image"
83+
content="https://linux-commands.labex.io/assets/og-image.png"
84+
/>
85+
<meta property="og:site_name" content="Linux Commands Cheat Sheet" />
5586
5687
<!-- Twitter Card Tags -->
57-
<meta name="twitter:card" content="summary_large_image">
58-
<meta name="twitter:title" content="Linux Commands Cheat Sheet - Full List - 2024 | LabEx">
59-
<meta name="twitter:description" content="A comprehensive Linux commands cheat sheet with detailed explanations and examples. Best linux commands reference for beginners and advanced users.">
60-
<meta name="twitter:image" content="https://linux-commands.labex.io/assets/og-image.png">
88+
<meta name="twitter:card" content="summary_large_image" />
89+
<meta
90+
name="twitter:title"
91+
content="Linux Commands Cheat Sheet PDF - 2025 | LabEx"
92+
/>
93+
<meta
94+
name="twitter:description"
95+
content="A comprehensive Linux commands cheat sheet with detailed explanations and examples. Download the best linux commands reference PDF for beginners and advanced users."
96+
/>
97+
<meta
98+
name="twitter:image"
99+
content="https://linux-commands.labex.io/assets/og-image.png"
100+
/>
61101
62102
<script src="https://cdn.tailwindcss.com"></script>
63-
<link rel="preconnect" href="https://fonts.googleapis.com">
64-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
65-
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=Parkinsans:wght@300..800&display=swap" rel="stylesheet">
103+
<link rel="preconnect" href="https://fonts.googleapis.com" />
104+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
105+
<link
106+
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=Parkinsans:wght@300..800&display=swap"
107+
rel="stylesheet"
108+
/>
66109
<!-- Google tag (gtag.js) -->
67110
<script async src="https://www.googletagmanager.com/gtag/js?id=G-ZFCX52ZJTZ"></script>
68111
<script>
@@ -159,6 +202,27 @@ def render_html(commands):
159202
<h1 class="text-4xl font-extrabold">Linux Commands Cheat Sheet</h1>
160203
<p class="mt-2 text-lg">A clean and minimal guide to {total_commands} Linux commands</p>
161204
<img src="assets/labex-logo-white.svg" alt="LabEx Logo" class="mx-auto mt-8">
205+
<a
206+
href="assets/linux-commands-cheat-sheet.pdf"
207+
download
208+
class="inline-flex items-center mt-6 px-6 py-3 bg-white text-[#2E7EEE] font-semibold rounded-lg hover:bg-gray-100 transition-colors duration-200"
209+
>
210+
<svg
211+
xmlns="http://www.w3.org/2000/svg"
212+
class="h-5 w-5 mr-2"
213+
fill="none"
214+
viewBox="0 0 24 24"
215+
stroke="currentColor"
216+
>
217+
<path
218+
stroke-linecap="round"
219+
stroke-linejoin="round"
220+
stroke-width="2"
221+
d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
222+
/>
223+
</svg>
224+
Download PDF
225+
</a>
162226
</div>
163227
</header>
164228
<nav>
@@ -181,7 +245,7 @@ def render_html(commands):
181245
</main>
182246
<footer class="bg-[#2E7EEE] text-white py-6">
183247
<div class="container mx-auto text-center">
184-
<p >&copy; 2024 <a href="https://labex.io">LabEx</a>. All rights reserved.</p>
248+
<p class="text-sm">&copy; 2025 <a href="https://labex.io">LabEx</a>. All rights reserved.</p>
185249
</div>
186250
</footer>
187251
</body>
@@ -254,7 +318,7 @@ def render_html(commands):
254318

255319

256320
# 在 render_html 函数后添加这两个新函数
257-
def generate_sitemap():
321+
def generate_sitemap(commands):
258322
# 获取所有命令的链接
259323
def get_url_entries(commands):
260324
entries = []
@@ -291,8 +355,8 @@ def get_url_entries(commands):
291355

292356
current_date = datetime.now().strftime("%Y-%m-%d")
293357

294-
# 重新解析 README 获取所有链接
295-
all_commands = parse_markdown("README.md")
358+
# We will use the fetched commands directly
359+
all_commands = commands
296360
entries = get_url_entries(all_commands)
297361

298362
with open("sitemap.xml", "w", encoding="utf-8") as f:
@@ -315,10 +379,9 @@ def generate_robots_txt():
315379

316380
# 修改主函数
317381
if __name__ == "__main__":
318-
input_file = "README.md"
319382
output_file = "index.html"
320383

321-
commands = parse_markdown(input_file)
384+
commands = fetch_commands_from_api()
322385
html_content = render_html(commands)
323386

324387
# 先运行 prettier 只格式化 HTML
@@ -328,5 +391,5 @@ def generate_robots_txt():
328391
print(f"HTML file generated: {output_file}")
329392

330393
# 然后生成 sitemap.xml 和 robots.txt
331-
generate_sitemap()
394+
generate_sitemap(commands)
332395
generate_robots_txt()

‎index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
@@ -153,7 +153,7 @@
153153
(navigator.userAgent.toLowerCase().indexOf("mac") != -1
154154
? "Command/Cmd"
155155
: "CTRL") +
156-
" + D to bookmark this page."
156+
" + D to bookmark this page.",
157157
);
158158
}
159159
}
@@ -472,7 +472,7 @@ <h3 class="text-xl font-extrabold text-gray-900">mkdir</h3>
472472
</a>
473473

474474
<a
475-
href="https://labex.io/tutorials/linux-linux-touch-command-with-practical-examples-422962"
475+
href="https://labex.io/tutorials/linux-create-and-manage-files-with-the-linux-touch-command-422962"
476476
target="_blank"
477477
class="card block bg-white shadow-lg rounded-lg p-6 hover:shadow-xl hover:bg-gray-50 transition-all duration-200 border-2 border-transparent"
478478
>
@@ -1240,7 +1240,7 @@ <h3 class="text-xl font-extrabold text-gray-900">whereis</h3>
12401240
</a>
12411241

12421242
<a
1243-
href="https://labex.io/tutorials/linux-linux-file-command-with-practical-examples-422681"
1243+
href="https://labex.io/tutorials/linux-how-to-identify-file-types-with-the-linux-file-command-422681"
12441244
target="_blank"
12451245
class="card block bg-white shadow-lg rounded-lg p-6 hover:shadow-xl hover:bg-gray-50 transition-all duration-200 border-2 border-transparent"
12461246
>
@@ -1553,7 +1553,7 @@ <h3 class="text-xl font-extrabold text-gray-900">mc</h3>
15531553
</a>
15541554

15551555
<a
1556-
href="https://labex.io/tutorials/linux-linux-readlink-command-with-practical-examples-422882"
1556+
href="https://labex.io/tutorials/linux-how-to-resolve-symbolic-links-with-the-readlink-command-422882"
15571557
target="_blank"
15581558
class="card block bg-white shadow-lg rounded-lg p-6 hover:shadow-xl hover:bg-gray-50 transition-all duration-200 border-2 border-transparent"
15591559
>
@@ -1826,7 +1826,7 @@ <h3 class="text-xl font-extrabold text-gray-900">lsattr</h3>
18261826
</a>
18271827

18281828
<a
1829-
href="https://labex.io/tutorials/linux-linux-cksum-command-with-practical-examples-422605"
1829+
href="https://labex.io/tutorials/linux-verify-file-integrity-with-linux-cksum-422605"
18301830
target="_blank"
18311831
class="card block bg-white shadow-lg rounded-lg p-6 hover:shadow-xl hover:bg-gray-50 transition-all duration-200 border-2 border-transparent"
18321832
>
@@ -10015,7 +10015,7 @@ <h3 class="text-xl font-extrabold text-gray-900">httpd</h3>
1001510015
</a>
1001610016

1001710017
<a
10018-
href="netcat"
10018+
href="https://labex.io/tutorials/linux-linux-nc-netcat-command-with-practical-examples-422835"
1001910019
target="_blank"
1002010020
class="card block bg-white shadow-lg rounded-lg p-6 hover:shadow-xl hover:bg-gray-50 transition-all duration-200 border-2 border-transparent"
1002110021
>
@@ -19842,7 +19842,7 @@ <h3 class="text-xl font-extrabold text-gray-900">info</h3>
1984219842
</a>
1984319843

1984419844
<a
19845-
href="https://labex.io/tutorials/linux-linux-whatis-command-with-practical-examples-423005"
19845+
href="https://labex.io/tutorials/linux-quickly-identify-linux-command-purposes-with-whatis-423005"
1984619846
target="_blank"
1984719847
class="card block bg-white shadow-lg rounded-lg p-6 hover:shadow-xl hover:bg-gray-50 transition-all duration-200 border-2 border-transparent"
1984819848
>
@@ -22511,7 +22511,7 @@ <h3 class="text-xl font-extrabold text-gray-900">rev</h3>
2251122511
<footer class="bg-[#2E7EEE] text-white py-6">
2251222512
<div class="container mx-auto text-center">
2251322513
<p class="text-sm">
22514-
&copy; 2025 <a href="https://labex.io">LabEx</a>. All rights reserved.
22514+
&copy; 2024 <a href="https://labex.io">LabEx</a>. All rights reserved.
2251522515
</p>
2251622516
</div>
2251722517
</footer>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /