diff options
Diffstat (limited to 'public/views/createPost.html')
| -rw-r--r-- | public/views/createPost.html | 60 |
1 files changed, 1 insertions, 59 deletions
diff --git a/public/views/createPost.html b/public/views/createPost.html index 976c0e5..c205f20 100644 --- a/public/views/createPost.html +++ b/public/views/createPost.html @@ -129,65 +129,7 @@ <script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"></script> - <script> - window.addEventListener("DOMContentLoaded", () => { - const content = document.getElementById('content'); - const renderPreview = document.getElementById('renderPreview'); - marked.setOptions({ - highlight: function (code) { - return hljs.highlightAuto(code).value; - } - }); - content.addEventListener('input', () => { - renderPreview.innerHTML = marked.parse(content.value); - renderMathInElement(renderPreview, { - // customised options - // • auto-render specific keys, e.g.: - delimiters: [ - { left: '$$', right: '$$', display: true }, - { left: '$', right: '$', display: false }, - { left: '\\(', right: '\\)', display: false }, - { left: '\\[', right: '\\]', display: true } - ], - // • rendering keys, e.g.: - throwOnError: false - }); - }); - }); - $(document).on('click', '#publishPost', () => { - document.getElementById('error').classList.add('hidden'); - const content = $('#content').val(); - const title = $('#title').val(); - const publishDate = $('#publishDate').val(); - const slug = title.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, ''); - const tags = $('#tags').val(); - if (title === '' || publishDate === '') { - document.getElementById('error').classList.remove('hidden'); - return; - } else { - // Publish post to api/blog/new - const body = { - title: title, - publishDate: publishDate, - tags: tags, - content: content, - shortText: marked.parse(content.substring(0, 120) + "..."), - slug: slug - }; - $.ajax({ - url: '/api/blog/new', - type: 'POST', - data: body, - success: (data) => { - window.location.href = '/admin/dashboard'; - }, - error: (err) => { - console.log(err); - } - }); - } - }); - </script> + <script src="/static/assets/js/pages/publish.js"></script> </body> </html>
\ No newline at end of file |
