Update sitemap.py
This commit is contained in:
parent
79a8cefe5d
commit
375aa85505
@ -18,17 +18,16 @@
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import re
|
||||
|
||||
canonical = "https://docs.pyrogram.org/"
|
||||
|
||||
dirs = {
|
||||
"start": ("weekly", 0.9),
|
||||
"resources": ("weekly", 0.8),
|
||||
"pyrogram": ("weekly", 0.8),
|
||||
"functions": ("monthly", 0.7),
|
||||
"types": ("monthly", 0.7),
|
||||
"errors": ("weekly", 0.6)
|
||||
".": ("weekly", 1.0),
|
||||
"intro": ("weekly", 0.8),
|
||||
"start": ("weekly", 0.8),
|
||||
"api": ("weekly", 0.6),
|
||||
"topics": ("weekly", 0.6),
|
||||
"telegram": ("weekly", 0.4)
|
||||
}
|
||||
|
||||
|
||||
@ -37,10 +36,10 @@ def now():
|
||||
|
||||
|
||||
with open("sitemap.xml", "w") as f:
|
||||
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||
f.write("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n")
|
||||
f.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
||||
f.write('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n')
|
||||
|
||||
urls = [(canonical, now(), "weekly", 1.0)]
|
||||
urls = []
|
||||
|
||||
|
||||
def search(path):
|
||||
@ -48,14 +47,27 @@ with open("sitemap.xml", "w") as f:
|
||||
for j in os.listdir(path):
|
||||
search("{}/{}".format(path, j))
|
||||
except NotADirectoryError:
|
||||
d = path.split("/")[0]
|
||||
path = "{}/{}".format(canonical, path.split(".")[0])
|
||||
path = re.sub("^(.+)/index$", "\g<1>", path)
|
||||
urls.append((path, now(), dirs[d][0], dirs[d][1]))
|
||||
if not path.endswith(".rst"):
|
||||
return
|
||||
|
||||
path = path.split("/")[1:]
|
||||
|
||||
if path[0].endswith(".rst"):
|
||||
folder = "."
|
||||
else:
|
||||
folder = path[0]
|
||||
|
||||
path = "{}{}".format(canonical, "/".join(path))[:-len(".rst")]
|
||||
|
||||
if path.endswith("index"):
|
||||
path = path[:-len("index")]
|
||||
|
||||
urls.append((path, now(), *dirs[folder]))
|
||||
|
||||
|
||||
for i in dirs.keys():
|
||||
search(i)
|
||||
search("source")
|
||||
|
||||
urls.sort(key=lambda x: x[3], reverse=True)
|
||||
|
||||
for i in urls:
|
||||
f.write(" <url>\n")
|
Loading…
Reference in New Issue
Block a user