Skip to content

Commit 375aa85

Browse files
committed
Update sitemap.py
1 parent 79a8cef commit 375aa85

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818

1919
import datetime
2020
import os
21-
import re
2221

2322
canonical = "https://docs.pyrogram.org/"
2423

2524
dirs = {
26-
"start": ("weekly", 0.9),
27-
"resources": ("weekly", 0.8),
28-
"pyrogram": ("weekly", 0.8),
29-
"functions": ("monthly", 0.7),
30-
"types": ("monthly", 0.7),
31-
"errors": ("weekly", 0.6)
25+
".": ("weekly", 1.0),
26+
"intro": ("weekly", 0.8),
27+
"start": ("weekly", 0.8),
28+
"api": ("weekly", 0.6),
29+
"topics": ("weekly", 0.6),
30+
"telegram": ("weekly", 0.4)
3231
}
3332

3433

@@ -37,25 +36,38 @@ def now():
3736

3837

3938
with open("sitemap.xml", "w") as f:
40-
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
41-
f.write("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n")
39+
f.write('<?xml version="1.0" encoding="utf-8"?>\n')
40+
f.write('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n')
4241

43-
urls = [(canonical, now(), "weekly", 1.0)]
42+
urls = []
4443

4544

4645
def search(path):
4746
try:
4847
for j in os.listdir(path):
4948
search("{}/{}".format(path, j))
5049
except NotADirectoryError:
51-
d = path.split("/")[0]
52-
path = "{}/{}".format(canonical, path.split(".")[0])
53-
path = re.sub("^(.+)/index$", "\g<1>", path)
54-
urls.append((path, now(), dirs[d][0], dirs[d][1]))
50+
if not path.endswith(".rst"):
51+
return
5552

53+
path = path.split("/")[1:]
5654

57-
for i in dirs.keys():
58-
search(i)
55+
if path[0].endswith(".rst"):
56+
folder = "."
57+
else:
58+
folder = path[0]
59+
60+
path = "{}{}".format(canonical, "/".join(path))[:-len(".rst")]
61+
62+
if path.endswith("index"):
63+
path = path[:-len("index")]
64+
65+
urls.append((path, now(), *dirs[folder]))
66+
67+
68+
search("source")
69+
70+
urls.sort(key=lambda x: x[3], reverse=True)
5971

6072
for i in urls:
6173
f.write(" <url>\n")

0 commit comments

Comments
 (0)