Browse Source

대규모 위키에서도 사이트맵 사용할 수 있게

Surplus_Up (2DU) 6 năm trước cách đây
mục cha
commit
5825eba342
4 tập tin đã thay đổi với 36 bổ sung7 xóa
  1. 1 0
      .gitignore
  2. 33 5
      route/api_sitemap.py
  3. 1 1
      route/main_file.py
  4. 1 1
      version.json

+ 1 - 0
.gitignore

@@ -26,3 +26,4 @@ views/nitori
 
 .DS_Store
 sitemap.xml
+sitemap_0.xml

+ 33 - 5
route/api_sitemap.py

@@ -6,21 +6,49 @@ def api_sitemap_2(conn):
     if admin_check() == 1:
         data = '' + \
             '<?xml version="1.0" encoding="UTF-8"?>\n' + \
-            '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + \
+            '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + \
         ''
 
         curs.execute(db_change("select title from data"))
-        for i in curs.fetchall():
-            data += '<url><loc>' + flask.request.host_url + 'w/' + url_pas(i[0]) + '</loc></url>\n'
+        all_data = curs.fetchall()
+
+        len_all_data = len(all_data)
+        count = int(len_all_data / 30000)
+        other_count = len_all_data % 30000
+
+        for i in range(count + 1):
+            data += '<sitemap><loc>sitemap_' + str(i) + '.xml</loc></sitemap>\n'
 
         data += '' + \
-            '</urlset>' + \
+            '</sitemapindex>' + \
         ''
 
         f = open("sitemap.xml", 'w')
         f.write(data)
         f.close()
 
-        return flask.Response(data, mimetype = 'text/xml')
+        e = 0
+        for i in range(count + 1):
+            data = '' + \
+                '<?xml version="1.0" encoding="UTF-8"?>\n' + \
+                '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + \
+            ''
+
+            if count == i:
+                for x in all_data[30000 * i:]:
+                    data += '<url><loc>' + flask.request.host_url + 'w/' + url_pas(x[0]) + '</loc></url>\n'
+            else:
+                for x in all_data[30000 * i:30000 * (i + 1)]:
+                    data += '<url><loc>' + flask.request.host_url + 'w/' + url_pas(x[0]) + '</loc></url>\n'
+
+            data += '' + \
+                '</urlset>' + \
+            ''
+
+            f = open("sitemap_" + str(i) + ".xml", 'w')
+            f.write(data)
+            f.close()
+
+        return redirect('/sitemap.xml')
     else:
         return re_error('/ban')

+ 1 - 1
route/main_file.py

@@ -10,7 +10,7 @@ def main_file_2(conn, data):
             data = open('./views/main_css/file/easter_egg.html', encoding='utf8').read(),
             menu = 0
         ))
-    elif re.search(r'\.txt$', data, flags = re.I) or data == 'sitemap.xml':
+    elif re.search(r'\.(txt|xml)$', data, flags = re.I):
         if data == 'robots.txt' and not os.path.exists('robots.txt'):
             return flask.Response('User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/', mimetype = 'text/plain')
         elif os.path.exists(data):

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "master" : {
-        "r_ver" : "v3.1.9-master-23",
+        "r_ver" : "v3.1.9-master-24",
         "c_ver" : "3192100",
         "s_ver" : "9"
     }, "stable" : {