فهرست منبع

fix sitemap func

잉여개발기 (SPDV) 3 سال پیش
والد
کامیت
7b9a477a5d
8فایلهای تغییر یافته به همراه133 افزوده شده و 65 حذف شده
  1. 1 2
      app.py
  2. 6 1
      lang/en-US.json
  3. 6 2
      lang/ko-KR.json
  4. 0 56
      route/api_sitemap.py
  5. 2 1
      route/main_func_setting.py
  6. 116 0
      route/main_func_setting_sitemap.py
  7. 1 2
      route/main_tool_admin.py
  8. 1 1
      version.json

+ 1 - 2
app.py

@@ -605,8 +605,6 @@ app.route('/api/sha224/<everything:data>', methods = ['POST', 'GET'])(api_func_s
 
 app.route('/api/title_index')(api_title_index)
 app.route('/api/image/<everything:name>', methods = ['POST', 'GET'])(api_image_view)
-# 이건 API 영역이 아닌 것 같아서 고심 중
-app.route('/api/sitemap.xml')(api_sitemap)
 
 # Func-main
 # 여기도 전반적인 조정 시행 예정
@@ -634,6 +632,7 @@ app.route('/setting/body/bottom/<skin_name>', defaults = { 'num' : 7 }, methods
 app.route('/setting/robot', methods = ['POST', 'GET'])(main_func_setting_robot)
 app.route('/setting/external', methods = ['POST', 'GET'])(main_func_setting_external)
 app.route('/setting/acl', methods = ['POST', 'GET'])(main_func_setting_acl)
+app.route('/setting/sitemap', methods = ['POST', 'GET'])(main_func_setting_sitemap)
 
 # views -> view
 app.route('/view/<everything:name>')(main_view)

+ 6 - 1
lang/en-US.json

@@ -210,7 +210,6 @@
         "link_in_this" : "Links in this document",
         "star_doc" : "Document(s) of interest",
         "add_star_doc" : "Add document(s) of interest",
-        "get_sitemap" : "Create or renewal sitemap.xml",
         "simple_check" : "Simple check",
         "add_user" : "Add user",
         "2fa" : "2FA",
@@ -337,6 +336,12 @@
                 "oauth" : "OAuth",
                 "_comment_2.2.4.2_" : "OAuth",
                     "oauth_client_id" : "OAuth client ID",
+            "_comment_" : "Sitemap",
+                "sitemap_management" : "sitemap.xml management",
+                "stiemap_exclude_domain" : "Exclude domain",
+                "stiemap_exclude_user_page" : "Exclude user page(s)",
+                "stiemap_exclude_file_page" : "Exclude file page(s)",
+                "stiemap_exclude_category_page" : "Exclude category page(s)",
         "_comment_2.3_" : "List",
             "open_discussion_list" : "Open discussion(s) list",
             "discussion_list" : "Discussion(s) list",

+ 6 - 2
lang/ko-KR.json

@@ -362,7 +362,7 @@
     "backup_where": "백업 위치",
     "empty": "빈칸",
     "email_send_error": "이메일 전송이 실패했습니다.",
-    "get_sitemap": "sitemap.xml 만들거나 갱신하기",
+    "sitemap_management": "sitemap.xml 관리",
     "same_ip_exist": "동일한 아이피가 존재합니다.",
     "restart_fail_error": "재시작이 실패했습니다. 수동 재시작을 이용해주세요.",
     "domain": "도메인",
@@ -456,5 +456,9 @@
     "set_history_recording_off": "역사 기록 중지",
     "multiple_ban": "다중 차단",
     "name_or_ip_or_regex_multiple": "한 줄에 IP나 정규식을 한 개씩 적어주세요.",
-    "dont_move" : "이동하지 않음"
+    "dont_move": "이동하지 않음",
+    "stiemap_exclude_domain": "도메인 제외",
+    "stiemap_exclude_user_page": "사용자 문서 제외",
+    "stiemap_exclude_file_page": "파일 문서 제외",
+    "stiemap_exclude_category_page": "분류 문서 제외"
 }

+ 0 - 56
route/api_sitemap.py

@@ -1,56 +0,0 @@
-from .tool.func import *
-
-def api_sitemap():
-    with get_db_connect() as conn:
-        curs = conn.cursor()
-
-        if admin_check(None, 'make sitemap') == 1:
-            data = '' + \
-                '<?xml version="1.0" encoding="UTF-8"?>\n' + \
-                '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + \
-            ''
-            domain = load_domain('full')
-
-            curs.execute(db_change("select title from data"))
-            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>' + domain + '/sitemap_' + str(i) + '.xml</loc></sitemap>\n'
-
-            data += '' + \
-                '</sitemapindex>' + \
-            ''
-
-            f = open("sitemap.xml", 'w')
-            f.write(data)
-            f.close()
-
-            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>' + domain + '/w/' + url_pas(x[0]) + '</loc></url>\n'
-                else:
-                    for x in all_data[30000 * i:30000 * (i + 1)]:
-                        data += '<url><loc>' + domain + '/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')

+ 2 - 1
route/main_func_setting.py

@@ -9,7 +9,8 @@ def main_func_setting():
             ['external', load_lang('ext_api_req_set')],
             ['head', load_lang('main_head')],
             ['body/top', load_lang('main_body')],
-            ['body/bottom', load_lang('main_bottom_body')]
+            ['body/bottom', load_lang('main_bottom_body')],
+            ['sitemap', load_lang('sitemap_management') + ' (' + load_lang('beta') + ')']
         ]
 
         li_data = ''.join(['<li><a href="/setting/' + str(li[0]) + '">' + li[1] + '</a></li>' for li in li_list])

+ 116 - 0
route/main_func_setting_sitemap.py

@@ -0,0 +1,116 @@
+from .tool.func import *
+
+def main_func_setting_sitemap():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+
+        if admin_check() != 1:
+            return re_error('/ban')
+        
+        if flask.request.method == 'POST':
+            admin_check(None, 'make sitemap')
+
+            data = '' + \
+                '<?xml version="1.0" encoding="UTF-8"?>\n' + \
+                '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + \
+            ''
+
+            if flask.request.form.get('exclude_domain', None):
+                domain = ''
+            else:
+                domain = load_domain('full')
+
+            sql_add = ''
+            if flask.request.form.get('exclude_user_page', None):
+                sql_add += ' title not like "user:%"'
+
+            if flask.request.form.get('exclude_file_page', None):
+                if sql_add != '':
+                    sql_add += ' and'
+
+                sql_add += ' title not like "file:%"'
+
+            if flask.request.form.get('exclude_category_page', None):
+                if sql_add != '':
+                    sql_add += ' and'
+
+                sql_add += ' title not like "category:%"'
+
+            if sql_add != '':
+                sql_add = ' where' + sql_add
+
+            print(sql_add)
+            curs.execute(db_change("select title from data" + sql_add))
+            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>' + domain + '/sitemap_' + str(i) + '.xml</loc></sitemap>\n'
+
+            data += '' + \
+                '</sitemapindex>' + \
+            ''
+
+            f = open("sitemap.xml", 'w')
+            f.write(data)
+            f.close()
+
+            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>' + domain + '/w/' + url_pas(x[0]) + '</loc></url>\n'
+                else:
+                    for x in all_data[30000 * i:30000 * (i + 1)]:
+                        data += '<url><loc>' + domain + '/w/' + url_pas(x[0]) + '</loc></url>\n'
+
+                data += '' + \
+                    '</urlset>' + \
+                ''
+
+                f = open("sitemap_" + str(i) + ".xml", 'w')
+                f.write(data)
+                f.close()
+
+            return redirect('/setting/sitemap')
+        else:
+            sitemap_list = ''
+            if os.path.exists('sitemap.xml'):
+                sitemap_list += '<a href="/sitemap.xml">(' + load_lang('view') + ')</a>'
+
+                for_a = 0
+                while os.path.exists('sitemap_' + str(for_a) + '.xml'):
+                    sitemap_list += ' <a href="/sitemap_' + str(for_a) + '.xml">(sitemap_' + str(for_a) + '.xml)</a>'
+
+                    for_a += 1
+
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('sitemap_management'), wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('beta') + ')', 0])],
+                data = '''
+                    ''' + sitemap_list + '''
+                    <hr class="main_hr">
+                    <form method="post">
+                        <input type="checkbox" name="exclude_domain"> ''' + load_lang('stiemap_exclude_domain') + '''
+                        <hr class="main_hr">
+
+                        <input type="checkbox" name="exclude_user_page"> ''' + load_lang('stiemap_exclude_user_page') + '''
+                        <hr class="main_hr">
+
+                        <input type="checkbox" name="exclude_file_page"> ''' + load_lang('stiemap_exclude_file_page') + '''
+                        <hr class="main_hr">
+
+                        <input type="checkbox" name="exclude_category_page"> ''' + load_lang('stiemap_exclude_category_page') + '''
+                        <hr class="main_hr">
+
+                        <button id="save" type="submit">''' + load_lang('create') + '''</button>
+                    </form>
+                ''',
+                menu = [['setting', load_lang('return')]]
+            ))

+ 1 - 2
route/main_tool_admin.py

@@ -20,7 +20,6 @@ def main_tool_admin():
                         <li><a href="/admin_group">''' + load_lang('admin_group_list') + '''</a></li>
                         <li><a href="/delete_multiple">''' + load_lang('many_delete') + '''</a></li>
                         <li><a href="/app_submit">''' + load_lang('application_list') + '''</a></li>
-                        <li><a href="/api/sitemap.xml">''' + load_lang('get_sitemap') + '''</a></li>
                         <li><a href="/register">''' + load_lang('add_user') + '''</a></li>
                         <li><a href="/setting">''' + load_lang('setting') + '''</a></li>
                     </ul>
@@ -34,7 +33,7 @@ def main_tool_admin():
                         <li><a href="/name_filter">''' + load_lang('id_filter_list') + '''</a></li>
                         <li><a href="/file_filter">''' + load_lang('file_filter_list') + '''</a></li>
                         <li><a href="/extension_filter">''' + load_lang('extension_filter_list') + '''</a></li>
-                        <li><a href="/filter/document/list">''' + load_lang('document_filter_list') + ''' ''' + load_lang('beta') + '''</a></li>
+                        <li><a href="/filter/document/list">''' + load_lang('document_filter_list') + ''' (''' + load_lang('beta') + ''')</a></li>
                     </ul>
                     <h3>2.2. ''' + load_lang('server') + '''</h2>
                     <ul class="inside_ul">

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.4.5 (stable2) (beta3) (dev41)",
+        "r_ver" : "v3.4.5 (stable2) (beta3) (dev42)",
         "c_ver" : "3500113",
         "s_ver" : "3500110"
     }