ソースを参照

0627 checkpoint

jason 2 年 前
コミット
d0dddc9ea6

+ 2 - 2
backstage/collections/forms.py

@@ -9,11 +9,11 @@ class CollectionCreateForm(FlaskForm):
     title = StringField('標題', validators=[DataRequired()])
     image = FileField('圖片', validators=[FileRequired(), FileAllowed(['jpg', 'png', 'gif', 'webp'], 'Images only!')])
     collectiontitle = StringField('作品集標題', validators=[DataRequired()])
-    description = TextAreaField('內容描述', validators=[DataRequired()])
+    description = TextAreaField('描述', validators=[DataRequired()])
     tags = StringField('分類')
     coverimg = FileField('封面圖片', validators=[FileRequired(), FileAllowed(['jpg', 'png', 'gif', 'webp'], 'Images only!')])
     bannerimgtext = StringField('封面圖片說明', validators=[DataRequired()])
-    homeowner = StringField('主', validators=[DataRequired()])
+    homeowner = StringField('主', validators=[DataRequired()])
     size = StringField('坪數', validators=[DataRequired()])
     bednum = SelectField('格局', choices=['1房', '2房', '3房', '4房以上',],validators=[DataRequired()])
     housetype = SelectField('屋型', choices=['大樓', '透天'], validators=[DataRequired()])

+ 5 - 5
backstage/collections/routes.py

@@ -51,12 +51,12 @@ def create():
 
     eng_name = get_trans_title_url_name(form.title.data)
     front_matter = '''---
-meta_title: "{}"\nmeta_description: "{}"\ncollection_title: "{}"\ntitle: "{}"\n\
-date: {}\n\
+meta_title: "{}"\nmeta_description: "{}"\ntitle: "{}"\ndate: {}\n\
 draft: {}\n\
 type: "{}"\n\
 url: "{}"\n\
 image: "/img/title/{}"\n\
+collection_name: "{}"\n\
 cover_img: "/img/title/{}"\n\
 description: "{}"\n\
 tags: ["{}"]\n\
@@ -64,7 +64,7 @@ banner_img_text: "{}"\n\
 homeowner: "{}"\n\
 size: "{}"\n\
 bed_num: "{}"\n\
-house_type: "{}"\n\
+house_cat: "{}"\n\
 designer: "{}"\n\
 space: "{}"\n\
 loc: "{}"\n\
@@ -73,9 +73,9 @@ construction: "{}"\n\
 collection_description: "{}"\n\
 collection_slider: "{}"\n\
 comment: "{}"\n
----'''.format(form.title.data, form.description.data, form.collectiontitle.data, form.title.data,
+---'''.format(form.title.data, form.description.data, form.title.data,
               get_now_time(), 'true', 'collection', '/collection/{}'.format(eng_name),
-              form.image.data.filename, form.coverimg.data.filename, form.description.data.replace('\r\n','<br>'), form.tags.data,
+              form.image.data.filename, form.collectiontitle.data, form.coverimg.data.filename, form.description.data.replace('\r\n','<br>'), form.tags.data,
               form.bannerimgtext.data, form.homeowner.data, form.size.data, form.bednum.data,
               form.housetype.data, form.designer.data, form.space.data, form.loc.data,
               form.budget.data, form.construction.data, form.collectiondesc.data, csliderimg, form.comment.data.filename)

+ 1 - 0
backstage/editor/routes.py

@@ -10,6 +10,7 @@ def editor():
     url = request.args.get('url', type=str)
     if "collection" in url: # 作品集
         type = "collection"
+        return render_template('editorcollection.html', title='Type Editor', url=url, type=type, bhouse_server=BHOUSE_SERVER)
     elif "maincategories" in url: # 設計專欄
         type = "blog"
         return render_template('editorblog.html', title='Type Editor', url=url, type=type, bhouse_server=BHOUSE_SERVER)

+ 0 - 299
backstage/static/js/old/editor.js

@@ -1,299 +0,0 @@
-const contentDiv = document.getElementById('editor_block');
-const titleButton = document.getElementById('title_button');
-const submitButton = document.getElementById('submit_button');
-contentApiUrl = `${PORTAL_SERVER}contents?url=${(JSON.parse(document.getElementById('url').textContent)).url}`
-
-aa = "";
-frontMatters = [];
-contentMatters = [];
-editorBlocks = [];
-var editor;
-axios.get(contentApiUrl).then(({ data }) => {
-  const content = data[0]['content'];
-  var blockArray = [{ title: '', data: [] }];
-  var blockCount = 0;
-  blocks = parseMd(content);
-  aa = new MDParser(content);
-  editor_block = document.getElementById('editor_block');
-  //alert(blocks[0]['text']);
-
-  //ul = document.createElement('ul');
-  //ul.id = "sortable";
-  for (i = 0; i < blocks.length; i++) {
-    //li = document.createElement('li');
-    //odiv = document.createElement('div');
-    //odiv.style.border = 'inset 1px gray';
-    if (blocks[i]['type'] == "para") {
-      editorBlocks.push({ type: "paragraph", data: { text: blocks[i]['text'] } });
-      //tmp = document.createElement('textarea');
-      //tmp.style.border = 'outset 5px pink';
-      //tmp.style.width = '100%';
-      //tmp.value = blocks[i]['text'];
-      //odiv.appendChild(tmp);
-    }
-    else if (blocks[i]['type'] == "br") {
-      editorBlocks.push({ type: "paragraph", data: { text: "" } });
-      //tmp = document.createElement('br');
-      //odiv.appendChild(tmp);
-    }
-    else if (blocks[i]['type'] == "img") {
-      ampimg = blocks[i]['text'];
-      //alert(ampimg.indexOf("width=\"",84));
-      //alert(ampimg.substr(ampimg.indexOf("alt=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("alt=\"") + 5) - ampimg.indexOf("alt=\"") - 5));
-      tmpsrc = BHOUSE_SERVER + JSON.parse(document.getElementById('url').textContent).url + '/' + ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("src=\"") + 5) - ampimg.indexOf("src=\"") - 5);
-      //tmpsrc = BHOUSE_SERVER + JSON.parse(document.getElementById('url').textContent).url + '/' + ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.lastIndexOf(".") - ampimg.indexOf("src=\"") -1);
-      //tmpsrc = ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf(".webp") - ampimg.indexOf("src=\""));
-      editorBlocks.push({
-        type: "image", data: {
-          file: {
-            url: tmpsrc,
-            width: parseInt(ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7)),
-            height: parseInt(ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8)),
-          },
-          caption: ampimg.substr(ampimg.indexOf("alt=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("alt=\"") + 5) - ampimg.indexOf("alt=\"") - 5).toString(),
-          stretched: false,
-          withBorder: true,
-          withBackground: false,
-        }
-      });
-      //alert(ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8));
-      //img = document.createElement('img');
-      //img.style.width = '100%';
-      //img.src = tmpsrc;
-      //odiv.appendChild(img);
-    }
-    else if (blocks[i]['type'] == "youtube") {
-      ampimg = blocks[i]['text'];
-      vid = ampimg.substr(ampimg.indexOf("data-videoid=\"") + 14, ampimg.indexOf("\"", ampimg.indexOf("data-videoid=\"") + 14) - ampimg.indexOf("data-videoid=\"") - 14)
-      editorBlocks.push({
-        type: "embed", data: {
-          service: 'youtube',
-          source: 'https://www.youtube.com/watch?' + vid,
-          embed: 'https://www.youtube.com/embed/' + vid,
-          width: parseInt(ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7)),
-          height: parseInt(ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8)),
-        }
-      });
-    }
-    else if (blocks[i]['type'] == "title") {
-      blocks[i]['text'] = blocks[i]['text'].replace("### **", "").replace("**", "")
-      editorBlocks.push({ type: "header", data: { text: blocks[i]['text'] } });
-      //tmp = document.createElement('h3');
-      //tmp.innerHTML = blocks[i]['text'];
-      //odiv.appendChild(tmp);
-    }
-    else if (blocks[i]['type'] == "hr") {
-      //alert('yo');
-      editorBlocks.push({ type: "paragraph", data: { text: "---" } });
-    }
-    else if (blocks[i]['type'] == "mt5") {
-      //alert('yo');
-      editorBlocks.push({ type: "delimiter", data: {} });
-    }
-    else if (blocks[i]['type'] == "table") {
-      //alert('yo');
-      editorBlocks.push({ type: "table", data: { content: tableTextToArray(blocks[i]['text']) } });
-    }
-    //li.appendChild(odiv);
-    //ul.appendChild(li);
-  }
-  //editor_block.appendChild(ul);
-  //$("#sortable").sortable();
-  //$("#sortable").disableSelection();
-  $("#editor_block").css({ "display": "none" });
-  //alert(JSON.parse(document.getElementById('url').textContent).url);
-  $('#editorjs')[0].innerHTML = "";
-  //alert(JSON.stringify(editorBlocks));
-  editor = new EditorJS({
-    readOnly: false,
-    holder: 'editorjs',
-
-    tools: {
-      header: {
-        class: Header,
-        config: {
-          placeholder: 'Header'
-        }
-      },
-
-      image: {
-        class: ImageTool,
-        config: {
-          endpoints: {
-            byFile: '/backstage/upload' + JSON.parse(document.getElementById('url').textContent).url, // Your backend file uploader endpoint
-            byUrl: '/backstage/getimage' + JSON.parse(document.getElementById('url').textContent).url, // Your endpoint that provides uploading by Url
-            /* byFile: '/backstage/upload' + JSON.parse(document.getElementById('url').textContent).url.substring(JSON.parse(document.getElementById('url').textContent).url.lastIndexOf('/')), // Your backend file uploader endpoint
-            byUrl: '/backstage/getimage' + JSON.parse(document.getElementById('url').textContent).url.substring(JSON.parse(document.getElementById('url').textContent).url.lastIndexOf('/')), // Your endpoint that provides uploading by Url */
-            /* byFile: '/backstage/upload/' + $('#ctitle').val(), // Your backend file uploader endpoint
-            byUrl: '/backstage/getimage/' + $('#ctitle').val(), // Your endpoint that provides uploading by Url */
-          }
-        }
-      }
-      ,
-      // warning: {
-      //   class: Warning,
-      //   inlineToolbar: true,
-      //   config: {
-      //     titlePlaceholder: 'Title',
-      //     messagePlaceholder: 'Message',
-      //   },
-      // },
-      table: Table,
-      delimiter: Delimiter,
-      embed: Embed,
-    }
-    ,
-    data: { blocks: editorBlocks }
-    ,
-    onReady: function () {
-      //saveButton.click();
-    },
-    onChange: function (api, block) {
-      //console.log('something changed', block);
-    }
-  });
-
-  /*   for (var blockData of preBlockArray) {
-      blockCount = loadDataToBlock(blockArray, blockCount, blockData);
-    }
-    titleButton.onclick = function () {
-      blockCount = loadDataToBlock(blockArray, blockCount);
-    } */
-});
-
-function editorSave() {
-  editor.save().then((outputData) => {
-    //console.log('Article data: ', outputData);
-    //var mdContent = GetMdHeader();
-    //var mdContent = frontMatters.join('\n');
-    //console.log(mdContent);
-    //console.log(frontMatters.join('\n'));
-    //mdContent = mdContent.replace('draft: ' + (!$('#cdraft').is(':checked')), 'draft: ' + $('#cdraft').val())
-    //alert(mdContent);
-    /*
-    for (var frontMatter of frontMatters) {
-      mdContent += frontMatter + '\n';
-    }
-    
-    //alert($('#cdescription').val());
-    mdContent += '---\n';
-    mdContent += 'title: "' + $('#ctitle').val() + '"\n';
-    mdContent += 'date: ' + $('#cdate').val() + '\n';
-    mdContent += 'draft: ' + $('#cdraft').val() + '\n';
-    mdContent += 'type: "' + $('#ctype').val() + '"\n';
-    mdContent += 'url: "' + $('#curl').val() + '"\n';
-    mdContent += 'image: "' + $('#cimage').val() + '"\n';
-    mdContent += 'description: "' + $('#cdescription').val().replace(/\r?\n/g, '<br>') + '"\n';
-    mdContent += 'weight: ' + ($('#cweight').val() == 'undefined' ? "" : $('#cweight').val()) + '\n';
-    mdContent += 'tag: "' + ($('#ctag').val() == 'undefined' ? "" : $('#ctag').val()) + '"\n';
-    mdContent += '---\n\n';
-    */
-
-    var mdContent = '\n';
-    var articleinfo = frontMatters.join('\n');
-    var opening = '\n<div class="container-fluid blog_article p-0">\n';
-    //var chapterlist = '<section><div class="question-box">\n<ul>\n<li data-gt-duration="100" data-gt-offset="0">小寶優居的客變懶人包將幫你解決以下客變問題:</li>\n';
-    var numChapters = 0;
-    var sectionstarted = false;
-
-    for (i = 0; i < outputData.blocks.length; i++) {
-      //alert(block.type);
-      block = outputData.blocks[i];
-      if (block.type == "header") {
-        mdContent += '<h4>' + block.data.text + '</h4>\n';
-      }
-      else if (block.type == "paragraph") {
-        mdContent += '\n' + block.data.text + '\n';
-      }
-      else if (block.type == "hr") {
-        //alert('hr');
-        mdContent += '\n---\n';
-      }
-      else if (block.type == "image") {
-        //console.log(block.data.file.url);
-        //console.log(JSON.parse(document.getElementById('url').textContent).url);
-        iurl = block.data.file.url.split('/');
-        mdContent += '<img class="w-100" src="' + iurl[iurl.length - 2] + '/' + iurl[iurl.length - 1] + ' alt="' + block.data.caption + '"\n >\n</img>\n'
-        if (block.data.caption != '')
-        {
-          mdContent += '<div class="img-text">\n<p>' + block.data.caption + '</p>\n</div>\n';
-        }
-      }
-      else if (block.type == "delimiter") {
-        mdContent += '\n{{% chuz-div class="mt-5" %}}\n';
-      }
-      else if (block.type == "embed") {
-        mdContent += '<iframe'
-          + '\n  data-videoid="' + block.data.embed.replace('https://www.youtube.com/embed/', '')
-          + '"\n  layout="responsive'
-          + '"\n  width="' + block.data.width
-          + '"\n  height="' + block.data.height
-          + '">\n</iframe>\n</div>\n';
-      }
-      else if (block.type == "table") {
-        //alert(tableArrayToHtml(block.data).length);
-        mdContent += '\n' + tableArrayToHtml(block.data.content) + '\n'
-        //console.log(tableArrayToHtml(block.data.content));
-      }
-    }
-    console.log(mdContent);
-
-    postData = {
-      content: mdContent,
-      url: (JSON.parse(document.getElementById('url').textContent)).url
-    };
-    axios.post(contentApiUrl, json = postData).then(({ data }) => {
-      alert('作品資料已儲存');
-    });
-  }).catch((error) => {
-    console.log('Saving failed: ', error)
-  });
-
-  /*   var mdContent = '';
-    for (var frontMatter of frontMatters) {
-      mdContent += frontMatter + '\n';
-    } */
-
-  //alert(bb);
-  /*     for(var eBlock in outputData.blocks)
-      {
-        alert(eBlock.type);
-      } */
-  /* 
-for (var idx = 0; idx < blockArray.length; idx++) {
- if (_.get(blockArray[idx], 'title', '').includes('敘述')) {
-   mdContent += `\n<!-- ### **${_.get(blockArray[idx], 'title', '')}**-->\n`
- } else {
-   mdContent += `\n### **${_.get(blockArray[idx], 'title', '')}**\n`
- }
- for (var data of _.get(blockArray[idx], 'data', [])) {
-   if (_.get(_.keys(data), 0) === 'description') {
-     if (_.get(data, 'description.text', '').includes('\n')) {
-       for (const line of _.get(data, 'description.text', '').split('\n')) {
-         mdContent += `\n${line}    `;
-       }
-     } else {
-       mdContent += `\n${_.get(data, 'description.text', '')}`;
-     }
-   } else if (_.get(_.keys(data), 0) === 'image') {
-     ampImgForm = `\n<amp-img\
-\n  alt="${_.get(data, 'image.alt', '小寶優居')}"\
-\n  src="${_.get(data, 'image.src', '')}"\
-\n  height="${_.get(data, 'image.height', 300)}"\
-\n  width="${_.get(data, 'image.width', 400)}"\
-\n  layout="${_.get(data, 'image.layout', 'responsive')}">\
-\n</amp-img>\n`;
-     mdContent += ampImgForm;
-   }
- }
-}
-*/
-  /* const postData = {
-    content: mdContent,
-    url: (JSON.parse(document.getElementById('url').textContent)).url
-  }; */
-
-  //axios.post(contentApiUrl, json = postData);
-
-}
-submitButton.onclick = editorSave

+ 0 - 91
backstage/static/js/old/parsers.js

@@ -1,91 +0,0 @@
-function parseMd(content) {
-  var frontMatters = [];
-  var blockCount;
-  var preDataIndex;
-  var parseBlockDiv;
-  var preImgObject = { 'image': {} };
-  var isNotFrontMatterCount = 0;
-  var isAmpImgRange = false;
-  var result = [];
-
-  for (const line of content.split('\n')) {
-    if (isNotFrontMatterCount < 2) {
-      frontMatters.push(line)
-      if (line.includes('---')) {
-        isNotFrontMatterCount += 1;
-      }
-      continue;
-    }
-
-    if (isAmpImgRange === true && !(line.includes('</img>'))) {
-      imgParamObject = parseAmpImg(line);
-      preImgObject.image = { ...preImgObject.image, ...imgParamObject };
-      continue;
-    }
-
-    if (line.includes('###')) {
-      parseBlockDiv = true;
-      preDataIndex = 0;
-      blockCount = blockCount + 1 | 0;
-      const preBlockindex = blockCount;
-      const title = parseTitle(line);
-      result[preBlockindex] = { title: title };
-
-    } else if (line.includes('img')) {
-      const preBlockindex = blockCount;
-      if (line.includes('</img>')) {
-        addDataToBlockArray(preImgObject, result, preBlockindex, preDataIndex);
-        isAmpImgRange = false;
-        preImgObject = { 'image': {} }
-        preDataIndex += 1;
-        continue;
-      }
-      isAmpImgRange = true;
-    } else {
-      if (parseBlockDiv === undefined) {
-        // for skipping space before first title
-        continue
-      }
-      if (line === '') {
-        // for skipping space
-        continue
-      }
-      const preBlockindex = blockCount;
-      const ownDataIndex = preDataIndex;
-      preDataIndex += 1;
-      //addDataToBlockArray({ description: { text: line } }, result, preBlockindex, ownDataIndex);
-      addDataToBlockArray({ text: line }, result, preBlockindex, ownDataIndex);
-    }
-  }
-  alert(JSON.stringify(result));
-  return { frontMatters: frontMatters, preBlockArray: result }
-}
-
-const parseTitle = line => {
-  var title = '';
-  title = line.replace('### **', '');
-  title = title.replace('**', '');
-  if (title.includes('敘述')) {
-    title = title.replace('<!-- ', '');
-    title = title.replace('-->', '');
-  }
-  return title;
-};
-
-const parseAmpImg = line => {
-  if (line.includes('alt')) {
-    const altParameter = line.replace(/ |alt=|"/g, '');
-    return { alt: altParameter };
-  } else if (line.includes('src')) {
-    const srcParameter = line.replace(/ |src=|"/g, '');
-    return { src: srcParameter };
-  } else if (line.includes('height')) {
-    const heightParameter = line.replace(/ |height=|"/g, '');
-    return { height: heightParameter };
-  } else if (line.includes('width')) {
-    const widthParameter = line.replace(/ |width=|"/g, '');
-    return { width: widthParameter };
-  } else if (line.includes('layout')) {
-    const layoutParameter = line.replace(/ |layout=|"|>/g, '');
-  }
-}

+ 0 - 783
backstage/static/js/old/yo.js

@@ -1,783 +0,0 @@
-contentApiUrl = `${PORTAL_SERVER}contents?url=`;
-frontMatters = [];
-contentMatters = [];
-tagOptionIds = ['thousetype', 'tpinsize', 'tbudget', 'troomscount'];
-
-var SwfType = {};
-if (location.pathname.indexOf('system_furniture') >= 0) {
-    SwfType = {
-        "custom_made_system_cabinet": "客製模組系統櫃",
-        "system_cabinet": "模組系統櫃單品",
-    };
-}
-else {
-    SwfType = {
-        "other_furniture": "其他",
-        "master_bedroom": "臥室",
-        "living_room": "客廳",
-        "study_room": "書房",
-        "dining_room": "餐廳",
-    };
-}
-
-//document.ready
-$(function () {
-
-    $("#dialog-form").hide();
-    if ($('#editorjs').length > 0)
-        editor = new EditorJS({
-            readOnly: false,
-            holder: 'editorjs',
-        });
-    if ($('#editorjs1').length > 0)
-        editor1 = new EditorJS({
-            readOnly: false,
-            holder: 'editorjs1',
-        });
-
-});
-
-function getHeader(url) {
-    axios.get(contentApiUrl + url).then(({ data }) => {
-        frontMatters = [];
-        contentMatters = [];
-        editTarget = url;
-        mdType = url.split('/')[1];
-        aa = data[0]['content'];
-        for (var toi of tagOptionIds) {
-            $('#' + toi).val("");
-        }
-        //const content = _.get(data, '0.content', '');
-        blocks = parseMd(aa);
-        oTitle = $("#ctitle").val();
-        // $("#dialog-form").dialog();
-        if ($("#ctype").val() == "collection") {
-            $("#scat").hide();
-        }
-        else if ($("#ctype").val() == "blog") {
-            $("#sdesc").hide();
-        }
-        else if ($("#ctype").val() == "news") {
-            $("#sdesc").hide();
-            $("#scat").hide();
-            $("#simg").hide();
-        }
-        else {
-            ParseProductSection(contentMatters.join(''));
-        }
-        $("#myModal").modal();
-
-        //console.log(frontMatters);
-        //alert($('#cimage').val());
-    });
-}
-
-function toggleDraft(obj, url) {
-    axios.get(contentApiUrl + url).then(({ data }) => {
-        frontMatters = [];
-        contentMatters = [];
-        aa = data[0]['content'];
-        const content = _.get(data, '0.content', '');
-        blocks = parseMd(aa);
-        editTarget = url;
-        $('#cdraft').removeAttr('checked');
-        $('#cdraft').prop('checked', obj.checked);
-        updateHeader();
-        oTitle = "";
-    });
-}
-
-function updateHeader() {
-    /* if (oTitle != $('#ctitle').val() && $('#ctitle').val() != "" && oTitle != "") {
-      axios.get('/backstage/modTitle/' + oTitle + '/' + $('#ctitle').val()).then(({ data }) => {
-        if (data.success == "0") {
-          alert('已有重複的標題,請重新設定');
-          return;
-        }
-        else {
-          writeMd();
-        }
-      });
-    }
-    else {
-      writeMd();
-    } */
-    $("#uptbtn").attr('disabled', true);
-    writeMd();
-    // location.reload();
-}
-
-function writeMd() {
-
-    axios.get('/backstage/utils?trantext=' + $('#ccategories').val()).then(({ data }) => { $('#ccol1').val(data); })
-        .finally(() => {
-            mdContent = GetMdHeader();
-            mdContent += contentMatters.join("\n");
-            var formData = new FormData();
-            var imagefile = document.querySelector('#cfile');
-            formData.append("image", imagefile.files[0]);
-            axios.post('/backstage/upload/title', formData, {
-                headers: {
-                    'Content-Type': 'multipart/form-data'
-                }
-            }).then(({ data }) => {
-                $('#cfile').val("");
-                if (data.success == "1") {
-                    mdContent = mdContent.replace($('#cimage').val(), '/img/collection/' + data.file.url.substring(data.file.url.lastIndexOf('/') + 1));
-                    //alert(data.file.url.substring(data.file.url.lastIndexOf('/')+1));
-                }
-
-                postData = {
-                    content: mdContent,
-                    url: editTarget
-                };
-                //console.log(mdContent);
-                axios.post(contentApiUrl + editTarget, json = postData).then(({ data }) => {
-                });
-            }).finally(() => {
-                alert('資料已更新'); // test
-                location.reload();
-            });
-
-        });
-}
-
-function parseMd(content) {
-    //var frontMatters = [];
-    var blockCount;
-    var preDataIndex;
-    var parseBlockDiv;
-    var preImgObject = { 'image': {} };
-    var isNotFrontMatterCount = 0;
-    var isAmpImgRange = false;
-    var result = [];
-
-    var rblocks = new Array();
-    lineIdx = 1;
-    foundImg = false;
-    foundYT = false;
-    foundTBL = false;
-    crossLine = "";
-
-    for (var line of content.split('\n')) {
-        lineIdx++;
-        if (isNotFrontMatterCount < 2) {
-            frontMatters.push(line)
-            if (line.includes('title: ')) {
-                $('#ctitle').val(line.replace('title: ', '').replaceAll('\"', ''));
-                //alert($('#ctitle').val());
-            }
-            if (line.includes('date: ')) {
-                //alert(line);
-                $('#cdate').val(line.replace('date: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('draft: ')) {
-                //alert(line);
-                $('#cdraft').val(line.replace('draft: ', '').replaceAll('\"', ''));
-                //console.log($('#cdraft').val());
-                $('#cdraft').removeAttr('checked');
-                if ($('#cdraft').val() == 'false')
-                    $('#cdraft').prop('checked', true);
-                /*
-                if($('#cdraft').val() == 'true') 
-                    $('#cdraft').removeAttr('checked');
-                else
-                    $('#cdraft').attr('checked','true');
-                    */
-            }
-            if (line.includes('type: ')) {
-                //alert(line);
-                $('#ctype').val(line.replace('type: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('url: ')) {
-                //alert(line);
-                $('#curl').val(line.replace('url: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('image: ')) {
-                //alert(line);
-                $('#cimage').val(line.replace('image: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('description: ')) {
-                //alert(line);
-                $('#cdescription').val(line.replace('description: ', '').replaceAll('\"', '').replaceAll('<br>', '\r\n'));
-            }
-            if (line.includes('weight: ')) {
-                //alert(line);
-                $('#cweight').val(line.replace('weight: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('tag: ')) {
-                //alert(line);
-                $('#ctag').val(line.replace('tag: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('tags: ')) {
-                //alert(line);
-                if ($('#ctags').length > 0) {
-                    $('#ctags').val(line.replace('tags: ', '').replaceAll('\"', ''));
-                    tags = $('#ctags').val().split(',');
-                    for (var tag of tags) {
-                        //console.log(tag);
-                        for (var toi of tagOptionIds) {
-                            $('#' + toi + ' option').each(function () {
-                                if (this.value == tag)
-                                    this.selected = true;
-                            });
-                        }
-                    }
-                }
-            }
-            if (line.includes('categories: ')) {
-                //alert(line);
-                $('#ccategories').val(line.replace('categories: ', '').replace('categories: ', '').replace(/\[|]/g, '').replace(/\"/g, ''));
-            }
-            /* if (line.includes('caturl: ')) {
-                //alert(line);
-                $('#ccaturl').val(line.replace('caturl: ', '').replaceAll('\"', ''));
-            } */
-            if (line.includes('col1: ')) {
-                //alert(line);
-                $('#ccol1').val(line.replace('col1: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('col2: ')) {
-                //alert(line);
-                $('#ccol2').val(line.replace('col2: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('meta_title: ')) {
-                //alert(line);
-                $('#cmetattl').val(line.replace('title: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('meta_description: ')) {
-                //alert(line);
-                $('#cmetadsc').val(line.replace('title: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('introduction: ')) {
-                //alert(line);
-                $('#cintroduction').val(line.replace('description: ', '').replaceAll('\"', '').replaceAll('<br>', '\r\n'));
-            }
-            if (line.includes('question_box_intro: ')) {
-                //alert(line);
-                $('#cquestionboxintro').val(line.replace('title: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('---')) {
-                isNotFrontMatterCount += 1;
-            }
-            continue;
-        }
-        contentMatters.push(line)
-        /*         if (line.toString().trim() == "") {
-                    rblocks.push({ 'type': 'br', 'text': line });
-                    continue;
-                } */
-
-        if (line.includes('---')) {
-            rblocks.push({ 'type': 'hr', 'text': line });
-            continue;
-        }
-
-        if (line.includes('<h4>')) {
-            rblocks.push({ 'type': 'title', 'text': line });
-            continue;
-        }
-
-        if (line.includes('{{% chuz-div class=\"mt-5\" %}}')) {
-            rblocks.push({ 'type': 'mt5', 'text': line });
-            continue;
-        }
-
-        if (line.includes('<img') || foundImg) {
-            crossLine += line;
-            foundImg = true;
-            if (line.includes('</img>')) {
-                rblocks.push({ 'type': 'img', 'text': crossLine });
-                foundImg = false;
-                crossLine = "";
-            }
-            continue;
-        }
-
-        if (line.includes('<iframe') || foundYT) {
-            crossLine += line;
-            foundYT = true;
-            if (line.includes('</iframe>')) {
-                rblocks.push({ 'type': 'youtube', 'text': crossLine });
-                foundYT = false;
-                crossLine = "";
-            }
-            continue;
-        }
-
-        if (line.includes('<table') || foundTBL) {
-            crossLine += line;
-            foundTBL = true;
-            if (line.includes('</table>')) {
-                rblocks.push({ 'type': 'table', 'text': crossLine });
-                foundTBL = false;
-                crossLine = "";
-            }
-            continue;
-        }
-
-        rblocks.push({ 'type': 'para', 'text': line });
-    }
-
-    return rblocks
-}
-
-function GetMdHeader() {
-    rContent = "";
-    rContent += '---\n';
-    rContent += 'title: "' + $('#ctitle').val() + '"\n';
-    rContent += 'date: ' + $('#cdate').val() + '\n';
-    rContent += 'draft: ' + (!$('#cdraft').is(':checked')) + '\n';
-    rContent += 'type: "' + $('#ctype').val() + '"\n';
-    rContent += 'url: "' + $('#curl').val() + '"\n';
-    //mdContent += 'url: "' + $('#curl').val() + '"\n';
-    rContent += 'image: "' + $('#cimage').val() + '"\n';
-    if ($('#ctype').val() == "collection") {
-        rContent += 'description: "' + $('#cdescription').val().replace(/\r?\n/g, '<br>') + '"\n';
-        rContent += 'weight: ' + ($('#cweight').val() == 'undefined' ? "" : $('#cweight').val()) + '\n';
-
-        tags = [];
-        for (var toi of tagOptionIds) {
-            if ($('#' + toi).val() != "")
-                tags.push($('#' + toi).val());
-        }
-        rContent += 'tags: "' + tags.join(',') + '"\n';
-        //rContent += 'tags: "' + ($('#ctags').val() == 'undefined' ? "" : $('#ctags').val()) + '"\n';
-    }
-    else if ($('#ctype').val() == "blog") {
-        rContent += 'categories: ["' + $('#ccategories').val() + '"]\n';
-        //rContent += 'caturl: "' + $('#ccaturl').val() + '"\n';
-        rContent += 'col1: "' + ($('#ccol1').val() == 'undefined' ? "" : $('#ccol1').val()) + '"\n';
-        rContent += 'col2: "' + ($('#ccol2').val() == 'undefined' ? "" : $('#ccol2').val()) + '"\n';
-    }
-    rContent += '---\n';
-    //alert(rContent);
-    return rContent
-}
-
-const parseTitle = line => {
-    var title = '';
-    title = line.replace('### **', '');
-    title = title.replace('**', '');
-    if (title.includes('敘述')) {
-        title = title.replace('<!-- ', '');
-        title = title.replace('-->', '');
-    }
-    return title;
-};
-
-const parseAmpImg = line => {
-    if (line.includes('alt')) {
-        const altParameter = line.replace(/ |alt=|"/g, '');
-        return { alt: altParameter };
-    } else if (line.includes('src')) {
-        const srcParameter = line.replace(/ |src=|"/g, '');
-        return { src: srcParameter };
-    } else if (line.includes('height')) {
-        const heightParameter = line.replace(/ |height=|"/g, '');
-        return { height: heightParameter };
-    } else if (line.includes('width')) {
-        const widthParameter = line.replace(/ |width=|"/g, '');
-        return { width: widthParameter };
-    } else if (line.includes('layout')) {
-        const layoutParameter = line.replace(/ |layout=|"|>/g, '');
-    }
-}
-
-function tableTextToArray(tableHtml) {
-    tbl = document.createElement('table');
-    tbl.innerHTML = tableHtml.replace('<table>', '').replace('</table>', '');
-    var tableInfo = Array.prototype.map.call(tbl.querySelectorAll('tr'), function (tr) {
-        return Array.prototype.map.call(tr.querySelectorAll('td'), function (td) {
-            return td.innerHTML;
-        });
-    });
-    return tableInfo;
-}
-
-function tableArrayToHtml(tableArray) {
-    tbl = document.createElement('table');
-    for (j = 0; j < tableArray.length; j++) {
-        tr = document.createElement('tr');
-        for (k = 0; k < tableArray[j].length; k++) {
-            td = document.createElement('td');
-            if (k == 0)
-                td.style.width = "25%";
-            td.innerHTML = tableArray[j][k];
-            tr.appendChild(td);
-        }
-        tbl.appendChild(tr);
-    }
-    //alert(tbl.outerHTML.toString());
-    return tbl.outerHTML.toString();
-}
-
-function GenSwfDD(obj) {
-    Object.entries(SwfType).forEach(([key, value]) => {
-        op = document.createElement('option');
-        op.value = key;
-        op.text = value;
-        obj.appendChild(op);
-    });
-}
-
-function ReplaceSwfType(inContent) {
-    Object.entries(SwfType).forEach(([key, value]) => {
-        inContent = inContent.replaceAll('[' + key + ']', '[' + value + ']');
-    });
-    return inContent;
-}
-
-var editor;
-var editor1;
-editorBlocks = [];
-editorBlocks1 = [];
-function ParseProductSection(inContent) {
-    editorBlocks = [];
-    editorBlocks1 = [];
-    var aa = $.parseHTML(inContent.trim());
-    //處理圖片
-    if ($("[id='carousel-with-preview']", aa).length > 0) {
-        imgnodes = $("[id='carousel-with-preview']", aa)[0].childNodes;
-        for (i = 0; i < imgnodes.length; i++) {
-            var tmpsrc, tmpw, tmph, ampimg;
-            if (imgnodes[i].nodeName == "AMP-IMG") {
-                //alert(imgnodes[i].nodeName);
-                ampimg = imgnodes[i].outerHTML;
-                tmpsrc = ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("src=\"") + 5) - ampimg.indexOf("src=\"") - 5);
-                //alert(tmpsrc);
-                tmpw = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
-                tmph = ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8);
-                //tmph = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
-                editorBlocks.push({
-                    type: "image", data: {
-                        file: {
-                            url: BHOUSE_SERVER + editTarget + '/' + tmpsrc,
-                            width: parseInt(tmpw),
-                            height: parseInt(tmph),
-                        },
-                        caption: "小寶優居 | " + $('#ctitle').val(),
-                    }
-                });
-            }
-        }
-    }
-    /*     else {
-            editorBlocks.push({
-                type: "image", data: {
-                    file: {
-                        url: 'https://bhouse.com.tw/img/logo2.png',
-                        width: 300,
-                        height: 300,
-                    },
-                    caption: "小寶優居 | " + $('#ctitle').val(),
-                }
-            });
-        } */
-    //editor.api.blocks.render(editorBlocks);
-    $('#editorjs')[0].innerHTML = "";
-    //alert(editorBlocks);
-    editor = new EditorJS({
-        readOnly: false,
-        holder: 'editorjs',
-        tools: {
-            paragraph: { inlineToolbar: false },
-            image: {
-                class: ImageTool,
-                config: {
-                    endpoints: {
-                        byFile: '/backstage/upload' + $('#curl').val(),
-                        byUrl: '/backstage/getimage' + $('#curl').val(),
-                    }
-                }
-            }
-        }
-        , data: { blocks: editorBlocks }
-        ,
-        onReady: function () {
-            //alert(editor.blocks.getBlocksCount());
-            //saveButton.click();
-        },
-        onChange: function (api, block) {
-            //$('#cimage')[0].val();
-            //console.log('something changed', block);
-        }
-    });
-
-    //類別
-    Object.entries(SwfType).forEach(([key, value]) => {
-        if ($("#ctype").val() == key) {
-            //alert($("#ctype").val());
-            $("#swfDropdown").val($("#ctype").val());
-        }
-    });
-
-    //敘述
-    $("#swfDesc").val("");
-    if ($("[class='description']", aa).length > 0) {
-        $("#swfDesc").val($(".description", aa)[0].innerHTML.trim().replaceAll('<b>', '').replaceAll('</b>', ''));
-    }
-    //alert(editorBlocks);
-    //其他
-    $("#swfPrice").val("");
-    $("#swfColor").val("");
-    $("#swfSize").val("");
-    $("#swfMat").val("");
-    $("#swfMemo").val("");
-    if ($("[class='detail']", aa).length > 0) {
-        onodes = $("[class='detail']", aa)[0].childNodes;
-        for (i = 0; i < onodes.length; i++) {
-            if (onodes[i].nodeName != "#text") {
-                if (onodes[i].innerHTML.trim().indexOf("定價 : ") >= 0)
-                    $("#swfPrice").val(onodes[i].innerHTML.replace("定價 : ", "").trim());
-                if (onodes[i].innerHTML.trim().indexOf("顏色 : ") >= 0)
-                    $("#swfColor").val(onodes[i].innerHTML.replace("顏色 : ", "").trim());
-                if (onodes[i].innerHTML.trim().indexOf("尺寸(mm) : ") >= 0)
-                    $("#swfSize").val(onodes[i].innerHTML.replace("尺寸(mm) : ", "").trim());
-                if (onodes[i].innerHTML.trim().indexOf("材質 : ") >= 0)
-                    $("#swfMat").val(onodes[i].innerHTML.replace("材質 : ", "").trim());
-                if (onodes[i].innerHTML.trim().indexOf("備註 : ") >= 0)
-                    $("#swfMemo").val(onodes[i].innerHTML.replace("備註 : ", "").trim());
-                //alert(nodes[i].innerHTML);
-            }
-        }
-    }
-
-    //處理規格圖片
-    if ($("[class='spec']", aa).length > 0) {
-        snodes = $("[class='spec']", aa)[0].childNodes;
-        //alert(snodes[0].innerHTML);
-        for (i = 0; i < snodes.length; i++) {
-            var tmpsrc, tmpw, tmph, ampimg;
-            if (snodes[i].nodeName == "AMP-IMG") {
-                ampimg = snodes[i].outerHTML;
-                tmpsrc = ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("src=\"") + 5) - ampimg.indexOf("src=\"") - 5);
-                tmpw = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
-                tmph = ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8);
-                //tmph = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
-                editorBlocks1.push({
-                    type: "image", data: {
-                        file: {
-                            url: BHOUSE_SERVER + editTarget + '/' + tmpsrc,
-                            width: parseInt(tmpw),
-                            height: parseInt(tmph),
-                        },
-                        caption: "小寶優居 | " + $('#ctitle').val(),
-                    }
-                });
-            }
-        }
-    }
-    /* else {
-        editorBlocks1.push({
-            type: "image", data: {
-                file: {
-                    url: 'https://bhouse.com.tw/img/logo2.png',
-                    width: 300,
-                    height: 300,
-                },
-                caption: "小寶優居 | " + $('#ctitle').val(),
-            }
-        });
-    } */
-    $('#editorjs1')[0].innerHTML = "";
-    editor1 = new EditorJS({
-        readOnly: false,
-        holder: 'editorjs1',
-        tools: {
-            paragraph: { inlineToolbar: false },
-            image: {
-                class: ImageTool,
-                config: {
-                    endpoints: {
-                        byFile: '/backstage/upload' + $('#curl').val(),
-                        byUrl: '/backstage/getimage' + $('#curl').val(),
-                    }
-                }
-            }
-        }
-        , data: { blocks: editorBlocks1 }
-        ,
-        onReady: function () {
-            //saveButton.click();
-        },
-        onChange: function (api, block) {
-            //console.log('something changed', block);
-        }
-    });
-    //$('.image-tool__caption').css('display', 'none');
-}
-
-function GenProductSection(mimg, specimg) {
-
-    section = document.createElement('section')
-    tmpstr = `<section class="section44 mb-5">
-    <div class="container">
-      <div class="mb-5">
-        <a href="/solid_wood_furniture">關於設計家具</a> > <a href="/##ctype##">##ctypec##</a> > <a href="##curl##">##ctitle##</a>
-      </div>
-      <div class="row">
-        <div class="col-md-5 col-sm-12">
-          <div class="block">
-            <div class="section-title text-center">
-              <amp-carousel
-                id="carousel-with-preview"
-                width="300"
-                height="300"
-                layout="responsive"
-                type="slides"
-                autoplay
-                delay="2500"
-                role="region"
-                aria-label="小寶優居 | ##ctitle##"
-              >
-##AMP-IMG##
-              </amp-carousel>
-              <div class="mt-3 carousel-preview">
-##PREV-IMG##
-              </div>
-            </div>
-          </div>
-        </div>
-        <div class="col-md-7 col-sm-12">
-          <div class="block ms-md-5 mb-5">
-            <div class="title mb-4"><b>##ctitle##</b></div>
-            <div class="description">
-<b>##swfDesc##</b>
-            </div>
-            <hr>
-            <div class="detail">
-##swfPrice##
-##swfColor##
-##swfSize##
-##swfMat##
-##swfMemo##
-            </div>
-          </div>
-        </div>
-      </div>
-      <div class="card">
-        <div class="card-body text-center">
-          <div class="mb-2">1.商品顏色因拍攝、螢幕差異略有不同,實際顏色請依照門市實際顏色為主</div>
-          <div>2.部分商品因應空間大小,保有客製尺寸服務,詳細客製尺寸,請預約門市諮詢訂購</div>
-        </div>
-      </div>
-##SPEC-IMG##
-</div>
-  </section>`;
-
-    tmpstr = tmpstr.replaceAll('##ctitle##', $("#ctitle").val());
-    tmpstr = tmpstr.replaceAll('##ctype##', $("#ctype").val());
-    tmpstr = tmpstr.replaceAll('##curl##', $("#curl").val());
-    Object.entries(SwfType).forEach(([key, value]) => {
-        if ($("#ctype").val() == key)
-            tmpstr = tmpstr.replaceAll('##ctypec##', value);
-    });
-    tmpstr = tmpstr.replaceAll('##swfDesc##', $("#swfDesc").val());
-    if ($("#swfPrice").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfPrice##', "<div>定價 : " + $("#swfPrice").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfPrice##', '<span></span>');
-    if ($("#swfColor").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfColor##', "<div>顏色 : " + $("#swfColor").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfColor##', '<span></span>');
-    if ($("#swfSize").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfSize##', "<div>尺寸(mm) : " + $("#swfSize").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfSize##', '<span></span>');
-    if ($("#swfMat").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfMat##', "<div>材質 : " + $("#swfMat").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfMat##', '<span></span>');
-    if ($("#swfMemo").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfMemo##', "<div>備註 : " + $("#swfMemo").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfMemo##', '<span></span>');
-
-    mimgstr = "";
-    firstimg = true;
-    for (i = 0; i < mimg.blocks.length; i++) {
-        //alert(block.type);
-        block = mimg.blocks[i];
-        if (block.type == "image") {
-            iurl = block.data.file.url.split('/');
-            if (iurl[iurl.length - 1] != "logo2.png") {
-                if (firstimg) {
-                    $("#cimage").val($("#curl").val() + '/' + iurl[iurl.length - 1]);
-                    firstimg = false;
-                }
-                mimgstr += '<amp-img\n  alt="小寶優居 | ' + $("#ctitle").val()
-                    + '"\n  src="' + iurl[iurl.length - 1]
-                    + '"\n  height="' + block.data.file.height
-                    + '"\n  width="' + block.data.file.width
-                    + '"\n  layout="responsive">\n</amp-img>';
-            }
-        }
-    }
-    tmpstr = tmpstr.replaceAll('##AMP-IMG##', mimgstr == "" ? "" : mimgstr);
-
-    previmgstr = "";
-    for (i = 0; i < mimg.blocks.length; i++) {
-        //alert(block.type);
-        block = mimg.blocks[i];
-        if (block.type == "image") {
-            iurl = block.data.file.url.split('/');
-            if (iurl[iurl.length - 1] != "logo2.png") {
-                previmgstr += (previmgstr == "" ? "" : '\n') + `<button on="tap:carousel-with-preview.goToSlide(index=` + i + `)">
-            <amp-img
-              src="`+ iurl[iurl.length - 1] + `"
-              width="40"
-              height="40"
-              alt="`+ block.data.caption + `"
-            ></amp-img>
-          </button>`;
-            }
-        }
-    }
-    tmpstr = tmpstr.replaceAll('##PREV-IMG##', previmgstr == "" ? "" : previmgstr);
-
-    specimgstr = "";
-    for (i = 0; i < specimg.blocks.length; i++) {
-        //alert(block.type);
-        block = specimg.blocks[i];
-        if (block.type == "image") {
-            iurl = block.data.file.url.split('/');
-            if (iurl[iurl.length - 1] != "logo2.png") {
-                specimgstr += '<amp-img\n  alt="小寶優居 | ' + $("#ctitle").val()
-                    + '"\n  src="' + iurl[iurl.length - 1]
-                    + '"\n  height="' + block.data.file.height
-                    + '"\n  width="' + block.data.file.width
-                    + '"\n  layout="responsive">\n</amp-img>';
-            }
-        }
-    }
-    tmpstr = tmpstr.replaceAll('##SPEC-IMG##', specimgstr == "" ? "" : '<div class="spec"><div class="mb-4"><b>尺寸規格</b></div>' + specimgstr + '</div>');
-
-    return tmpstr;
-
-}
-
-class MDParser {
-
-    constructor(MDtext) {
-        this.headerText = "";
-        this.contentText = "";
-        this.title = "";
-        this.date = new Date();
-        this.draft = true;
-        this.type = "";
-        this.url = "";
-        this.image = "";
-        this.description = "";
-        this.weight = 1;
-        this.tag = [];
-        for (var line of MDtext.split('\n')) {
-            //console.log(line);
-        }
-    }
-
-
-}
-
-

+ 0 - 299
backstage/static/js/old2/editor.js

@@ -1,299 +0,0 @@
-const contentDiv = document.getElementById('editor_block');
-const titleButton = document.getElementById('title_button');
-const submitButton = document.getElementById('submit_button');
-contentApiUrl = `${PORTAL_SERVER}contents?url=${(JSON.parse(document.getElementById('url').textContent)).url}`
-
-aa = "";
-frontMatters = [];
-contentMatters = [];
-editorBlocks = [];
-var editor;
-axios.get(contentApiUrl).then(({ data }) => {
-  const content = data[0]['content'];
-  var blockArray = [{ title: '', data: [] }];
-  var blockCount = 0;
-  blocks = parseMd(content);
-  aa = new MDParser(content);
-  editor_block = document.getElementById('editor_block');
-  //alert(blocks[0]['text']);
-
-  //ul = document.createElement('ul');
-  //ul.id = "sortable";
-  for (i = 0; i < blocks.length; i++) {
-    //li = document.createElement('li');
-    //odiv = document.createElement('div');
-    //odiv.style.border = 'inset 1px gray';
-    if (blocks[i]['type'] == "para") {
-      editorBlocks.push({ type: "paragraph", data: { text: blocks[i]['text'] } });
-      //tmp = document.createElement('textarea');
-      //tmp.style.border = 'outset 5px pink';
-      //tmp.style.width = '100%';
-      //tmp.value = blocks[i]['text'];
-      //odiv.appendChild(tmp);
-    }
-    else if (blocks[i]['type'] == "br") {
-      editorBlocks.push({ type: "paragraph", data: { text: "" } });
-      //tmp = document.createElement('br');
-      //odiv.appendChild(tmp);
-    }
-    else if (blocks[i]['type'] == "img") {
-      ampimg = blocks[i]['text'];
-      //alert(ampimg.indexOf("width=\"",84));
-      //alert(ampimg.substr(ampimg.indexOf("alt=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("alt=\"") + 5) - ampimg.indexOf("alt=\"") - 5));
-      tmpsrc = BHOUSE_SERVER + JSON.parse(document.getElementById('url').textContent).url + '/' + ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("src=\"") + 5) - ampimg.indexOf("src=\"") - 5);
-      //tmpsrc = BHOUSE_SERVER + JSON.parse(document.getElementById('url').textContent).url + '/' + ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.lastIndexOf(".") - ampimg.indexOf("src=\"") -1);
-      //tmpsrc = ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf(".webp") - ampimg.indexOf("src=\""));
-      editorBlocks.push({
-        type: "image", data: {
-          file: {
-            url: tmpsrc,
-            width: parseInt(ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7)),
-            height: parseInt(ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8)),
-          },
-          caption: ampimg.substr(ampimg.indexOf("alt=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("alt=\"") + 5) - ampimg.indexOf("alt=\"") - 5).toString(),
-          stretched: false,
-          withBorder: true,
-          withBackground: false,
-        }
-      });
-      //alert(ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8));
-      //img = document.createElement('img');
-      //img.style.width = '100%';
-      //img.src = tmpsrc;
-      //odiv.appendChild(img);
-    }
-    else if (blocks[i]['type'] == "youtube") {
-      ampimg = blocks[i]['text'];
-      vid = ampimg.substr(ampimg.indexOf("data-videoid=\"") + 14, ampimg.indexOf("\"", ampimg.indexOf("data-videoid=\"") + 14) - ampimg.indexOf("data-videoid=\"") - 14)
-      editorBlocks.push({
-        type: "embed", data: {
-          service: 'youtube',
-          source: 'https://www.youtube.com/watch?' + vid,
-          embed: 'https://www.youtube.com/embed/' + vid,
-          width: parseInt(ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7)),
-          height: parseInt(ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8)),
-        }
-      });
-    }
-    else if (blocks[i]['type'] == "title") {
-      blocks[i]['text'] = blocks[i]['text'].replace("### **", "").replace("**", "")
-      editorBlocks.push({ type: "header", data: { text: blocks[i]['text'] } });
-      //tmp = document.createElement('h3');
-      //tmp.innerHTML = blocks[i]['text'];
-      //odiv.appendChild(tmp);
-    }
-    else if (blocks[i]['type'] == "hr") {
-      //alert('yo');
-      editorBlocks.push({ type: "paragraph", data: { text: "---" } });
-    }
-    else if (blocks[i]['type'] == "mt5") {
-      //alert('yo');
-      editorBlocks.push({ type: "delimiter", data: {} });
-    }
-    else if (blocks[i]['type'] == "table") {
-      //alert('yo');
-      editorBlocks.push({ type: "table", data: { content: tableTextToArray(blocks[i]['text']) } });
-    }
-    //li.appendChild(odiv);
-    //ul.appendChild(li);
-  }
-  //editor_block.appendChild(ul);
-  //$("#sortable").sortable();
-  //$("#sortable").disableSelection();
-  $("#editor_block").css({ "display": "none" });
-  //alert(JSON.parse(document.getElementById('url').textContent).url);
-  $('#editorjs')[0].innerHTML = "";
-  //alert(JSON.stringify(editorBlocks));
-  editor = new EditorJS({
-    readOnly: false,
-    holder: 'editorjs',
-
-    tools: {
-      header: {
-        class: Header,
-        config: {
-          placeholder: 'Header'
-        }
-      },
-
-      image: {
-        class: ImageTool,
-        config: {
-          endpoints: {
-            byFile: '/backstage/upload' + JSON.parse(document.getElementById('url').textContent).url, // Your backend file uploader endpoint
-            byUrl: '/backstage/getimage' + JSON.parse(document.getElementById('url').textContent).url, // Your endpoint that provides uploading by Url
-            /* byFile: '/backstage/upload' + JSON.parse(document.getElementById('url').textContent).url.substring(JSON.parse(document.getElementById('url').textContent).url.lastIndexOf('/')), // Your backend file uploader endpoint
-            byUrl: '/backstage/getimage' + JSON.parse(document.getElementById('url').textContent).url.substring(JSON.parse(document.getElementById('url').textContent).url.lastIndexOf('/')), // Your endpoint that provides uploading by Url */
-            /* byFile: '/backstage/upload/' + $('#ctitle').val(), // Your backend file uploader endpoint
-            byUrl: '/backstage/getimage/' + $('#ctitle').val(), // Your endpoint that provides uploading by Url */
-          }
-        }
-      }
-      ,
-      // warning: {
-      //   class: Warning,
-      //   inlineToolbar: true,
-      //   config: {
-      //     titlePlaceholder: 'Title',
-      //     messagePlaceholder: 'Message',
-      //   },
-      // },
-      table: Table,
-      delimiter: Delimiter,
-      embed: Embed,
-    }
-    ,
-    data: { blocks: editorBlocks }
-    ,
-    onReady: function () {
-      //saveButton.click();
-    },
-    onChange: function (api, block) {
-      //console.log('something changed', block);
-    }
-  });
-
-  /*   for (var blockData of preBlockArray) {
-      blockCount = loadDataToBlock(blockArray, blockCount, blockData);
-    }
-    titleButton.onclick = function () {
-      blockCount = loadDataToBlock(blockArray, blockCount);
-    } */
-});
-
-function editorSave() {
-  editor.save().then((outputData) => {
-    //console.log('Article data: ', outputData);
-    //var mdContent = GetMdHeader();
-    //var mdContent = frontMatters.join('\n');
-    //console.log(mdContent);
-    //console.log(frontMatters.join('\n'));
-    //mdContent = mdContent.replace('draft: ' + (!$('#cdraft').is(':checked')), 'draft: ' + $('#cdraft').val())
-    //alert(mdContent);
-    /*
-    for (var frontMatter of frontMatters) {
-      mdContent += frontMatter + '\n';
-    }
-    
-    //alert($('#cdescription').val());
-    mdContent += '---\n';
-    mdContent += 'title: "' + $('#ctitle').val() + '"\n';
-    mdContent += 'date: ' + $('#cdate').val() + '\n';
-    mdContent += 'draft: ' + $('#cdraft').val() + '\n';
-    mdContent += 'type: "' + $('#ctype').val() + '"\n';
-    mdContent += 'url: "' + $('#curl').val() + '"\n';
-    mdContent += 'image: "' + $('#cimage').val() + '"\n';
-    mdContent += 'description: "' + $('#cdescription').val().replace(/\r?\n/g, '<br>') + '"\n';
-    mdContent += 'weight: ' + ($('#cweight').val() == 'undefined' ? "" : $('#cweight').val()) + '\n';
-    mdContent += 'tag: "' + ($('#ctag').val() == 'undefined' ? "" : $('#ctag').val()) + '"\n';
-    mdContent += '---\n\n';
-    */
-
-    var mdContent = '\n';
-    var articleinfo = frontMatters.join('\n');
-    var opening = '\n<div class="container-fluid blog_article p-0">\n';
-    //var chapterlist = '<section><div class="question-box">\n<ul>\n<li data-gt-duration="100" data-gt-offset="0">小寶優居的客變懶人包將幫你解決以下客變問題:</li>\n';
-    var numChapters = 0;
-    var sectionstarted = false;
-
-    for (i = 0; i < outputData.blocks.length; i++) {
-      //alert(block.type);
-      block = outputData.blocks[i];
-      if (block.type == "header") {
-        mdContent += '<h4>' + block.data.text + '</h4>\n';
-      }
-      else if (block.type == "paragraph") {
-        mdContent += '\n' + block.data.text + '\n';
-      }
-      else if (block.type == "hr") {
-        //alert('hr');
-        mdContent += '\n---\n';
-      }
-      else if (block.type == "image") {
-        //console.log(block.data.file.url);
-        //console.log(JSON.parse(document.getElementById('url').textContent).url);
-        iurl = block.data.file.url.split('/');
-        mdContent += '<img class="w-100" src="' + iurl[iurl.length - 2] + '/' + iurl[iurl.length - 1] + ' alt="' + block.data.caption + '"\n >\n</img>\n'
-        if (block.data.caption != '')
-        {
-          mdContent += '<div class="img-text">\n<p>' + block.data.caption + '</p>\n</div>\n';
-        }
-      }
-      else if (block.type == "delimiter") {
-        mdContent += '\n{{% chuz-div class="mt-5" %}}\n';
-      }
-      else if (block.type == "embed") {
-        mdContent += '<iframe'
-          + '\n  data-videoid="' + block.data.embed.replace('https://www.youtube.com/embed/', '')
-          + '"\n  layout="responsive'
-          + '"\n  width="' + block.data.width
-          + '"\n  height="' + block.data.height
-          + '">\n</iframe>\n</div>\n';
-      }
-      else if (block.type == "table") {
-        //alert(tableArrayToHtml(block.data).length);
-        mdContent += '\n' + tableArrayToHtml(block.data.content) + '\n'
-        //console.log(tableArrayToHtml(block.data.content));
-      }
-    }
-    console.log(mdContent);
-
-    postData = {
-      content: mdContent,
-      url: (JSON.parse(document.getElementById('url').textContent)).url
-    };
-    axios.post(contentApiUrl, json = postData).then(({ data }) => {
-      alert('作品資料已儲存');
-    });
-  }).catch((error) => {
-    console.log('Saving failed: ', error)
-  });
-
-  /*   var mdContent = '';
-    for (var frontMatter of frontMatters) {
-      mdContent += frontMatter + '\n';
-    } */
-
-  //alert(bb);
-  /*     for(var eBlock in outputData.blocks)
-      {
-        alert(eBlock.type);
-      } */
-  /* 
-for (var idx = 0; idx < blockArray.length; idx++) {
- if (_.get(blockArray[idx], 'title', '').includes('敘述')) {
-   mdContent += `\n<!-- ### **${_.get(blockArray[idx], 'title', '')}**-->\n`
- } else {
-   mdContent += `\n### **${_.get(blockArray[idx], 'title', '')}**\n`
- }
- for (var data of _.get(blockArray[idx], 'data', [])) {
-   if (_.get(_.keys(data), 0) === 'description') {
-     if (_.get(data, 'description.text', '').includes('\n')) {
-       for (const line of _.get(data, 'description.text', '').split('\n')) {
-         mdContent += `\n${line}    `;
-       }
-     } else {
-       mdContent += `\n${_.get(data, 'description.text', '')}`;
-     }
-   } else if (_.get(_.keys(data), 0) === 'image') {
-     ampImgForm = `\n<amp-img\
-\n  alt="${_.get(data, 'image.alt', '小寶優居')}"\
-\n  src="${_.get(data, 'image.src', '')}"\
-\n  height="${_.get(data, 'image.height', 300)}"\
-\n  width="${_.get(data, 'image.width', 400)}"\
-\n  layout="${_.get(data, 'image.layout', 'responsive')}">\
-\n</amp-img>\n`;
-     mdContent += ampImgForm;
-   }
- }
-}
-*/
-  /* const postData = {
-    content: mdContent,
-    url: (JSON.parse(document.getElementById('url').textContent)).url
-  }; */
-
-  //axios.post(contentApiUrl, json = postData);
-
-}
-submitButton.onclick = editorSave

+ 0 - 91
backstage/static/js/old2/parsers.js

@@ -1,91 +0,0 @@
-function parseMd(content) {
-  var frontMatters = [];
-  var blockCount;
-  var preDataIndex;
-  var parseBlockDiv;
-  var preImgObject = { 'image': {} };
-  var isNotFrontMatterCount = 0;
-  var isAmpImgRange = false;
-  var result = [];
-
-  for (const line of content.split('\n')) {
-    if (isNotFrontMatterCount < 2) {
-      frontMatters.push(line)
-      if (line.includes('---')) {
-        isNotFrontMatterCount += 1;
-      }
-      continue;
-    }
-
-    if (isAmpImgRange === true && !(line.includes('</img>'))) {
-      imgParamObject = parseAmpImg(line);
-      preImgObject.image = { ...preImgObject.image, ...imgParamObject };
-      continue;
-    }
-
-    if (line.includes('<h4>')) {
-      parseBlockDiv = true;
-      preDataIndex = 0;
-      blockCount = blockCount + 1 | 0;
-      const preBlockindex = blockCount;
-      const title = parseTitle(line);
-      result[preBlockindex] = { title: title };
-
-    } else if (line.includes('img')) {
-      const preBlockindex = blockCount;
-      if (line.includes('</img>')) {
-        addDataToBlockArray(preImgObject, result, preBlockindex, preDataIndex);
-        isAmpImgRange = false;
-        preImgObject = { 'image': {} }
-        preDataIndex += 1;
-        continue;
-      }
-      isAmpImgRange = true;
-    } else {
-      if (parseBlockDiv === undefined) {
-        // for skipping space before first title
-        continue
-      }
-      if (line === '') {
-        // for skipping space
-        continue
-      }
-      const preBlockindex = blockCount;
-      const ownDataIndex = preDataIndex;
-      preDataIndex += 1;
-      //addDataToBlockArray({ description: { text: line } }, result, preBlockindex, ownDataIndex);
-      addDataToBlockArray({ text: line }, result, preBlockindex, ownDataIndex);
-    }
-  }
-  alert(JSON.stringify(result));
-  return { frontMatters: frontMatters, preBlockArray: result }
-}
-
-const parseTitle = line => {
-  var title = '';
-  title = line.replace('### **', '');
-  title = title.replace('**', '');
-  if (title.includes('敘述')) {
-    title = title.replace('<!-- ', '');
-    title = title.replace('-->', '');
-  }
-  return title;
-};
-
-const parseAmpImg = line => {
-  if (line.includes('alt')) {
-    const altParameter = line.replace(/ |alt=|"/g, '');
-    return { alt: altParameter };
-  } else if (line.includes('src')) {
-    const srcParameter = line.replace(/ |src=|"/g, '');
-    return { src: srcParameter };
-  } else if (line.includes('height')) {
-    const heightParameter = line.replace(/ |height=|"/g, '');
-    return { height: heightParameter };
-  } else if (line.includes('width')) {
-    const widthParameter = line.replace(/ |width=|"/g, '');
-    return { width: widthParameter };
-  } else if (line.includes('layout')) {
-    const layoutParameter = line.replace(/ |layout=|"|>/g, '');
-  }
-}

+ 0 - 783
backstage/static/js/old2/yo.js

@@ -1,783 +0,0 @@
-contentApiUrl = `${PORTAL_SERVER}contents?url=`;
-frontMatters = [];
-contentMatters = [];
-tagOptionIds = ['thousetype', 'tpinsize', 'tbudget', 'troomscount'];
-
-var SwfType = {};
-if (location.pathname.indexOf('system_furniture') >= 0) {
-    SwfType = {
-        "custom_made_system_cabinet": "客製模組系統櫃",
-        "system_cabinet": "模組系統櫃單品",
-    };
-}
-else {
-    SwfType = {
-        "other_furniture": "其他",
-        "master_bedroom": "臥室",
-        "living_room": "客廳",
-        "study_room": "書房",
-        "dining_room": "餐廳",
-    };
-}
-
-//document.ready
-$(function () {
-
-    $("#dialog-form").hide();
-    if ($('#editorjs').length > 0)
-        editor = new EditorJS({
-            readOnly: false,
-            holder: 'editorjs',
-        });
-    if ($('#editorjs1').length > 0)
-        editor1 = new EditorJS({
-            readOnly: false,
-            holder: 'editorjs1',
-        });
-
-});
-
-function getHeader(url) {
-    axios.get(contentApiUrl + url).then(({ data }) => {
-        frontMatters = [];
-        contentMatters = [];
-        editTarget = url;
-        mdType = url.split('/')[1];
-        aa = data[0]['content'];
-        for (var toi of tagOptionIds) {
-            $('#' + toi).val("");
-        }
-        //const content = _.get(data, '0.content', '');
-        blocks = parseMd(aa);
-        oTitle = $("#ctitle").val();
-        // $("#dialog-form").dialog();
-        if ($("#ctype").val() == "collection") {
-            $("#scat").hide();
-        }
-        else if ($("#ctype").val() == "blog") {
-            $("#sdesc").hide();
-        }
-        else if ($("#ctype").val() == "news") {
-            $("#sdesc").hide();
-            $("#scat").hide();
-            $("#simg").hide();
-        }
-        else {
-            ParseProductSection(contentMatters.join(''));
-        }
-        $("#myModal").modal();
-
-        //console.log(frontMatters);
-        //alert($('#cimage').val());
-    });
-}
-
-function toggleDraft(obj, url) {
-    axios.get(contentApiUrl + url).then(({ data }) => {
-        frontMatters = [];
-        contentMatters = [];
-        aa = data[0]['content'];
-        const content = _.get(data, '0.content', '');
-        blocks = parseMd(aa);
-        editTarget = url;
-        $('#cdraft').removeAttr('checked');
-        $('#cdraft').prop('checked', obj.checked);
-        updateHeader();
-        oTitle = "";
-    });
-}
-
-function updateHeader() {
-    /* if (oTitle != $('#ctitle').val() && $('#ctitle').val() != "" && oTitle != "") {
-      axios.get('/backstage/modTitle/' + oTitle + '/' + $('#ctitle').val()).then(({ data }) => {
-        if (data.success == "0") {
-          alert('已有重複的標題,請重新設定');
-          return;
-        }
-        else {
-          writeMd();
-        }
-      });
-    }
-    else {
-      writeMd();
-    } */
-    $("#uptbtn").attr('disabled', true);
-    writeMd();
-    // location.reload();
-}
-
-function writeMd() {
-
-    axios.get('/backstage/utils?trantext=' + $('#ccategories').val()).then(({ data }) => { $('#ccol1').val(data); })
-        .finally(() => {
-            mdContent = GetMdHeader();
-            mdContent += contentMatters.join("\n");
-            var formData = new FormData();
-            var imagefile = document.querySelector('#cfile');
-            formData.append("image", imagefile.files[0]);
-            axios.post('/backstage/upload/title', formData, {
-                headers: {
-                    'Content-Type': 'multipart/form-data'
-                }
-            }).then(({ data }) => {
-                $('#cfile').val("");
-                if (data.success == "1") {
-                    mdContent = mdContent.replace($('#cimage').val(), '/img/collection/' + data.file.url.substring(data.file.url.lastIndexOf('/') + 1));
-                    //alert(data.file.url.substring(data.file.url.lastIndexOf('/')+1));
-                }
-
-                postData = {
-                    content: mdContent,
-                    url: editTarget
-                };
-                //console.log(mdContent);
-                axios.post(contentApiUrl + editTarget, json = postData).then(({ data }) => {
-                });
-            }).finally(() => {
-                alert('資料已更新'); // test
-                location.reload();
-            });
-
-        });
-}
-
-function parseMd(content) {
-    //var frontMatters = [];
-    var blockCount;
-    var preDataIndex;
-    var parseBlockDiv;
-    var preImgObject = { 'image': {} };
-    var isNotFrontMatterCount = 0;
-    var isAmpImgRange = false;
-    var result = [];
-
-    var rblocks = new Array();
-    lineIdx = 1;
-    foundImg = false;
-    foundYT = false;
-    foundTBL = false;
-    crossLine = "";
-
-    for (var line of content.split('\n')) {
-        lineIdx++;
-        if (isNotFrontMatterCount < 2) {
-            frontMatters.push(line)
-            if (line.includes('title: ')) {
-                $('#ctitle').val(line.replace('title: ', '').replaceAll('\"', ''));
-                //alert($('#ctitle').val());
-            }
-            if (line.includes('date: ')) {
-                //alert(line);
-                $('#cdate').val(line.replace('date: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('draft: ')) {
-                //alert(line);
-                $('#cdraft').val(line.replace('draft: ', '').replaceAll('\"', ''));
-                //console.log($('#cdraft').val());
-                $('#cdraft').removeAttr('checked');
-                if ($('#cdraft').val() == 'false')
-                    $('#cdraft').prop('checked', true);
-                /*
-                if($('#cdraft').val() == 'true') 
-                    $('#cdraft').removeAttr('checked');
-                else
-                    $('#cdraft').attr('checked','true');
-                    */
-            }
-            if (line.includes('type: ')) {
-                //alert(line);
-                $('#ctype').val(line.replace('type: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('url: ')) {
-                //alert(line);
-                $('#curl').val(line.replace('url: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('image: ')) {
-                //alert(line);
-                $('#cimage').val(line.replace('image: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('description: ')) {
-                //alert(line);
-                $('#cdescription').val(line.replace('description: ', '').replaceAll('\"', '').replaceAll('<br>', '\r\n'));
-            }
-            if (line.includes('weight: ')) {
-                //alert(line);
-                $('#cweight').val(line.replace('weight: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('tag: ')) {
-                //alert(line);
-                $('#ctag').val(line.replace('tag: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('tags: ')) {
-                //alert(line);
-                if ($('#ctags').length > 0) {
-                    $('#ctags').val(line.replace('tags: ', '').replaceAll('\"', ''));
-                    tags = $('#ctags').val().split(',');
-                    for (var tag of tags) {
-                        //console.log(tag);
-                        for (var toi of tagOptionIds) {
-                            $('#' + toi + ' option').each(function () {
-                                if (this.value == tag)
-                                    this.selected = true;
-                            });
-                        }
-                    }
-                }
-            }
-            if (line.includes('categories: ')) {
-                //alert(line);
-                $('#ccategories').val(line.replace('categories: ', '').replace('categories: ', '').replace(/\[|]/g, '').replace(/\"/g, ''));
-            }
-            /* if (line.includes('caturl: ')) {
-                //alert(line);
-                $('#ccaturl').val(line.replace('caturl: ', '').replaceAll('\"', ''));
-            } */
-            if (line.includes('col1: ')) {
-                //alert(line);
-                $('#ccol1').val(line.replace('col1: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('col2: ')) {
-                //alert(line);
-                $('#ccol2').val(line.replace('col2: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('meta_title: ')) {
-                //alert(line);
-                $('#cmetattl').val(line.replace('title: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('meta_description: ')) {
-                //alert(line);
-                $('#cmetadsc').val(line.replace('title: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('introduction: ')) {
-                //alert(line);
-                $('#cintroduction').val(line.replace('description: ', '').replaceAll('\"', '').replaceAll('<br>', '\r\n'));
-            }
-            if (line.includes('question_box_intro: ')) {
-                //alert(line);
-                $('#cquestionboxintro').val(line.replace('title: ', '').replaceAll('\"', ''));
-            }
-            if (line.includes('---')) {
-                isNotFrontMatterCount += 1;
-            }
-            continue;
-        }
-        contentMatters.push(line)
-        /*         if (line.toString().trim() == "") {
-                    rblocks.push({ 'type': 'br', 'text': line });
-                    continue;
-                } */
-
-        if (line.includes('---')) {
-            rblocks.push({ 'type': 'hr', 'text': line });
-            continue;
-        }
-
-        if (line.includes('<h4>')) {
-            rblocks.push({ 'type': 'title', 'text': line });
-            continue;
-        }
-
-        if (line.includes('{{% chuz-div class=\"mt-5\" %}}')) {
-            rblocks.push({ 'type': 'mt5', 'text': line });
-            continue;
-        }
-
-        if (line.includes('<img') || foundImg) {
-            crossLine += line;
-            foundImg = true;
-            if (line.includes('</img>')) {
-                rblocks.push({ 'type': 'img', 'text': crossLine });
-                foundImg = false;
-                crossLine = "";
-            }
-            continue;
-        }
-
-        if (line.includes('<iframe') || foundYT) {
-            crossLine += line;
-            foundYT = true;
-            if (line.includes('</iframe>')) {
-                rblocks.push({ 'type': 'youtube', 'text': crossLine });
-                foundYT = false;
-                crossLine = "";
-            }
-            continue;
-        }
-
-        if (line.includes('<table') || foundTBL) {
-            crossLine += line;
-            foundTBL = true;
-            if (line.includes('</table>')) {
-                rblocks.push({ 'type': 'table', 'text': crossLine });
-                foundTBL = false;
-                crossLine = "";
-            }
-            continue;
-        }
-
-        rblocks.push({ 'type': 'para', 'text': line });
-    }
-
-    return rblocks
-}
-
-function GetMdHeader() {
-    rContent = "";
-    rContent += '---\n';
-    rContent += 'title: "' + $('#ctitle').val() + '"\n';
-    rContent += 'date: ' + $('#cdate').val() + '\n';
-    rContent += 'draft: ' + (!$('#cdraft').is(':checked')) + '\n';
-    rContent += 'type: "' + $('#ctype').val() + '"\n';
-    rContent += 'url: "' + $('#curl').val() + '"\n';
-    //mdContent += 'url: "' + $('#curl').val() + '"\n';
-    rContent += 'image: "' + $('#cimage').val() + '"\n';
-    if ($('#ctype').val() == "collection") {
-        rContent += 'description: "' + $('#cdescription').val().replace(/\r?\n/g, '<br>') + '"\n';
-        rContent += 'weight: ' + ($('#cweight').val() == 'undefined' ? "" : $('#cweight').val()) + '\n';
-
-        tags = [];
-        for (var toi of tagOptionIds) {
-            if ($('#' + toi).val() != "")
-                tags.push($('#' + toi).val());
-        }
-        rContent += 'tags: "' + tags.join(',') + '"\n';
-        //rContent += 'tags: "' + ($('#ctags').val() == 'undefined' ? "" : $('#ctags').val()) + '"\n';
-    }
-    else if ($('#ctype').val() == "blog") {
-        rContent += 'categories: ["' + $('#ccategories').val() + '"]\n';
-        //rContent += 'caturl: "' + $('#ccaturl').val() + '"\n';
-        rContent += 'col1: "' + ($('#ccol1').val() == 'undefined' ? "" : $('#ccol1').val()) + '"\n';
-        rContent += 'col2: "' + ($('#ccol2').val() == 'undefined' ? "" : $('#ccol2').val()) + '"\n';
-    }
-    rContent += '---\n';
-    //alert(rContent);
-    return rContent
-}
-
-const parseTitle = line => {
-    var title = '';
-    title = line.replace('### **', '');
-    title = title.replace('**', '');
-    if (title.includes('敘述')) {
-        title = title.replace('<!-- ', '');
-        title = title.replace('-->', '');
-    }
-    return title;
-};
-
-const parseAmpImg = line => {
-    if (line.includes('alt')) {
-        const altParameter = line.replace(/ |alt=|"/g, '');
-        return { alt: altParameter };
-    } else if (line.includes('src')) {
-        const srcParameter = line.replace(/ |src=|"/g, '');
-        return { src: srcParameter };
-    } else if (line.includes('height')) {
-        const heightParameter = line.replace(/ |height=|"/g, '');
-        return { height: heightParameter };
-    } else if (line.includes('width')) {
-        const widthParameter = line.replace(/ |width=|"/g, '');
-        return { width: widthParameter };
-    } else if (line.includes('layout')) {
-        const layoutParameter = line.replace(/ |layout=|"|>/g, '');
-    }
-}
-
-function tableTextToArray(tableHtml) {
-    tbl = document.createElement('table');
-    tbl.innerHTML = tableHtml.replace('<table>', '').replace('</table>', '');
-    var tableInfo = Array.prototype.map.call(tbl.querySelectorAll('tr'), function (tr) {
-        return Array.prototype.map.call(tr.querySelectorAll('td'), function (td) {
-            return td.innerHTML;
-        });
-    });
-    return tableInfo;
-}
-
-function tableArrayToHtml(tableArray) {
-    tbl = document.createElement('table');
-    for (j = 0; j < tableArray.length; j++) {
-        tr = document.createElement('tr');
-        for (k = 0; k < tableArray[j].length; k++) {
-            td = document.createElement('td');
-            if (k == 0)
-                td.style.width = "25%";
-            td.innerHTML = tableArray[j][k];
-            tr.appendChild(td);
-        }
-        tbl.appendChild(tr);
-    }
-    //alert(tbl.outerHTML.toString());
-    return tbl.outerHTML.toString();
-}
-
-function GenSwfDD(obj) {
-    Object.entries(SwfType).forEach(([key, value]) => {
-        op = document.createElement('option');
-        op.value = key;
-        op.text = value;
-        obj.appendChild(op);
-    });
-}
-
-function ReplaceSwfType(inContent) {
-    Object.entries(SwfType).forEach(([key, value]) => {
-        inContent = inContent.replaceAll('[' + key + ']', '[' + value + ']');
-    });
-    return inContent;
-}
-
-var editor;
-var editor1;
-editorBlocks = [];
-editorBlocks1 = [];
-function ParseProductSection(inContent) {
-    editorBlocks = [];
-    editorBlocks1 = [];
-    var aa = $.parseHTML(inContent.trim());
-    //處理圖片
-    if ($("[id='carousel-with-preview']", aa).length > 0) {
-        imgnodes = $("[id='carousel-with-preview']", aa)[0].childNodes;
-        for (i = 0; i < imgnodes.length; i++) {
-            var tmpsrc, tmpw, tmph, ampimg;
-            if (imgnodes[i].nodeName == "AMP-IMG") {
-                //alert(imgnodes[i].nodeName);
-                ampimg = imgnodes[i].outerHTML;
-                tmpsrc = ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("src=\"") + 5) - ampimg.indexOf("src=\"") - 5);
-                //alert(tmpsrc);
-                tmpw = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
-                tmph = ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8);
-                //tmph = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
-                editorBlocks.push({
-                    type: "image", data: {
-                        file: {
-                            url: BHOUSE_SERVER + editTarget + '/' + tmpsrc,
-                            width: parseInt(tmpw),
-                            height: parseInt(tmph),
-                        },
-                        caption: "小寶優居 | " + $('#ctitle').val(),
-                    }
-                });
-            }
-        }
-    }
-    /*     else {
-            editorBlocks.push({
-                type: "image", data: {
-                    file: {
-                        url: 'https://bhouse.com.tw/img/logo2.png',
-                        width: 300,
-                        height: 300,
-                    },
-                    caption: "小寶優居 | " + $('#ctitle').val(),
-                }
-            });
-        } */
-    //editor.api.blocks.render(editorBlocks);
-    $('#editorjs')[0].innerHTML = "";
-    //alert(editorBlocks);
-    editor = new EditorJS({
-        readOnly: false,
-        holder: 'editorjs',
-        tools: {
-            paragraph: { inlineToolbar: false },
-            image: {
-                class: ImageTool,
-                config: {
-                    endpoints: {
-                        byFile: '/backstage/upload' + $('#curl').val(),
-                        byUrl: '/backstage/getimage' + $('#curl').val(),
-                    }
-                }
-            }
-        }
-        , data: { blocks: editorBlocks }
-        ,
-        onReady: function () {
-            //alert(editor.blocks.getBlocksCount());
-            //saveButton.click();
-        },
-        onChange: function (api, block) {
-            //$('#cimage')[0].val();
-            //console.log('something changed', block);
-        }
-    });
-
-    //類別
-    Object.entries(SwfType).forEach(([key, value]) => {
-        if ($("#ctype").val() == key) {
-            //alert($("#ctype").val());
-            $("#swfDropdown").val($("#ctype").val());
-        }
-    });
-
-    //敘述
-    $("#swfDesc").val("");
-    if ($("[class='description']", aa).length > 0) {
-        $("#swfDesc").val($(".description", aa)[0].innerHTML.trim().replaceAll('<b>', '').replaceAll('</b>', ''));
-    }
-    //alert(editorBlocks);
-    //其他
-    $("#swfPrice").val("");
-    $("#swfColor").val("");
-    $("#swfSize").val("");
-    $("#swfMat").val("");
-    $("#swfMemo").val("");
-    if ($("[class='detail']", aa).length > 0) {
-        onodes = $("[class='detail']", aa)[0].childNodes;
-        for (i = 0; i < onodes.length; i++) {
-            if (onodes[i].nodeName != "#text") {
-                if (onodes[i].innerHTML.trim().indexOf("定價 : ") >= 0)
-                    $("#swfPrice").val(onodes[i].innerHTML.replace("定價 : ", "").trim());
-                if (onodes[i].innerHTML.trim().indexOf("顏色 : ") >= 0)
-                    $("#swfColor").val(onodes[i].innerHTML.replace("顏色 : ", "").trim());
-                if (onodes[i].innerHTML.trim().indexOf("尺寸(mm) : ") >= 0)
-                    $("#swfSize").val(onodes[i].innerHTML.replace("尺寸(mm) : ", "").trim());
-                if (onodes[i].innerHTML.trim().indexOf("材質 : ") >= 0)
-                    $("#swfMat").val(onodes[i].innerHTML.replace("材質 : ", "").trim());
-                if (onodes[i].innerHTML.trim().indexOf("備註 : ") >= 0)
-                    $("#swfMemo").val(onodes[i].innerHTML.replace("備註 : ", "").trim());
-                //alert(nodes[i].innerHTML);
-            }
-        }
-    }
-
-    //處理規格圖片
-    if ($("[class='spec']", aa).length > 0) {
-        snodes = $("[class='spec']", aa)[0].childNodes;
-        //alert(snodes[0].innerHTML);
-        for (i = 0; i < snodes.length; i++) {
-            var tmpsrc, tmpw, tmph, ampimg;
-            if (snodes[i].nodeName == "AMP-IMG") {
-                ampimg = snodes[i].outerHTML;
-                tmpsrc = ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("src=\"") + 5) - ampimg.indexOf("src=\"") - 5);
-                tmpw = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
-                tmph = ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8);
-                //tmph = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
-                editorBlocks1.push({
-                    type: "image", data: {
-                        file: {
-                            url: BHOUSE_SERVER + editTarget + '/' + tmpsrc,
-                            width: parseInt(tmpw),
-                            height: parseInt(tmph),
-                        },
-                        caption: "小寶優居 | " + $('#ctitle').val(),
-                    }
-                });
-            }
-        }
-    }
-    /* else {
-        editorBlocks1.push({
-            type: "image", data: {
-                file: {
-                    url: 'https://bhouse.com.tw/img/logo2.png',
-                    width: 300,
-                    height: 300,
-                },
-                caption: "小寶優居 | " + $('#ctitle').val(),
-            }
-        });
-    } */
-    $('#editorjs1')[0].innerHTML = "";
-    editor1 = new EditorJS({
-        readOnly: false,
-        holder: 'editorjs1',
-        tools: {
-            paragraph: { inlineToolbar: false },
-            image: {
-                class: ImageTool,
-                config: {
-                    endpoints: {
-                        byFile: '/backstage/upload' + $('#curl').val(),
-                        byUrl: '/backstage/getimage' + $('#curl').val(),
-                    }
-                }
-            }
-        }
-        , data: { blocks: editorBlocks1 }
-        ,
-        onReady: function () {
-            //saveButton.click();
-        },
-        onChange: function (api, block) {
-            //console.log('something changed', block);
-        }
-    });
-    //$('.image-tool__caption').css('display', 'none');
-}
-
-function GenProductSection(mimg, specimg) {
-
-    section = document.createElement('section')
-    tmpstr = `<section class="section44 mb-5">
-    <div class="container">
-      <div class="mb-5">
-        <a href="/solid_wood_furniture">關於設計家具</a> > <a href="/##ctype##">##ctypec##</a> > <a href="##curl##">##ctitle##</a>
-      </div>
-      <div class="row">
-        <div class="col-md-5 col-sm-12">
-          <div class="block">
-            <div class="section-title text-center">
-              <amp-carousel
-                id="carousel-with-preview"
-                width="300"
-                height="300"
-                layout="responsive"
-                type="slides"
-                autoplay
-                delay="2500"
-                role="region"
-                aria-label="小寶優居 | ##ctitle##"
-              >
-##AMP-IMG##
-              </amp-carousel>
-              <div class="mt-3 carousel-preview">
-##PREV-IMG##
-              </div>
-            </div>
-          </div>
-        </div>
-        <div class="col-md-7 col-sm-12">
-          <div class="block ms-md-5 mb-5">
-            <div class="title mb-4"><b>##ctitle##</b></div>
-            <div class="description">
-<b>##swfDesc##</b>
-            </div>
-            <hr>
-            <div class="detail">
-##swfPrice##
-##swfColor##
-##swfSize##
-##swfMat##
-##swfMemo##
-            </div>
-          </div>
-        </div>
-      </div>
-      <div class="card">
-        <div class="card-body text-center">
-          <div class="mb-2">1.商品顏色因拍攝、螢幕差異略有不同,實際顏色請依照門市實際顏色為主</div>
-          <div>2.部分商品因應空間大小,保有客製尺寸服務,詳細客製尺寸,請預約門市諮詢訂購</div>
-        </div>
-      </div>
-##SPEC-IMG##
-</div>
-  </section>`;
-
-    tmpstr = tmpstr.replaceAll('##ctitle##', $("#ctitle").val());
-    tmpstr = tmpstr.replaceAll('##ctype##', $("#ctype").val());
-    tmpstr = tmpstr.replaceAll('##curl##', $("#curl").val());
-    Object.entries(SwfType).forEach(([key, value]) => {
-        if ($("#ctype").val() == key)
-            tmpstr = tmpstr.replaceAll('##ctypec##', value);
-    });
-    tmpstr = tmpstr.replaceAll('##swfDesc##', $("#swfDesc").val());
-    if ($("#swfPrice").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfPrice##', "<div>定價 : " + $("#swfPrice").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfPrice##', '<span></span>');
-    if ($("#swfColor").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfColor##', "<div>顏色 : " + $("#swfColor").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfColor##', '<span></span>');
-    if ($("#swfSize").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfSize##', "<div>尺寸(mm) : " + $("#swfSize").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfSize##', '<span></span>');
-    if ($("#swfMat").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfMat##', "<div>材質 : " + $("#swfMat").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfMat##', '<span></span>');
-    if ($("#swfMemo").val() != "")
-        tmpstr = tmpstr.replaceAll('##swfMemo##', "<div>備註 : " + $("#swfMemo").val() + "</div>");
-    else
-        tmpstr = tmpstr.replaceAll('##swfMemo##', '<span></span>');
-
-    mimgstr = "";
-    firstimg = true;
-    for (i = 0; i < mimg.blocks.length; i++) {
-        //alert(block.type);
-        block = mimg.blocks[i];
-        if (block.type == "image") {
-            iurl = block.data.file.url.split('/');
-            if (iurl[iurl.length - 1] != "logo2.png") {
-                if (firstimg) {
-                    $("#cimage").val($("#curl").val() + '/' + iurl[iurl.length - 1]);
-                    firstimg = false;
-                }
-                mimgstr += '<amp-img\n  alt="小寶優居 | ' + $("#ctitle").val()
-                    + '"\n  src="' + iurl[iurl.length - 1]
-                    + '"\n  height="' + block.data.file.height
-                    + '"\n  width="' + block.data.file.width
-                    + '"\n  layout="responsive">\n</amp-img>';
-            }
-        }
-    }
-    tmpstr = tmpstr.replaceAll('##AMP-IMG##', mimgstr == "" ? "" : mimgstr);
-
-    previmgstr = "";
-    for (i = 0; i < mimg.blocks.length; i++) {
-        //alert(block.type);
-        block = mimg.blocks[i];
-        if (block.type == "image") {
-            iurl = block.data.file.url.split('/');
-            if (iurl[iurl.length - 1] != "logo2.png") {
-                previmgstr += (previmgstr == "" ? "" : '\n') + `<button on="tap:carousel-with-preview.goToSlide(index=` + i + `)">
-            <amp-img
-              src="`+ iurl[iurl.length - 1] + `"
-              width="40"
-              height="40"
-              alt="`+ block.data.caption + `"
-            ></amp-img>
-          </button>`;
-            }
-        }
-    }
-    tmpstr = tmpstr.replaceAll('##PREV-IMG##', previmgstr == "" ? "" : previmgstr);
-
-    specimgstr = "";
-    for (i = 0; i < specimg.blocks.length; i++) {
-        //alert(block.type);
-        block = specimg.blocks[i];
-        if (block.type == "image") {
-            iurl = block.data.file.url.split('/');
-            if (iurl[iurl.length - 1] != "logo2.png") {
-                specimgstr += '<amp-img\n  alt="小寶優居 | ' + $("#ctitle").val()
-                    + '"\n  src="' + iurl[iurl.length - 1]
-                    + '"\n  height="' + block.data.file.height
-                    + '"\n  width="' + block.data.file.width
-                    + '"\n  layout="responsive">\n</amp-img>';
-            }
-        }
-    }
-    tmpstr = tmpstr.replaceAll('##SPEC-IMG##', specimgstr == "" ? "" : '<div class="spec"><div class="mb-4"><b>尺寸規格</b></div>' + specimgstr + '</div>');
-
-    return tmpstr;
-
-}
-
-class MDParser {
-
-    constructor(MDtext) {
-        this.headerText = "";
-        this.contentText = "";
-        this.title = "";
-        this.date = new Date();
-        this.draft = true;
-        this.type = "";
-        this.url = "";
-        this.image = "";
-        this.description = "";
-        this.weight = 1;
-        this.tag = [];
-        for (var line of MDtext.split('\n')) {
-            //console.log(line);
-        }
-    }
-
-
-}
-
-

+ 125 - 33
backstage/static/js/yo.js

@@ -115,38 +115,38 @@ function updateHeader() {
 }
 
 function writeMd() {
-
     axios.get('/backstage/utils?trantext=' + $('#ccategories').val()).then(({ data }) => { $('#ccol1').val(data); })
-        .finally(() => {
-            mdContent = GetMdHeader();
-            mdContent += contentMatters.join("\n");
-            var formData = new FormData();
-            var imagefile = document.querySelector('#cfile');
-            formData.append("image", imagefile.files[0]);
-            axios.post('/backstage/upload/title', formData, {
-                headers: {
-                    'Content-Type': 'multipart/form-data'
-                }
-            }).then(({ data }) => {
-                $('#cfile').val("");
-                if (data.success == "1") {
-                    mdContent = mdContent.replace($('#cimage').val(), '/img/title/' + data.file.url.substring(data.file.url.lastIndexOf('/') + 1));
-                    //alert(data.file.url.substring(data.file.url.lastIndexOf('/')+1));
-                }
+    .finally(() => {
+        mdContent = GetMdHeader();
+        mdContent += contentMatters.join("\n");
+        var formData = new FormData();
+        var imagefile = document.querySelector('#cfile');
+        console.log(imagefile.files);
+        formData.append("image", imagefile.files[0]);
+        axios.post('/backstage/upload/title', formData, {
+            headers: {
+                'Content-Type': 'multipart/form-data'
+            }
+        }).then(({ data }) => {
+            $('#cfile').val("");
+            if (data.success == "1") {
+                mdContent = mdContent.replace($('#cimage').val(), '/img/title/' + data.file.url.substring(data.file.url.lastIndexOf('/') + 1));
+                //alert(data.file.url.substring(data.file.url.lastIndexOf('/')+1));
+            }
 
-                postData = {
-                    content: mdContent,
-                    url: editTarget
-                };
-                //console.log(mdContent);
-                axios.post(contentApiUrl + editTarget, json = postData).then(({ data }) => {
-                });
-            }).finally(() => {
-                alert('資料已更新'); // test
-                location.reload();
+            postData = {
+                content: mdContent,
+                url: editTarget
+            };
+            //console.log(mdContent);
+            axios.post(contentApiUrl + editTarget, json = postData).then(({ data }) => {
             });
-
+        }).finally(() => {
+            alert('資料已更新'); // test
+            location.reload();
         });
+
+    });
 }
 
 function parseMd(content) {
@@ -170,14 +170,14 @@ function parseMd(content) {
         lineIdx++;
         if (isNotFrontMatterCount < 2) {
             frontMatters.push(line)
+
             if (line.includes('meta_title: ')) {
                 //alert(line);
                 $('#cmetattl').val(line.replace('meta_title: ', '').replaceAll('\"', ''));
             }
             else if (line.includes('title: ')) {
                 $('#ctitle').val(line.replace('title: ', '').replaceAll('\"', ''));
-                console.log($('#ctitle').val());
-                //alert($('#ctitle').val());
+                //console.log($('#ctitle').val());
             }
             if (line.includes('date: ')) {
                 //alert(line);
@@ -213,9 +213,13 @@ function parseMd(content) {
                 //alert(line);
                 $('#cmetadsc').val(line.replace('meta_description: ', '').replaceAll('\"', ''));
             }
+            else if (line.includes('collection_description: ')) { //collections
+                //alert(line);
+                $('#ccolldesc').val(line.replace('collection_description: ', '').replaceAll('\"', '').replaceAll('<br>', '\r\n'));
+            }
             else if (line.includes('description: ')) {
                 $('#cdescription').val(line.replace('description: ', '').replaceAll('\"', '').replaceAll('<br>', '\r\n'));
-                console.log($('#cdescription').val());
+                //console.log($('#cdescription').val());
             }
             if (line.includes('weight: ')) {
                 //alert(line);
@@ -257,6 +261,8 @@ function parseMd(content) {
                 //alert(line);
                 $('#ccol2').val(line.replace('col2: ', '').replaceAll('\"', ''));
             }
+
+            //for blogs
             if (line.includes('introduction: ')) {
                 //alert(line);
                 $('#cintroduction').val(line.replace('introduction: ', '').replaceAll('\"', '').replaceAll('<br>', '\r\n'));
@@ -264,7 +270,77 @@ function parseMd(content) {
             if (line.includes('question_box_intro: ')) {
                 //alert(line);
                 $('#cquestionboxintro').val(line.replace('question_box_intro: ', '').replaceAll('\"', ''));
-            }            
+            }
+
+            
+            //for collections
+            if (line.includes('banner_img_text: ')) {
+                //alert(line);
+                $('#ccoverimgtxt').val(line.replace('banner_img_text: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('homeowner: ')) {
+                //alert(line);
+                $('#chomeowner').val(line.replace('homeowner: ', '').replaceAll('\"', ''));
+				
+            }
+
+            if (line.includes('size: ')) {
+                //alert(line);
+                $('#csize').val(line.replace('size: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('bed_num: ')) {
+                //alert(line);
+                $('#cbednum').val(line.replace('bed_num: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('house_cat: ')) {
+                //alert(line);
+                $('#thousetype').val(line.replace('house_cat: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('designer: ')) {
+                //alert(line);
+                $('#cdesigner').val(line.replace('designer: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('space: ')) {
+                //alert(line);
+                $('#cspace').val(line.replace('space: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('loc: ')) {
+                //alert(line);
+                $('#cloc').val(line.replace('loc: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('budget: ')) {
+                //alert(line);
+                $('#cbudget').val(line.replace('budget: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('construction: ')) {
+                //alert(line);
+                $('#cconstruction').val(line.replace('construction: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('collection_name: ')) {
+                //alert(line);
+                $('#ccollname').val(line.replace('collection_name: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('collection_slider: ')) {
+                //alert(line);
+                //$('#ccollslider').val(line.replace('collection_slider: ', '').replaceAll('\"', ''));
+            }
+
+            if (line.includes('comment: ')) {
+                //alert(line);
+                //$('#ccomment').val(line.replace('comment: ', '').replaceAll('\"', ''));
+            }
+
+            // back to normal
             if (line.includes('---')) {
                 isNotFrontMatterCount += 1;
             }
@@ -351,8 +427,10 @@ function GetMdHeader() {
     //mdContent += 'url: "' + $('#curl').val() + '"\n';
     rContent += 'image: "' + $('#cimage').val() + '"\n';
     if ($('#ctype').val() == "collection") {
+        rContent += 'collection_name: "' + $('#ccollname').val() + '"\n';
+        rContent += 'cover_img: "' + $('#ccoverimg').val() + '"\n';
         rContent += 'description: "' + $('#cdescription').val().replace(/\r?\n/g, '<br>') + '"\n';
-        rContent += 'weight: ' + ($('#cweight').val() == 'undefined' ? "" : $('#cweight').val()) + '\n';
+        //rContent += 'weight: ' + ($('#cweight').val() == 'undefined' ? "" : $('#cweight').val()) + '\n';
 
         tags = [];
         for (var toi of tagOptionIds) {
@@ -361,6 +439,20 @@ function GetMdHeader() {
         }
         rContent += 'tags: "' + tags.join(',') + '"\n';
         //rContent += 'tags: "' + ($('#ctags').val() == 'undefined' ? "" : $('#ctags').val()) + '"\n';
+
+        rContent += 'banner_img_text: "' + $('#ccoverimgtxt').val() + '"\n';
+        rContent += 'homeowner: "' + $('#chomeowner').val() + '"\n';
+        rContent += 'size: "' + $('#csize').val() + '"\n';
+        rContent += 'bed_num: "' + $('#cbednum').val() + '"\n';
+        rContent += 'house_cat: "' + $('#thousetype').val() + '"\n';
+        rContent += 'designer: "' + $('#cdesigner').val() + '"\n';
+        rContent += 'space: "' + $('#cspace').val() + '"\n';
+        rContent += 'loc: "' + $('#cloc').val() + '"\n';
+        rContent += 'budget: "' + $('#cbudget').val() + '"\n';
+        rContent += 'construction: "' + $('#cconstruction').val() + '"\n';
+        rContent += 'collection_description: "' + $('#ccolldesc').val() + '"\n';
+        rContent += 'collection_slider: "' + $('#ccollslider').val() + '"\n';
+        rContent += 'comment: "' + $('#ccomment').val() + '"\n';
     }
     else if ($('#ctype').val() == "blog" || $('#ctype').val() == "maincategories") {
         rContent += 'categories: ["' + $('#ccategories').val() + '"]\n';

+ 135 - 25
backstage/templates/collections.html

@@ -38,11 +38,15 @@
   <div class="form-group">
     {{ form.title.label(class="form-control-label modal__label mb-1") }} <span class="text-danger">(建議字數: 15字內)</span>
     {{ form.title(class="form-control form-control-lg") }}
+    
+    {{ form.description.label(class="form-control-label modal__label mt-3 mb-1") }} <span class="text-danger">(建議字數:
+      50字內)</span>
+    {{ form.description(class="form-control form-control-lg textarea") }}
 
     {{ form.collectiontitle.label(class="form-control-label modal__label mb-1") }}
     {{ form.collectiontitle(class="form-control form-control-lg") }}
 
-    {{ form.description.label(class="form-control-label modal__label mt-3 mb-1") }} <span class="text-danger">(建議字數:
+    {{ form.collectiondesc.label(class="form-control-label modal__label mt-3 mb-1") }} <span class="text-danger">(建議字數:
       50字內)</span>
     {{ form.collectiondesc(class="form-control form-control-lg textarea") }}
 
@@ -50,10 +54,6 @@
       寬2048px * 高1365px)</span>
     {{ form.image(class="form-control form-control-lg modal__file") }}
 
-    {{ form.description.label(class="form-control-label modal__label mt-3 mb-1") }} <span class="text-danger">(建議字數:
-      50字內)</span>
-    {{ form.description(class="form-control form-control-lg textarea") }}
-
     {{ form.tags.label(class="form-control-label modal__label mb-1") }}
     {{ form.tags(class="form-control form-control-lg") }}    
     
@@ -140,6 +140,35 @@
               <td><input class="form-control" id="cmetadsc" type="text" />
               </td>
             </tr>
+            <tr id='sdesc'>
+              <td>
+                <h4>描述</h4>
+              </td>
+              <td><textarea class="form-control" rows="3" id="cdescription"></textarea>
+                <div class="mt-1 text-danger">(建議字數: 50字內)</div>
+              </td>
+            </tr>
+            <tr>
+              <td>
+                <h4>作品集標題</h4>
+              </td>
+              <td><input class="form-control" id="ccollname" type="text" />
+              </td>
+            </tr>
+            <tr>
+              <td>
+                <h4>日期</h4>
+              </td>
+              <td><input class="form-control" id="cdate" type="text" /></td>
+            </tr>
+            <tr>
+            <tr>
+              <td>
+                <h4>作品集描述</h4>
+              </td>
+              <td><textarea class="form-control" rows="3" id="ccolldesc"></textarea>
+              </td>
+            </tr>
             <tr>
               <td>
                 <h4>圖片</h4>
@@ -149,60 +178,137 @@
                 <div class="mt-1 text-danger">(建議尺寸/比例: 寬2048px * 高1365px)</div>
               </td>
             </tr>
-            <tr id='sdesc'>
+            <tr>
               <td>
-                <h4>描述</h4>
+                <h4>分類</h4>
               </td>
-              <td><textarea class="form-control" rows="3" id="cdescription"></textarea>
-                <div class="mt-1 text-danger">(建議字數: 50字內)</div>
+              <td><input class="form-control" id="ctags" type="text" />
               </td>
             </tr>
             <tr>
               <td>
-                <h4>日期</h4>
+                <h4>封面圖片</h4>
+              </td>
+              <td>
+                <input class="form-control" id="cnewcoverimg" type="file" />
+                <div class="mt-1 text-danger">(建議尺寸/比例: 寬____px * 高____px)</div>
+              </td>
+            </tr>
+            <tr>
+              <td>
+                <h4>封面圖片說明</h4>
+              </td>
+              <td><input class="form-control" id="ccoverimgtxt" type="text" />
+              </td>
+            </tr>
+            <tr>
+              <td>
+                <h4>屋主</h4>
+              </td>
+              <td><input class="form-control" id="chomeowner" type="text" />
               </td>
-              <td><input class="form-control" id="cdate" type="text" /></td>
+            </tr>
+            <tr>
+              <td>
+                <h4>坪數</h4>
+              </td>
+              <td><input class="form-control" id="csize" type="text" />
+              </td>
+            </tr>
+            <tr>
+              <td>
+                <h4>格局</h4>
+              </td>
+              <td><select id="cbednum">
+                  <option value="">格局</option>
+                  <option value="1房">1房</option>
+                  <option value="2房">2房</option>
+                  <option value="3房">3房</option>
+                  <option value="4房以上">4房以上</option>
+                </select></td>
             </tr>
             <tr>
               <td>
                 <h4>類型</h4>
               </td>
               <td><select id="thousetype">
-                  <option value="">類型</option>
-                  <option>大樓</option>
-                  <option>透天</option>                  
+                  <option value="大樓">大樓</option>
+                  <option value="透天">透天</option>                  
                 </select></td>
             </tr>
             <tr>
               <td>
-                <h4>坪數</h4>
+                <h4>設計師</h4>
               </td>
-              <td><input class="form-control" id="tpinsize" type="text" /></td>
+              <td><input class="form-control" id="cdesigner" type="text" /></td>
             </tr>
             <tr>
               <td>
-                <h4>預算</h4>
+                <h4>設計空間</h4>
               </td>
-              <td><input class="form-control" id="tbudget" type="text" /></td>
+              <td><input class="form-control" id="cspace" type="text" /></td>
             </tr>
             <tr>
               <td>
-                <h4>格局</h4>
+                <h4>地點</h4>
               </td>
-              <td><select id="troomscount">
-                  <option value="">格局</option>
-                  <option>1房</option>
-                  <option>2房</option>
-                  <option>3房</option>
-                  <option>4房以上</option>
+              <td><select id="cloc">
+                  <option value="台北">台北</option>
+                  <option value="新北">新北</option>
+                  <option value="基隆">基隆</option>
+                  <option value="桃園">桃園</option>
+                  <option value="新竹">新竹</option>                  
+                  <option value="苗栗">苗栗</option>
+                  <option value="台中">台中</option>
+                  <option value="南投">南投</option>
+                  <option value="彰化">彰化</option>
+                  <option value="雲林">雲林</option>
+                  <option value="嘉義">嘉義</option>
+                  <option value="台南">台南</option>
+                  <option value="高雄">高雄</option>
+                  <option value="屏東">屏東</option>
+                  <option value="宜蘭">宜蘭</option>
+                  <option value="花蓮">花蓮</option>
+                  <option value="台東">台東</option>
+                  <option value="澎湖">澎湖</option>
+                  <option value="金門">金門</option>
+                  <option value="馬祖">馬祖</option>
+                  <option value="其他">其他</option>
                 </select></td>
             </tr>
+            <tr>
+              <td>
+                <h4>預算</h4>
+              </td>
+              <td><input class="form-control" id="cbudget" type="text" /></td>
+            </tr>
+            <tr>
+              <td>
+                <h4>建案名稱</h4>
+              </td>
+              <td><input class="form-control" id="cconstruction" type="text" /></td>
+            </tr>
+            <tr>
+              <td>
+                <h4>作品集圖片集</h4>
+              </td>
+              <td><input class="form-control" id="cnewccollslider" type="text" /></td>
+            </tr>
             <tr>
               <td>
                 <h4>是否顯示</h4>
               </td>
               <td><input id="cdraft" type="checkbox" checked="true" /></td>
             </tr>
+            <tr>
+              <td>
+                <h4>Comment</h4>
+              </td>
+              <td>
+                <input class="form-control" id="cnewcomment" type="file" />
+                <div class="mt-1 text-danger">(建議尺寸/比例: 寬2048px * 高1365px)</div>
+              </td>
+            </tr>
           </tbody>
         </table>
         <div class="d-none">
@@ -215,6 +321,10 @@
           <input id="ccategories" type="text" /><br />
           <input id="ccol1" type="text" /><br />
           <input id="ccol2" type="text" /><br />
+          <input id="ccoverimg" type="text" /><br />
+          <input id="cccollslider" type="text" /><br />
+          <input id="ccomment" type="text" /><br />
+          <input id="cfile" type="text" /><br />
         </div>
       </div>
 

+ 16 - 0
backstage/templates/editorcollection.html

@@ -0,0 +1,16 @@
+{% extends "editor.html" %}
+{% block extras %}
+      <div class="d-none">
+        <input id="ccoverimgtxt" type="text" /><br />
+        <input id="chomeowner" type="text" /><br />
+        <input id="csize" type="text" /><br />
+        <input id="cbednum" type="text" /><br />
+        <input id="cspace" type="text" /><br />
+        <input id="cloc" type="text" /><br />
+        <input id="cbudget" type="text" /><br />
+        <input id="cconstruction" type="text" /><br />
+        <input id="ccollname" type="text" /><br />
+        <input id="ccollslider" type="text" /><br />
+        <input id="ccomment" type="text" /><br />
+      </div>
+{% endblock extras %}

BIN
backstage/upload/title/img/1712ce30be794ac4bbc51bd8724b762e.webp


BIN
backstage/upload/title/img/orig/1712ce30be794ac4bbc51bd8724b762e.JPG


+ 8 - 4
models/contents/routes.py

@@ -149,8 +149,12 @@ class Content(Resource):
 
     def post(self):
         try:
-            file_dir = path.join(
-                _search_dir(request.args.get('url', type=str)), 'index.md')
+            requrl = request.args.get('url', type=str)
+            print(requrl)
+            if "frequently_asked_questions" in requrl:
+                file_dir = path.join(_search_dir(requrl), '_index.md')
+            else:
+                file_dir = path.join(_search_dir(requrl), 'index.md')
             md_content = request.json.get('content')
             with open(file_dir, 'w', encoding="utf-8") as md:
                 md.write(md_content)
@@ -183,7 +187,7 @@ class Content(Resource):
 def upload_img():
     img_data = request.files['image']
     file_dir = _search_dir(request.args.get('url', type=str))
-    print("file_dir 1 is " + file_dir)
+    #print("file_dir 1 is " + file_dir)
     img_dir = path.join(file_dir, 'img/{}'.format(img_data.filename))
     print("img_dir 1 is " + img_dir)
     img_data.save(img_dir)
@@ -193,7 +197,7 @@ def upload_img():
 def upload_img_to_dir():
     img_data = request.files['image']
     file_dir = _search_dir(request.args.get('url', type=str))
-    print("file_dir 2 is " + file_dir)
+    #print("file_dir 2 is " + file_dir)
     img_dir = path.join(file_dir, 'img/{}'.format(request.args.get('filename', type=str)))
     print("img_dir 2 is " + img_dir)
     img_data.save(img_dir)