[READ-ONLY] Mirror of https://github.com/mrgnw/editable-cv.
0

Configure Feed

Select the types of activity you want to include in your feed.

editable-cv / src / routes / blog / new / +page.svelte
1.7 kB 58 lines
1<script> 2 import EditorToolbar from '$lib/components/EditorToolbar.svelte'; 3 import { extractTeaser, fetchJSON } from '$lib/util'; 4 import WebsiteNav from '$lib/components/WebsiteNav.svelte'; 5 import { goto } from '$app/navigation'; 6 import Footer from '$lib/components/Footer.svelte'; 7 import EditableWebsiteTeaser from '$lib/components/EditableWebsiteTeaser.svelte'; 8 import Article from '$lib/components/Article.svelte'; 9 import NotEditable from '$lib/components/NotEditable.svelte'; 10 11 export let data; 12 13 let showUserMenu = false, 14 editable = true, 15 title = 'Untitled', 16 content = 'Copy and paste your text here.'; 17 18 $: currentUser = data.currentUser; 19 20 async function createArticle() { 21 if (!currentUser) { 22 return alert('Sorry, you are not authorized to create new articles.'); 23 } 24 const teaser = extractTeaser(document.getElementById('article_content')); 25 try { 26 const { slug } = await fetchJSON('POST', '/api/create-article', { 27 title, 28 content, 29 teaser 30 }); 31 goto(`/blog/${slug}`); 32 } catch (err) { 33 console.error(err); 34 alert('A document with that title has already been published. Choose a different title.'); 35 } 36 } 37 38 async function discardDraft() { 39 goto('/blog'); 40 } 41</script> 42 43<svelte:head> 44 <title>New blog post</title> 45</svelte:head> 46 47{#if editable} 48 <EditorToolbar {currentUser} on:cancel={discardDraft} on:save={createArticle} /> 49{/if} 50 51<WebsiteNav bind:editable bind:showUserMenu {currentUser} /> 52<Article bind:title bind:content {editable} /> 53 54<NotEditable {editable}> 55 <EditableWebsiteTeaser /> 56</NotEditable> 57 58<Footer {editable} />