diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index fefb43c..a838e6c 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -15,10 +15,13 @@ >
{data.blog.site.name} -
+
{#if data.blog.site.use_about_page} About {/if} + {#if data.blog.site.use_contact_page} + Contact + {/if}
diff --git a/src/routes/contact/+page.server.js b/src/routes/contact/+page.server.js new file mode 100644 index 0000000..b0b34ad --- /dev/null +++ b/src/routes/contact/+page.server.js @@ -0,0 +1,47 @@ +import { redirect } from "@sveltejs/kit"; +import { get } from 'svelte/store'; +import { site_id } from '../store'; +import { env } from '$lib'; + +/** @type {import("@sveltejs/kit").Actions} */ +export const actions = { + contact: async (event) => { + const data = await event.request.formData(); + + const subject = data.get("subject"); + const email = data.get("email"); + const message = data.get("message"); + + if (!subject || !email || !message) { + return { + success: false, + message: "missing data" + } + } + + if (!email.toString().includes("@")) { + return { + success: false, + message: "invalid email" + } + } + + let res = await fetch(env.api_url + "/blog/contact", { + method: "POST", + headers: { + "content-type": "application/json" + }, + body: JSON.stringify({ + subject, + email, + content: message, + blog_id: get(site_id) + }) + }); + console.log(await res.text()); + + return { + success: true + } + }, +} \ No newline at end of file diff --git a/src/routes/contact/+page.svelte b/src/routes/contact/+page.svelte new file mode 100644 index 0000000..22684ac --- /dev/null +++ b/src/routes/contact/+page.svelte @@ -0,0 +1,28 @@ +
+
+ + +