Skip to content

Commit 51f373d

Browse files
committed
add media select to editor
1 parent e8217a8 commit 51f373d

File tree

5 files changed

+88
-4
lines changed

5 files changed

+88
-4
lines changed

adminEditor/config.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"coloredCode": "```language\ncode\n```",
1212
"horizontalLine": "---",
1313
"internalLink": "{{< link \"path/to/file\" >}}text{{< /link >}}",
14-
"mediaSelect": "![alt text](/img/blog/image.jpg)"
14+
"mediaSelect": "![alt text](/img/blog/image.jpg)",
15+
"blockquoteSelect": "Github \n Blockquote content"
1516
},
1617
"icons": {
1718
"bold": "bold",
@@ -25,7 +26,8 @@
2526
"coloredCode": "code",
2627
"horizontalLine": "minus",
2728
"internalLink": "file-alt",
28-
"mediaSelect": "photo-video"
29+
"mediaSelect": "photo-video",
30+
"blockquoteSelect": "quote-right"
2931
},
3032
"server": {
3133
"port": 8081,
@@ -40,7 +42,7 @@
4042
},
4143
"thumbnailResize": {
4244
"method": "fit",
43-
"maxWidth": 640
45+
"maxWidth": 1024
4446
}
4547
}
4648
}

adminEditor/static/index.html

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ <h5 class="modal-title" id="mediaSelectModalLabel">Select Media</h5>
5454
</div>
5555
<div class="modal-body">
5656
<select id="mediaFileSelect" class="form-select mb-3"></select>
57+
<input type="file" webkitRelativePath id="fileMediaSelect-select" class="form-control mb-3" placeholder="Select a file from the media folder">
58+
<p id="fileMediaSelect-feedback"></p>
5759
<input type="text" id="newFileName" class="form-control mb-3" placeholder="New file name (without extension)">
5860
<input type="text" id="altText" class="form-control" placeholder="Alt text for image">
5961
</div>
@@ -65,6 +67,33 @@ <h5 class="modal-title" id="mediaSelectModalLabel">Select Media</h5>
6567
</div>
6668
</div>
6769

70+
<div class="modal fade" id="blockquoteModal" tabindex="-1" aria-labelledby="blockquoteModalLabel" aria-hidden="true">
71+
<div class="modal-dialog">
72+
<div class="modal-content">
73+
<div class="modal-header">
74+
<h5 class="modal-title" id="blockquoteModalLabel">Insert Blockqoute Code</h5>
75+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
76+
</div>
77+
<div class="modal-body">
78+
<select id="blockquoteSelect" class="form-select mb-3">
79+
<option value="> [!NOTE]">NOTE</option>
80+
<option value="> [!TIP]">TIP</option>
81+
<option value="> [!IMPORTANT]">IMPORTANT</option>
82+
<option value="> [!WARNING]">WARNING</option>
83+
<option value="> [!CAUTION]">CAUTION</option>
84+
<option value="> ">Only Quote</option>
85+
</select>
86+
<textarea title="blockquoteEditor" id="blockquoteContent" class="form-control" rows="10"></textarea>
87+
</div>
88+
<div class="modal-footer">
89+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
90+
<button type="button" class="btn btn-primary" onclick="insertBlockquoteCode()">Enter</button>
91+
</div>
92+
</div>
93+
</div>
94+
</div>
95+
96+
6897
<!-- Colored Code Dialog -->
6998
<div class="modal fade" id="coloredCodeModal" tabindex="-1" aria-labelledby="coloredCodeModalLabel" aria-hidden="true">
7099
<div class="modal-dialog">
@@ -244,6 +273,9 @@ <h5 class="modal-title" id="internalLinksModalLabel">Insert Internal Link</h5>
244273
case 'internalLink':
245274
showInternalLinksDialog();
246275
break;
276+
case 'blockquoteSelect':
277+
showModal('blockquoteModal');
278+
break;
247279
default:
248280
doc.replaceRange(value, cursor);
249281
}
@@ -262,6 +294,22 @@ <h5 class="modal-title" id="internalLinksModalLabel">Insert Internal Link</h5>
262294
hideModal('coloredCodeModal');
263295
}
264296

297+
function insertBlockquoteCode() {
298+
const blockquote = document.getElementById('blockquoteSelect').value;
299+
const text = document.getElementById('blockquoteContent').value;
300+
const formattedText = blockquote + "\n" + addPrefixToLines(text);
301+
editor.getDoc().replaceSelection(formattedText);
302+
hideModal('blockquoteModal');
303+
}
304+
305+
function addPrefixToLines(text) {
306+
var lines = text.split('\n');
307+
for (var i = 0; i < lines.length; i++) {
308+
lines[i] = "> " + lines[i];
309+
}
310+
return lines.join('\n');
311+
}
312+
265313
function showInternalLinksDialog() {
266314
const select = document.getElementById('internalLinkSelect');
267315
select.innerHTML = '';
@@ -332,6 +380,9 @@ <h5 class="modal-title" id="internalLinksModalLabel">Insert Internal Link</h5>
332380
case 'mediaSelect':
333381
showMediaSelectDialog();
334382
break;
383+
case 'blockquoteSelect':
384+
showModal('blockquoteModal');
385+
break;
335386
default:
336387
doc.replaceRange(value, cursor);
337388
}
@@ -350,12 +401,23 @@ <h5 class="modal-title" id="internalLinksModalLabel">Insert Internal Link</h5>
350401
option.textContent = file;
351402
select.appendChild(option);
352403
});
404+
// TODO change, only for testing now -> create this as example for testing purposes:
405+
var fileName = document.getElementById("file-select").value;
406+
var newFileName = fileName.replace(/\.md$/, '_1'); // Replace .md with 1
407+
document.getElementById("newFileName").defaultValue = newFileName;
408+
document.getElementById("altText").defaultValue = newFileName;
353409
showModal('mediaSelectModal');
354410
});
355411
}
356412

357413
function insertMediaFile() {
358-
const file = document.getElementById('mediaFileSelect').value;
414+
var file = document.getElementById('mediaFileSelect').value;
415+
console.log(file)
416+
const fileMediaSelect = document.getElementById('fileMediaSelect-select').files[0].name;
417+
if(fileMediaSelect != null && fileMediaSelect) {
418+
file = fileMediaSelect;
419+
console.log(file)
420+
}
359421
const newName = document.getElementById('newFileName').value;
360422
const altText = document.getElementById('altText').value;
361423

@@ -374,6 +436,24 @@ <h5 class="modal-title" id="internalLinksModalLabel">Insert Internal Link</h5>
374436
});
375437
}
376438

439+
document.getElementById("fileMediaSelect-select").addEventListener("change", function() {
440+
var fileInput = document.getElementById("fileMediaSelect-select");
441+
var filePath = fileInput.value;
442+
443+
var feedback = document.getElementById("fileMediaSelect-feedback");
444+
445+
// Check if the selected file is in the ./mediaSet folder
446+
// TODO check against the media file list /api/media-list
447+
if (true) {
448+
feedback.textContent = "File selected: " + fileInput.files[0].name;
449+
feedback.style.color = "green";
450+
} else {
451+
feedback.textContent = "Please select a file from the media folder.";
452+
feedback.style.color = "red";
453+
fileInput.value = ""; // Clear the input
454+
}
455+
});
456+
377457
function toggleFullscreen() {
378458
const editorWrapper = editor.getWrapperElement();
379459
if (!document.fullscreenElement) {
@@ -486,6 +566,8 @@ <h5 class="modal-title" id="internalLinksModalLabel">Insert Internal Link</h5>
486566
});
487567
}
488568

569+
570+
489571
function pasteFromClipboard() {
490572
navigator.clipboard.readText()
491573
.then(text => {
Loading

assets/img/blog/thumb_test.jpg

-62.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)