Procházet zdrojové kódy

feat: 支持多域名ICP备案号

SongZihuan před 2 roky
rodič
revize
793b778137
4 změnil soubory, kde provedl 26 přidání a 12 odebrání
  1. 16 2
      app/index.py
  2. 2 2
      configure/__init__.py
  3. 4 4
      templates/base.html
  4. 4 4
      templates/index/hello.html

+ 16 - 2
app/index.py

@@ -1,4 +1,4 @@
-from flask import Blueprint, render_template
+from flask import Blueprint, render_template, request
 from flask_login import current_user
 
 from configure import conf
@@ -39,6 +39,18 @@ def inject_base():
     return {"top_nav": ["active", "", "", "", "", ""]}
 
 
+def get_icp():
+    for i in conf["ICP"]:
+        if i in request.host:
+            return conf["ICP"][i]
+
+
+def get_gongan():
+    for i in conf["GONG_AN"]:
+        if i in request.host:
+            return conf["GONG_AN"][i]
+
+
 @index.app_context_processor
 @app.cache.cached(timeout=conf["CACHE_EXPIRE"], key_prefix="inject_base")
 def inject_base():
@@ -46,4 +58,6 @@ def inject_base():
     return {"blog_name": conf['BLOG_NAME'],
             "top_nav": ["", "", "", "", "", ""],
             "blog_describe": conf['BLOG_DESCRIBE'],
-            "conf": conf}
+            "conf": conf,
+            "get_icp": get_icp,
+            "get_gongan": get_gongan}

+ 2 - 2
configure/__init__.py

@@ -54,8 +54,8 @@ conf = {
     "LOG_LEVEL": logging.INFO,
     "LOG_STDERR": True,
     "LOGO": "logo.jpg",
-    "ICP": None,
-    "GONG_AN": None,
+    "ICP": {},
+    "GONG_AN": {},
 }
 
 

+ 4 - 4
templates/base.html

@@ -108,16 +108,16 @@
     <footer id="foot">
         <hr>
         {{ conf['FOOT'] }}
-        {% if conf["ICP"] %}
+        {% if get_icp() %}
             <br> <a id="ICP2" href="https://beian.miit.gov.cn" target="_blank"
                 style="display:inline-block;text-decoration:none;height:20px;line-height:20px;" >
-                {{ conf['ICP'] }} </a>
-            {% if conf["GONG_AN"] %}
+                {{ get_icp() }} </a>
+            {% if get_gongan() %}
                 <br> <a id="GONG_AN2" target="_blank"
                    href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=44011402000783"
                    style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
                     <img src="{{ url_for('static', filename='wangan.png') }}" style="float:left;" alt="wangan"/>
-                    {{ conf["GONG_AN"] }}
+                    {{ get_gongan() }}
                 </a>
             {% endif %}
         {% endif %}

+ 4 - 4
templates/index/hello.html

@@ -26,17 +26,17 @@
 {% endblock %}
 
 {% block footer %}
-    {% if conf["ICP"] %}
+    {% if get_icp() %}
         <footer id="foot">
             <a id="ICP" href="https://beian.miit.gov.cn" target="_blank"
                 style="display:inline-block;text-decoration:none;height:20px;line-height:20px;" >
-                {{ conf['ICP'] }} </a>
-            {% if conf["GONG_AN"] %}
+                {{ get_icp() }} </a>
+            {% if get_gongan() %}
                 <br> <a id="GONG_AN" target="_blank"
                    href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=44011402000783"
                    style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
                     <img src="{{ url_for('static', filename='wangan.png') }}" style="float:left;"/>
-                    {{ conf["GONG_AN"] }}
+                    {{ get_gongan() }}
                 </a>
             {% endif %}
         </footer>