diff options
| author | Bobby <[email protected]> | 2022-03-21 04:48:28 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-03-21 04:48:28 -0400 |
| commit | ea6e14059d8904c83f16ef65dc30dfde70ca78d8 (patch) | |
| tree | c0630591e6f2f90f7bea4c976d5aef2079c16a51 /public/views/createPost.html | |
| parent | 1a55a855b5e448f2d27065e55ff8bf9900544db5 (diff) | |
| download | luciferreeves.github.io-ea6e14059d8904c83f16ef65dc30dfde70ca78d8.tar.xz luciferreeves.github.io-ea6e14059d8904c83f16ef65dc30dfde70ca78d8.zip | |
force check referer before api request
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 |
