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