|
@@ -17,7 +17,6 @@ axios.get(contentApiUrl).then(({ data }) => {
|
|
|
blocks = parseMd(content);
|
|
|
aa = new MDParser(content);
|
|
|
editor_block = document.getElementById("editor_block");
|
|
|
- //alert(blocks[0]['text']);
|
|
|
|
|
|
//ul = document.createElement('ul');
|
|
|
//ul.id = "sortable";
|
|
@@ -41,8 +40,6 @@ axios.get(contentApiUrl).then(({ data }) => {
|
|
|
//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 +
|
|
@@ -90,7 +87,6 @@ axios.get(contentApiUrl).then(({ data }) => {
|
|
|
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;
|
|
@@ -136,13 +132,10 @@ axios.get(contentApiUrl).then(({ data }) => {
|
|
|
//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"]) },
|
|
@@ -155,9 +148,7 @@ axios.get(contentApiUrl).then(({ data }) => {
|
|
|
//$("#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",
|
|
@@ -207,54 +198,18 @@ axios.get(contentApiUrl).then(({ data }) => {
|
|
|
//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 articleinfo = frontMatters.join('\n');
|
|
|
var articleinfo = GetMdHeader();
|
|
|
var mdContent = '<div class="container-fluid blog_article p-0">\n\n';
|
|
|
- //var headings = new Array();
|
|
|
|
|
|
for (i = 0; i < outputData.blocks.length; i++) {
|
|
|
var paragraphdata = "";
|
|
|
|
|
|
- //alert(block.type);
|
|
|
block = outputData.blocks[i];
|
|
|
if (block.type == "header") {
|
|
|
mdContent += "## " + block.data.text + "\n";
|
|
@@ -266,11 +221,8 @@ function editorSave() {
|
|
|
mdContent += paragraphdata + "\n\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="img-fluid" alt="' +
|
|
@@ -297,12 +249,9 @@ function editorSave() {
|
|
|
block.data.height +
|
|
|
'"></iframe>\n\n';
|
|
|
} else if (block.type == "table") {
|
|
|
- //alert(tableArrayToHtml(block.data).length);
|
|
|
mdContent += "\n" + tableArrayToHtml(block.data.content) + "\n\n";
|
|
|
- //console.log(tableArrayToHtml(block.data.content));
|
|
|
}
|
|
|
}
|
|
|
- //alert(mdContent);
|
|
|
|
|
|
var mdData = articleinfo + "\n\n" + mdContent;
|
|
|
|
|
@@ -317,51 +266,5 @@ function editorSave() {
|
|
|
.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;
|