Jelajahi Sumber

js needs some work

Jason 2 tahun lalu
induk
melakukan
6d71bc19b9

+ 40 - 12
backstage/blogs/routes.py

@@ -309,6 +309,8 @@ col1: "{}"\n\
 col2: "{}"\n\
 introduction: "{}"\n\
 question_box_intro: "{}"\n\
+readmore_ttl: ["","","","",""]\n\
+readmore_lnk: ["","","","",""]\n\
 ---'''.format(form.title.data, "", form.title.data,
               get_now_time(),
               'true',
@@ -339,27 +341,53 @@ def edit_blog_getfurther():
     #sortedData = sorted(sortedData, key=lambda x: x['type'])
     return {"data": data}
 
+@blogs_app.route('/backstage/getarticle', methods=['GET'])
+def article():
+    try:
+        response = requests.get('{}contents?url={}'.format(PORTAL_SERVER, "/blog/check_in/"))
+        #print('{}contents?url=/blog'.format(PORTAL_SERVER))
+        x = response.json()
+        return x[0]['title']
+    except:
+        return "undefined article"
+
 @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)])
+    data.append(request.args.get('data01', type=str))
+    data.append(request.args.get('data11', type=str))
+    data.append(request.args.get('data21', type=str))
+    data.append(request.args.get('data31', type=str))
+    data.append(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')     
+    res=[]
+
+    for d in data:
+        if d!='':
+            try:
+                link=d.split("1313")[1]
+                if link[-1] == "/":
+                    link = link[:-1]
+                    d = d[:-1]
+                print(link)
+                response = requests.get('{}contents?url={}'.format(PORTAL_SERVER, link))
+                x = response.json()
+                #print('{}contents?url=/blog'.format(PORTAL_SERVER))
+                resp = x[0]['title']
+                print(resp)
+                res.append([resp, d])
+            except:
+                res.append(["undefined_article", d])
+        else:
+            res.append(["", ""])
+        
+    print(res)
 
     #sortedData = sorted(sortedData, key=lambda x: x['type'])
-    return "{success: Success}"
+    return {"data": res}
 
 @blogs_app.route('/backstage/blog/createCat/', methods=['GET'])
 def createCat():

+ 55 - 1
backstage/static/js/yo.js

@@ -432,6 +432,44 @@ function parseMd(content) {
         );
       }
 
+      if (line.includes("readmore_ttl: ")) {
+        var titles = line.replace("readmore_ttl: ", "").replaceAll('[', "").replaceAll(']', "").replaceAll('"', "").split(",");
+
+        try
+        {
+          var inserted = 0;
+          $("#data00").val(titles[0]); inserted = 1; 
+          $("#data10").val(titles[1]); inserted = 2;
+          $("#data20").val(titles[2]); inserted = 3;
+          $("#data30").val(titles[3]); inserted = 4;
+          $("#data40").val(titles[4]); inserted = 5;
+        }
+        catch(err)
+        {
+          console.log("Less than 5 articles");
+        }
+        console.log("Total articles inserted: " + inserted);
+      }
+
+      if (line.includes("readmore_lnk: ")) {
+        var links = line.replace("readmore_lnk: ", "").replaceAll('[', "").replaceAll(']', "").replaceAll('"', "").split(",");
+
+        try
+        {
+          var inserted = 0;
+          $("#data01").val(links[0]); inserted = 1; 
+          $("#data11").val(links[1]); inserted = 2;
+          $("#data21").val(links[2]); inserted = 3;
+          $("#data31").val(links[3]); inserted = 4;
+          $("#data41").val(links[4]); inserted = 5;
+        }
+        catch(err)
+        {
+          console.log("Less than 5 links");
+        }
+        console.log("Total links inserted: " + str(inserted));
+      }
+
       // for collections
       if (line.includes("banner_img_text: ")) {
         $("#ccoverimgtxt").val(
@@ -819,7 +857,23 @@ function GetMdHeader(result = []) {
         let tagVal= $("#cblogtags").val();
         rContent += 'blog_tag: [' + tagVal.replaceAll(",", ",") + ']\n';
       }
-  }
+    axios.get('/backstage/edit_blog_editfurther?data01=' + $('#data01').val() + '&data11=' + $('#data11').val() + '&data21=' + $('#data21').val() + '&data31=' + $('#data31').val() + '&data41=' + $('#data41').val()).then(({data}) => {
+      console.log(data);
+      $('#data00').val(data.data[0][0]);
+      $('#data10').val(data.data[1][0]);
+      $('#data20').val(data.data[2][0]);
+      $('#data30').val(data.data[3][0]);
+      $('#data40').val(data.data[4][0]);
+      $('#data01').val(data.data[0][1]);
+      $('#data11').val(data.data[1][1]);
+      $('#data21').val(data.data[2][1]);
+      $('#data31').val(data.data[3][1]);
+      $('#data41').val(data.data[4][1]);
+    });
+    console.log($('#data00').val());
+    rContent += 'readmore_ttl: ["' + $('#data00').val() + '","' + $('#data10').val() + '","' + $('#data20').val() + '","' + $('#data30').val() + '","' + $('#data40').val() + '"]\n';
+    rContent += 'readmore_lnk: ["' + $('#data01').val() + '","' + $('#data11').val() + '","' + $('#data21').val() + '","' + $('#data31').val() + '","' + $('#data41').val() + '"]\n';
+   }
   rContent += "---\n";
   console.log("rContent", rContent);
   return rContent;

+ 1 - 0
backstage/templates/editor.html

@@ -99,6 +99,7 @@
             id="add_mt5_button">+mt5</button></span>
       </div>
       <br />
+      {% block extratwo %}{% endblock %}
       <div>
         <button id='submit_button' class="btn__submit mb-3" onclick="editorSave()"><b>編輯完成</b></button>
       </div>

+ 70 - 1
backstage/templates/editorblog.html

@@ -12,4 +12,73 @@
           <div><input class="form-control" id="cquestionboxintro" type="text" /></div>
         </div>
       </p>
-{% endblock extras %}
+{% endblock extras %}
+{% block extratwo %}
+<p class="card">
+  <table>
+    <tbody id='contactData'>
+      <p>延伸閱讀清單</p>
+      <tr>
+        <td>文章名稱</td>
+        <td>文章連結 <span class="text-danger">(請務必填寫文章連結,否則此項文章不予載入)</span></td>
+      </tr>
+      <tr>
+        <td class="table__data"><input class="form-control" id="data00" type="text" style="width: 420px;"
+          placeholder="文章內容" disabled/></td>
+        <td class="table__data"><input class="form-control" id="data01" type="text" style="width: 420px;"
+            placeholder="文章連結" /></td>
+      </tr>
+      <tr>
+        <td class="table__data"><input class="form-control" id="data10" type="text" style="width: 420px;"
+            placeholder="文章內容" disabled/></td>
+        <td class="table__data"><input class="form-control" id="data11" type="text" style="width: 420px;"
+            placeholder="文章連結" /></td>
+      </tr>
+      <tr>
+        <td class="table__data"><input class="form-control" id="data20" type="text" style="width: 420px;"
+            placeholder="文章內容" disabled/></td>
+        <td class="table__data"><input class="form-control" id="data21" type="text" style="width: 420px;"
+            placeholder="文章連結" /></td>
+      </tr>
+      <tr>
+        <td class="table__data"><input class="form-control" id="data30" type="text" style="width: 420px;"
+            placeholder="文章內容" disabled/></td>
+        <td class="table__data"><input class="form-control" id="data31" type="text" style="width: 420px;"
+            placeholder="文章連結" /></td>
+      </tr>
+      <tr>
+        <td class="table__data"><input class="form-control" id="data40" type="text" style="width: 420px;"
+            placeholder="文章內容" disabled/></td>
+        <td class="table__data"><input class="form-control" id="data41" type="text" style="width: 420px;"
+            placeholder="文章連結" /></td>
+      </tr>
+  
+    </tbody>
+  </table>
+</p>
+<!--<script>
+  $(function () {
+    axios.get('/backstage/edit_blog_getfurther').then(({ data }) => {
+      $('#data00').val(data.data[0][0]);
+      $('#data01').val(data.data[0][1]);
+      $('#data10').val(data.data[1][0]);
+      $('#data11').val(data.data[1][1]);
+      $('#data20').val(data.data[2][0]);
+      $('#data21').val(data.data[2][1]);
+      $('#data30').val(data.data[3][0]);
+      $('#data31').val(data.data[3][1]);
+      $('#data40').val(data.data[4][0]);
+      $('#data41').val(data.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 extratwo %}

+ 7 - 7
backstage/templates/further.html

@@ -13,36 +13,36 @@
   <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>
+      <td>文章名稱</td>
+      <td>文章連結 <span class="text-danger">(請務必填寫文章連結,否則此項文章不予載入)</span></td>
     </tr>
     <tr>
       <td class="table__data"><input class="form-control" id="data01" type="text" style="width: 600px;"
-          placeholder="文章內容" /></td>
+        placeholder="文章內容" disabled/></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>
+          placeholder="文章內容" disabled/></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>
+          placeholder="文章內容" disabled/></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>
+          placeholder="文章內容" disabled/></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>
+          placeholder="文章內容" disabled/></td>
       <td class="table__data"><input class="form-control" id="data40" type="text" style="width: 600px;"
           placeholder="文章連結" /></td>
     </tr>