Explorar o código

further reading and update btn

Jason %!s(int64=2) %!d(string=hai) anos
pai
achega
f6aafed45a
Modificáronse 3 ficheiros con 128 adicións e 2 borrados
  1. 47 2
      backstage/blogs/routes.py
  2. 69 0
      backstage/templates/further.html
  3. 12 0
      backstage/templates/layout.html

+ 47 - 2
backstage/blogs/routes.py

@@ -11,6 +11,7 @@ from backstage.blogs.forms import BlogCreateForm
 from backstage.utils import get_now_time, translate
 from backstage.utils.routes import create_content, remove_content, get_trans_title_url_name
 from backstage.config import PORTAL_SERVER, UPLOAD_PATH_MAP, BHOUSE_WEB_DIR
+from bs4 import BeautifulSoup
 
 blogs_app = Blueprint('blogs', __name__)
 
@@ -133,6 +134,12 @@ image: ""\n
     # get_trans_title_url_name()
     return furniturePath
 
+@blogs_app.route('/backstage/update', methods=['GET'])
+def update():
+    stream = os.popen('/var/www/bhouse2/New-Bhouse-Web; hugo; rsync -azn -e ssh /var/www/bhouse2/New-Bhouse-Web/public root@172.105.241.163:/var/www/New-Bhouse-Web')
+    output = stream.read()
+    print(output)
+    return redirect(url_for('blogs.blog_list'))
 
 @blogs_app.route('/backstage/blogs', methods=['GET'])
 def blog_list():
@@ -224,12 +231,16 @@ def edit_news():
 
 @blogs_app.route('/backstage/edit_contact_us', methods=['GET'])
 def edit_contact_us():
-    response = requests.get('{}contents?url=/contact'.format(PORTAL_SERVER))
-    if response.status_code == 200:
         return render_template('contact_us.html',
                                title='聯絡我們',
                                )
 
+@blogs_app.route('/backstage/edit_further', methods=['GET'])
+def edit_further():
+        return render_template('further.html',
+                               title='編輯延伸閱讀',
+                               )
+
 @blogs_app.route('/backstage/edit_faq', methods=['GET'])
 def edit_faq():
     return render_template('frequently_asked_questions.html',
@@ -312,6 +323,40 @@ question_box_intro: "{}"\n\
 
     return create_content(data, form.image.data)
 
+@blogs_app.route('/backstage/edit_blog_getfurther', methods=['GET'])
+def edit_blog_getfurther():
+    txt = ""
+    datapath = BHOUSE_WEB_DIR + "/themes/hugo-universal-theme-master/layouts/partials/further.html"
+    data=[]
+    with open(datapath, encoding="utf-8") as inf:
+        obj=BeautifulSoup(inf, 'html.parser', from_encoding="utf+8").find_all("a")
+        for item in obj:
+            data.append([item.get('href'), item.text])
+
+    #sortedData = sorted(sortedData, key=lambda x: x['type'])
+    return data
+
+@blogs_app.route('/backstage/edit_blog_editfurther', methods=['GET'])
+def edit_blog_editfurther():
+    txt = ""
+    data=[]
+    data.append([request.args.get('data00', type=str), request.args.get('data01', type=str)])
+    data.append([request.args.get('data10', type=str), request.args.get('data11', type=str)])
+    data.append([request.args.get('data20', type=str), request.args.get('data21', type=str)])
+    data.append([request.args.get('data30', type=str), request.args.get('data31', type=str)])
+    data.append([request.args.get('data40', type=str), request.args.get('data41', type=str)])
+
+    print(data)
+    
+    datapath = BHOUSE_WEB_DIR + "/themes/hugo-universal-theme-master/layouts/partials/further.html"
+
+    with open(datapath, 'w' , encoding="utf-8") as inf:
+        for d in data:
+            if d[1]!='':
+                inf.write('<li><a href="' + d[0] + '">' + d[1] + '</a></li>\n')     
+
+    #sortedData = sorted(sortedData, key=lambda x: x['type'])
+    return "修改成功"
 
 @blogs_app.route('/backstage/blog/createCat/', methods=['GET'])
 def createCat():

+ 69 - 0
backstage/templates/further.html

@@ -0,0 +1,69 @@
+{% extends "layout.html" %}
+{% block main %}
+<!-- <script type="text/javascript" src="/static/config.js"></script> -->
+<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
+<script src="https://cdn.jsdelivr.net/npm/@editorjs/image@latest"></script><!-- Image -->
+<script type="text/javascript" src="/static/js/yo.js"></script>
+<table>
+    <tbody id='contactData'>
+        <h1 class="h3"><i class="fas fa-pen mr-3 mb-3"></i>{{ title }}</h1>
+        <tr>
+            <td>延伸閱讀文章名稱 <span class="text-danger">(請務必填寫文章名稱,否則此項文章不予顯示)</span></td>
+            <td>延伸閱讀文章連結</td>
+        </tr>
+        <tr>
+            <td class="table__data"><input class="form-control" id="data01" type="text" style="width: 600px;" placeholder="文章內容" /></td>
+            <td class="table__data"><input class="form-control" id="data00" type="text" style="width: 600px;" placeholder="文章連結" /></td>
+        </tr>
+        <tr>
+            <td class="table__data"><input class="form-control" id="data11" type="text" style="width: 600px;" placeholder="文章內容" /></td>
+            <td class="table__data"><input class="form-control" id="data10" type="text" style="width: 600px;" placeholder="文章連結" /></td>
+        </tr>
+        <tr>
+            <td class="table__data"><input class="form-control" id="data21" type="text" style="width: 600px;" placeholder="文章內容" /></td>
+            <td class="table__data"><input class="form-control" id="data20" type="text" style="width: 600px;" placeholder="文章連結" /></td>
+        </tr>
+        <tr>
+            <td class="table__data"><input class="form-control" id="data31" type="text" style="width: 600px;" placeholder="文章內容" /></td>
+            <td class="table__data"><input class="form-control" id="data30" type="text" style="width: 600px;" placeholder="文章連結" /></td>
+        </tr>
+        <tr>
+            <td class="table__data"><input class="form-control" id="data41" type="text" style="width: 600px;" placeholder="文章內容" /></td>
+            <td class="table__data"><input class="form-control" id="data40" type="text" style="width: 600px;" placeholder="文章連結" /></td>
+        </tr>
+        <tr>
+            <td>
+                <div class="d-flex justify-content-center">
+                    <button class="btn btn_light mr-1" onclick="changeArticles();"><b>儲存</b> <i
+                            class="fas fa-pencil-alt"></i></button>
+                </div>
+            </td>
+        </tr>
+
+    </tbody>
+</table>
+<script>
+    $(function(){
+        axios.get('/backstage/edit_blog_getfurther').then(({ data }) => {
+            $('#data00').val(data[0][0]);
+            $('#data01').val(data[0][1]);
+            $('#data10').val(data[1][0]);
+            $('#data11').val(data[1][1]);
+            $('#data20').val(data[2][0]);
+            $('#data21').val(data[2][1]);
+            $('#data30').val(data[3][0]);
+            $('#data31').val(data[3][1]);
+            $('#data40').val(data[4][0]);
+            $('#data41').val(data[4][1]);
+        });
+        
+    });
+
+    function changeArticles() {
+        axios.get('/backstage/edit_blog_editfurther?data00='+$('#data00').val()+'&data01='+$('#data01').val()+'&data10='+$('#data10').val()+'&data11='+$('#data11').val()+'&data20='+$('#data20').val()+'&data21='+$('#data21').val()+'&data30='+$('#data30').val()+'&data31='+$('#data31').val()+'&data40='+$('#data40').val()+'&data41='+$('#data41').val()).then(({ data }) => {
+            alert('已儲存');
+        }).finally((data) => { location.reload(); });
+    };
+
+</script>
+{% endblock main %}

+ 12 - 0
backstage/templates/layout.html

@@ -52,6 +52,12 @@
               <span class="submenu-icon ml-auto"></span>
             </div>
           </a> -->
+          <a href="{{ url_for('blogs.update') }}" class="bg-dark list-group-item list-group-item-action">
+            <div class="d-flex w-100 justify-content-start align-items-center">
+              <i class="fas mr-3"></i>
+              <span class="menu-collapsed">更新網站</span>
+            </div>
+          </a>
           <a href="{{ url_for('collections.collection_list') }}" class="bg-dark list-group-item list-group-item-action">
             <div class="d-flex w-100 justify-content-start align-items-center">
               <i class="fas fa-ruler-combined mr-3"></i>
@@ -64,6 +70,12 @@
               <span class="menu-collapsed">設計專欄</span>
             </div>
           </a>
+          <a href="{{ url_for('blogs.edit_further') }}" class="bg-dark list-group-item list-group-item-action">
+            <div class="d-flex w-100 justify-content-start align-items-center">
+              <i class="far fa-newspaper mr-3"></i>
+              <span class="menu-collapsed">設計專欄延伸閱讀清單編輯</span>
+            </div>
+          </a>
           <a href="{{ url_for('blogs.edit_solid_wood_furniture') }}"
             class="bg-dark list-group-item list-group-item-action">
             <div class="d-flex w-100 justify-content-start align-items-center">