Got the blog submission working initially, no tags yet.

I also have it displaying on the blog pages
This commit is contained in:
2025-06-29 21:07:05 -05:00
parent 72367b30d2
commit 0f05b5fea7
4 changed files with 104 additions and 29 deletions
+12 -4
View File
@@ -2,7 +2,7 @@ import Database from 'bun:sqlite';
import { dev } from '$app/environment'; import { dev } from '$app/environment';
// Initialize the database // Initialize the database
const db = new Database('sludge.db', { create: true}); const db = new Database('sludge.db', { create: true });
db.exec(` db.exec(`
CREATE TABLE IF NOT EXISTS users ( CREATE TABLE IF NOT EXISTS users (
@@ -47,8 +47,8 @@ export function get_blag(uri) {
export function create_user(name: string, email: string) { export function create_user(name: string, email: string) {
try { try {
const result = db.query('INSERT INTO users (name, email) VALUES ($name, $email)').get({ $name: name, $email: email });
return { success: true, id: result.lastInsertRowid, name, email }; return { success: true, id: result.lastInsertRowid, name, email };
const result = db.query('INSERT INTO users (name, email) VALUES ($name, $email)').get({$name: name, $email: email});
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return { success: false, error: 'Failed to create user' + (error as Error).message }; return { success: false, error: 'Failed to create user' + (error as Error).message };
@@ -64,6 +64,14 @@ export function get_all_pork() {
} }
export function publish_blog(title, uri, body) {
const result = db.query('INSERT INTO blags (title, uri, body) VALUES ($title, $uri, $body)').get({ $title: title, $uri: uri, $body: body });
console.log(result)
return { success: true, uri }
}
/** /**
* Thread Stuff * Thread Stuff
* *
@@ -76,9 +84,9 @@ export function get_all_threads() {
} }
export function create_thread(title, id, creator){ export function create_thread(title, id, creator) {
db.query('INSERT INTO threads (id, title, progenator) VALUES ($id, $title, $creator)').get({$id: id, $title: title, $creator: creator}) db.query('INSERT INTO threads (id, title, progenator) VALUES ($id, $title, $creator)').get({ $id: id, $title: title, $creator: creator })
return db.query(`CREATE TABLE return db.query(`CREATE TABLE
'${id}' ( '${id}' (
+48 -6
View File
@@ -1,7 +1,8 @@
<script lang="javascript"> <script lang="javascript">
let {data} = $props() let { data } = $props();
let {post} = data let { post } = data;
$inspect('bu', data) import { marked } from "marked";
$inspect("bu", data);
</script> </script>
<svelte:head> <svelte:head>
@@ -11,12 +12,53 @@
<section> <section>
<h1>{post.title}</h1> <h1>{post.title}</h1>
{@html post.body} {@html marked.parse(post.body)}
<span>{post.created_at}</span> <span
>Created @ {new Date(post.created_at).toLocaleString("en-US", {
timeZone: "-10:00", // This is wrong for some reason the SQLite db is recording the wrong time
hour12: false,
})}</span
>
</section> </section>
<style lang="scss"> <style lang="scss">
@use "/src/app.scss" as *;
section { section {
display: flex;
flex-direction: column;
gap: 1rem;
max-width: 60rem;
margin: 0 auto;
:global(h1) {
:global(strong) {
font-family: "Initials";
font-size: 1.5rem;
font-weight: 500;
}
text-align: center;
}
:global(hr) {
color: $green;
}
:global(blockquote) {
background: $green-42;
border-left: 1rem solid $green;
padding: 0.5rem 1rem;
&:before {
color: $orange;
content: open-quote;
font-size: 1.5rem;
line-height: 0.1rem;
vertical-align: -0.9rem;
}
&:p {
display: inline;
}
}
span {
align-self: center;
font-size: 0.75rem;
}
} }
</style> </style>
+5
View File
@@ -1,9 +1,14 @@
export async function load({ }) { export async function load({ }) {
console.log("new blag") console.log("new blag")
} }
import { publish_blog } from "$lib/db"
export const actions = { export const actions = {
default: async ({ cookies, fetch, getClientAddress, locals, params, platform, request, route, setHeaders, url, isDataRequest }) => { default: async ({ cookies, fetch, getClientAddress, locals, params, platform, request, route, setHeaders, url, isDataRequest }) => {
let data = await request.formData(); let data = await request.formData();
console.log(data); console.log(data);
console.log(publish_blog(data.get('title'), data.get('uri'), data.get('body')))
} }
} }
+26 -6
View File
@@ -18,7 +18,7 @@ Regular; hmm double enter gets a new
> It will only line over on width basis I guess that makes sense > It will only line over on width basis I guess that makes sense
`); `);
$inspect("n", value); // $inspect("n", value);
</script> </script>
<svelte:head> <svelte:head>
@@ -30,14 +30,16 @@ Regular; hmm double enter gets a new
<div> <div>
<h1>Editor</h1> <h1>Editor</h1>
<form method="POST"> <form method="POST">
<div>
<label> <label>
<p>Title</p> <p>Title</p>
<input type="text" name="title" /> <input required type="text" name="title" />
</label> </label>
<label> <label>
<p>URI</p> <p>URI</p>
<input type="text" name="uri" /> <input required type="text" name="uri" />
</label> </label>
</div>
<textarea name="body" bind:value></textarea> <textarea name="body" bind:value></textarea>
<button>Post</button> <button>Post</button>
</form> </form>
@@ -52,6 +54,7 @@ Regular; hmm double enter gets a new
<style lang="scss"> <style lang="scss">
@use "/src/app.scss" as *; @use "/src/app.scss" as *;
section { section {
width: 100%; width: 100%;
display: flex; display: flex;
@@ -60,9 +63,15 @@ Regular; hmm double enter gets a new
flex-basis: 45%; flex-basis: 45%;
margin: 0 auto; margin: 0 auto;
form { form {
display: flex;
flex-direction: column;
div {
gap: 1rem;
display: flex;
}
label { label {
display: flex; display: flex;
margin-top: 1rem; margin: 1rem 0;
gap: 1rem; gap: 1rem;
input { input {
background: $green-42; background: $green-42;
@@ -79,11 +88,23 @@ Regular; hmm double enter gets a new
width: 100%; width: 100%;
height: 40rem; height: 40rem;
line-height: 1.5; line-height: 1.5;
border-radius: 5px;
border: 1px solid $green; border: 1px solid $green;
border-radius: 5px;
background: $green-42; background: $green-42;
color: $yellow; color: $yellow;
font-family: "Garamond"; font-family: "Garamond";
&:focus-visible {
outline: none;
}
}
button {
padding: 0.25rem 0.75rem;
margin-top: 1rem;
background-color: $green-42;
color: $yellow;
border: solid 3px $green;
border-radius: 5px;
align-self: center;
} }
} }
} }
@@ -118,4 +139,3 @@ Regular; hmm double enter gets a new
} }
} }
</style> </style>