|
@@ -53,27 +53,9 @@ function getHeader(url) {
|
|
|
//const content = _.get(data, '0.content', '');
|
|
|
blocks = parseMd(aa);
|
|
|
oTitle = $("#ctitle").val();
|
|
|
- //console.log($("#ctype").val());
|
|
|
// $("#dialog-form").dialog();
|
|
|
if ($("#ctype").val() == "collection") {
|
|
|
$("#scat").hide();
|
|
|
- console.log($("#ctype").val());
|
|
|
- // editorslider = 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(),
|
|
|
- // },
|
|
|
- // },
|
|
|
- // },
|
|
|
- // },
|
|
|
- // });
|
|
|
} else if (
|
|
|
$("#ctype").val() == "maincategories" ||
|
|
|
$("#ctype").val() == "blog"
|
|
@@ -87,9 +69,6 @@ function getHeader(url) {
|
|
|
ParseProductSection(contentMatters.join(""));
|
|
|
}
|
|
|
$("#myModal").modal();
|
|
|
-
|
|
|
- //console.log(frontMatters);
|
|
|
- //alert($('#cimage').val());
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -144,13 +123,14 @@ function writeMd() {
|
|
|
mdContent += contentMatters.join("\n");
|
|
|
var formData = new FormData();
|
|
|
var imagefile = document.querySelector("#cfile");
|
|
|
- //alert("The type is " + $('#ctype').val());
|
|
|
if ($("#ctype").val() == "collection") {
|
|
|
var imagefil2 = document.querySelector("#cnewcoverimg");
|
|
|
var imagefil3 = document.querySelector("#cnewcomment");
|
|
|
+
|
|
|
formData.append("image1", imagefile.files[0]);
|
|
|
formData.append("image2", imagefil2.files[0]);
|
|
|
formData.append("image3", imagefil3.files[0]);
|
|
|
+
|
|
|
axios
|
|
|
.post("/backstage/multiupload/title", formData, {
|
|
|
headers: {
|
|
@@ -158,13 +138,9 @@ function writeMd() {
|
|
|
},
|
|
|
})
|
|
|
.then(({ data }) => {
|
|
|
- //$('#ccomment').val("");
|
|
|
- console.log(data);
|
|
|
+ console.log("data", data);
|
|
|
if (data.success == "1") {
|
|
|
var imglinks = data.fileurl.split(";;;");
|
|
|
- //mdContent = mdContent.replace($('#ccomment').val(), '/img/title/' + data.filelink.substring(data.file.url.lastIndexOf('/') + 1));
|
|
|
- console.log(imglinks);
|
|
|
- console.log(imagefile, imagefil2, imagefil3);
|
|
|
mdContent = mdContent.replace(
|
|
|
$("#cfile").val(),
|
|
|
"/img/title/" + imglinks[0]
|
|
@@ -180,13 +156,12 @@ function writeMd() {
|
|
|
} else {
|
|
|
console.log("skipped");
|
|
|
}
|
|
|
- // try split(";;;")
|
|
|
|
|
|
postData = {
|
|
|
content: mdContent,
|
|
|
url: editTarget,
|
|
|
};
|
|
|
- //console.log(mdContent);
|
|
|
+
|
|
|
axios
|
|
|
.post(contentApiUrl + editTarget, (json = postData))
|
|
|
.then(({ data }) => {});
|
|
@@ -204,7 +179,6 @@ function writeMd() {
|
|
|
},
|
|
|
})
|
|
|
.then(({ data }) => {
|
|
|
- //alert($('#cfile').val());
|
|
|
if (data.success == "1") {
|
|
|
mdContent = mdContent.replace(
|
|
|
$("#cfile").val(),
|
|
@@ -217,7 +191,6 @@ function writeMd() {
|
|
|
content: mdContent,
|
|
|
url: editTarget,
|
|
|
};
|
|
|
- //console.log(mdContent);
|
|
|
axios
|
|
|
.post(contentApiUrl + editTarget, (json = postData))
|
|
|
.then(({ data }) => {});
|
|
@@ -229,7 +202,7 @@ function writeMd() {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-// md的內容解出來
|
|
|
+// md 的內容解出來
|
|
|
function parseMd(content) {
|
|
|
//var frontMatters = [];
|
|
|
var blockCount;
|
|
@@ -253,51 +226,39 @@ function parseMd(content) {
|
|
|
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());
|
|
|
}
|
|
|
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("cover_img: ")) {
|
|
|
+ $("#ccoverimg").val(
|
|
|
+ line.replace("cover_img: ", "").replaceAll('"', "")
|
|
|
+ );
|
|
|
+ }
|
|
|
if (line.includes("meta_description: ")) {
|
|
|
- //alert(line);
|
|
|
$("#cmetadsc").val(
|
|
|
line.replace("meta_description: ", "").replaceAll('"', "")
|
|
|
);
|
|
|
} else if (line.includes("collection_description: ")) {
|
|
|
- //collections
|
|
|
- //alert(line);
|
|
|
$("#ccolldesc").val(
|
|
|
line
|
|
|
.replace("collection_description: ", "")
|
|
@@ -311,23 +272,18 @@ function parseMd(content) {
|
|
|
.replaceAll('"', "")
|
|
|
.replaceAll("<br>", "\r\n")
|
|
|
);
|
|
|
- //console.log($('#cdescription').val());
|
|
|
}
|
|
|
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;
|
|
@@ -337,7 +293,6 @@ function parseMd(content) {
|
|
|
}
|
|
|
}
|
|
|
if (line.includes("categories: ")) {
|
|
|
- //alert(line);
|
|
|
$("#ccategories").val(
|
|
|
line
|
|
|
.replace("categories: ", "")
|
|
@@ -346,22 +301,15 @@ function parseMd(content) {
|
|
|
.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('"', ""));
|
|
|
}
|
|
|
|
|
|
//for blogs
|
|
|
if (line.includes("introduction: ")) {
|
|
|
- //alert(line);
|
|
|
$("#cintroduction").val(
|
|
|
line
|
|
|
.replace("introduction: ", "")
|
|
@@ -370,7 +318,6 @@ function parseMd(content) {
|
|
|
);
|
|
|
}
|
|
|
if (line.includes("question_box_intro: ")) {
|
|
|
- //alert(line);
|
|
|
$("#cquestionboxintro").val(
|
|
|
line.replace("question_box_intro: ", "").replaceAll('"', "")
|
|
|
);
|
|
@@ -378,65 +325,54 @@ function parseMd(content) {
|
|
|
|
|
|
//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);
|
|
|
$("#chousetype").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('"', "")
|
|
|
);
|
|
@@ -451,24 +387,18 @@ function parseMd(content) {
|
|
|
let left = slider[0].value.lastIndexOf("[");
|
|
|
let right = slider[0].value.lastIndexOf("]");
|
|
|
let stringList = slider[0].value.substr(left + 1, right - 1);
|
|
|
-
|
|
|
- console.log("stringList", stringList);
|
|
|
-
|
|
|
let stringArr = stringList.split(",");
|
|
|
- console.log("stringArr", stringArr);
|
|
|
-
|
|
|
let imgArr = [];
|
|
|
let textArr = [];
|
|
|
+
|
|
|
// 擷取字串後存入陣列
|
|
|
stringArr.map((e) => {
|
|
|
if (e.includes("slide_img")) {
|
|
|
e = e.substr(11);
|
|
|
imgArr.push(e);
|
|
|
- console.log("if slide_img :", e);
|
|
|
} else {
|
|
|
e = e.substr(11);
|
|
|
e = e.substring(0, e.length - 1);
|
|
|
- console.log("else slide_text :", e);
|
|
|
textArr.push(e);
|
|
|
}
|
|
|
});
|
|
@@ -478,15 +408,13 @@ function parseMd(content) {
|
|
|
for (let index = 0; index < imgArr.length; index++) {
|
|
|
const element = imgArr[index];
|
|
|
captionValue = textArr[index];
|
|
|
-
|
|
|
+
|
|
|
tmpsrcImg =
|
|
|
BHOUSE_SERVER +
|
|
|
JSON.parse(document.getElementById("url").textContent).url +
|
|
|
"/" +
|
|
|
element;
|
|
|
-
|
|
|
- console.log("tmpsrcImg", tmpsrcImg);
|
|
|
-
|
|
|
+
|
|
|
editorBlocks1.push({
|
|
|
type: "image",
|
|
|
data: {
|
|
@@ -497,15 +425,12 @@ function parseMd(content) {
|
|
|
},
|
|
|
});
|
|
|
}
|
|
|
- console.log("imgArr", imgArr);
|
|
|
- console.log("textArr", textArr);
|
|
|
}
|
|
|
//$('#ccollslider').val(line.replace('collection_slider: ', '').replaceAll('\"', ''));
|
|
|
}
|
|
|
|
|
|
if (line.includes("comment: ")) {
|
|
|
- //alert(line);
|
|
|
- //$('#ccomment').val(line.replace('comment: ', '').replaceAll('\"', ''));
|
|
|
+ $("#ccomment").val(line.replace("comment: ", "").replaceAll('"', ""));
|
|
|
}
|
|
|
|
|
|
// back to normal
|
|
@@ -515,10 +440,6 @@ function parseMd(content) {
|
|
|
continue;
|
|
|
}
|
|
|
contentMatters.push(line);
|
|
|
- /* if (line.toString().trim() == "") {
|
|
|
- rblocks.push({ 'type': 'br', 'text': line });
|
|
|
- continue;
|
|
|
- } */
|
|
|
|
|
|
if (line.includes("---")) {
|
|
|
rblocks.push({ type: "mt5", text: line });
|
|
@@ -575,7 +496,7 @@ function parseMd(content) {
|
|
|
console.log("Empty paragraph -- skipped.");
|
|
|
}
|
|
|
}
|
|
|
- console.log(frontMatters);
|
|
|
+ console.log("frontMatters", frontMatters);
|
|
|
return rblocks;
|
|
|
}
|
|
|
|
|
@@ -662,11 +583,10 @@ function GetMdHeader(result = []) {
|
|
|
let collection_slider_value = result.filter((e) =>
|
|
|
e.match("collection_slider")
|
|
|
);
|
|
|
- console.log("collection_slider_value", collection_slider_value);
|
|
|
rContent += `${collection_slider_value[0]}\n`;
|
|
|
}
|
|
|
|
|
|
- console.log(rContent);
|
|
|
+ console.log("rContent", rContent);
|
|
|
} else if (
|
|
|
$("#ctype").val() == "blog" ||
|
|
|
$("#ctype").val() == "maincategories"
|
|
@@ -691,11 +611,8 @@ function GetMdHeader(result = []) {
|
|
|
$("#cintroduction").val().replace(/\r?\n/g, "<br>") +
|
|
|
'"\n';
|
|
|
rContent += 'question_box_intro: "' + $("#cquestionboxintro").val() + '"\n';
|
|
|
- console.log($("#cdescription").val());
|
|
|
}
|
|
|
rContent += "---\n";
|
|
|
- //alert(rContent);
|
|
|
- // rContent.replaceAll('"',"'"); # replace " with '' (two single quotes)
|
|
|
|
|
|
return rContent;
|
|
|
}
|
|
@@ -755,7 +672,6 @@ function tableArrayToHtml(tableArray) {
|
|
|
}
|
|
|
tbl.appendChild(tr);
|
|
|
}
|
|
|
- //alert(tbl.outerHTML.toString());
|
|
|
return tbl.outerHTML.toString();
|
|
|
}
|
|
|
|
|
@@ -789,7 +705,6 @@ function ParseProductSection(inContent) {
|
|
|
for (i = 0; i < imgnodes.length; i++) {
|
|
|
var tmpsrc, tmpw, tmph, ampimg;
|
|
|
if (imgnodes[i].nodeName == "IMG") {
|
|
|
- //alert(imgnodes[i].nodeName);
|
|
|
ampimg = imgnodes[i].outerHTML;
|
|
|
tmpsrc = ampimg.substr(
|
|
|
ampimg.indexOf('src="') + 5,
|
|
@@ -797,7 +712,6 @@ function ParseProductSection(inContent) {
|
|
|
ampimg.indexOf('src="') -
|
|
|
5
|
|
|
);
|
|
|
- //alert(tmpsrc);
|
|
|
tmpw = ampimg.substr(
|
|
|
ampimg.indexOf('width="') + 7,
|
|
|
ampimg.indexOf('"', ampimg.indexOf('width="') + 7) -
|
|
@@ -839,7 +753,6 @@ function ParseProductSection(inContent) {
|
|
|
} */
|
|
|
//editor.api.blocks.render(editorBlocks);
|
|
|
$("#editorjs")[0].innerHTML = "";
|
|
|
- //alert(editorBlocks);
|
|
|
editor = new EditorJS({
|
|
|
readOnly: false,
|
|
|
holder: "editorjs",
|
|
@@ -857,19 +770,16 @@ function ParseProductSection(inContent) {
|
|
|
},
|
|
|
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());
|
|
|
}
|
|
|
});
|
|
@@ -884,7 +794,6 @@ function ParseProductSection(inContent) {
|
|
|
.replaceAll("</b>", "")
|
|
|
);
|
|
|
}
|
|
|
- //alert(editorBlocks);
|
|
|
//其他
|
|
|
$("#swfPrice").val("");
|
|
|
$("#swfColor").val("");
|
|
@@ -911,7 +820,6 @@ function ParseProductSection(inContent) {
|
|
|
$("#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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -919,7 +827,6 @@ function ParseProductSection(inContent) {
|
|
|
//處理規格圖片
|
|
|
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") {
|
|
@@ -1099,12 +1006,9 @@ function GenProductSection(mimg, specimg) {
|
|
|
firstimg = true;
|
|
|
for (i = 0; i < mimg.blocks.length; i++) {
|
|
|
block = mimg.blocks[i];
|
|
|
- console.log(block.data);
|
|
|
|
|
|
- console.log(block.data.file.url);
|
|
|
if (block.type == "image") {
|
|
|
iurl = block.data.file.url.split("/");
|
|
|
- console.log("img/" + iurl[iurl.length - 1]);
|
|
|
|
|
|
if (iurl[iurl.length - 1] != "logo2.png") {
|
|
|
if (firstimg) {
|
|
@@ -1126,7 +1030,6 @@ function GenProductSection(mimg, specimg) {
|
|
|
|
|
|
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("/");
|
|
@@ -1155,7 +1058,6 @@ function GenProductSection(mimg, specimg) {
|
|
|
|
|
|
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("/");
|
|
@@ -1194,8 +1096,5 @@ class MDParser {
|
|
|
this.description = "";
|
|
|
this.weight = 1;
|
|
|
this.tag = [];
|
|
|
- for (var line of MDtext.split("\n")) {
|
|
|
- //console.log(line);
|
|
|
- }
|
|
|
}
|
|
|
}
|