Add categories for docs template

This commit is contained in:
thiloho
2024-08-27 16:39:29 +02:00
parent 0753345bba
commit 1b1767c0f7
24 changed files with 651 additions and 154 deletions

View File

@@ -85,7 +85,6 @@ export const actions: Actions = {
},
body: JSON.stringify({
website_id: params.websiteId,
user_id: locals.user.id,
title: data.get("title")
})
});

View File

@@ -14,6 +14,7 @@
<WebsiteEditor
id={data.website.id}
contentType={data.website.content_type}
title={data.website.title}
previewContent={data.home.main_content}
>

View File

@@ -11,10 +11,22 @@ export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) =
}
});
const categoryData = await fetch(
`${API_BASE_PREFIX}/docs_category?website_id=eq.${params.websiteId}&order=category_weight.desc`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
}
}
);
const article = await articleData.json();
const categories = await categoryData.json();
const { website } = await parent();
return { website, article, API_BASE_PREFIX };
return { website, article, categories, API_BASE_PREFIX };
};
export const actions: Actions = {
@@ -53,7 +65,8 @@ export const actions: Actions = {
meta_author: data.get("author"),
cover_image: uploadedImage.file_id,
publication_date: data.get("publication-date"),
main_content: data.get("main-content")
main_content: data.get("main-content"),
category: data.get("category")
})
});

View File

@@ -30,6 +30,7 @@
<WebsiteEditor
id={data.website.id}
contentType={data.website.content_type}
title={data.website.title}
previewContent={previewContent ||
"Put some markdown content in main content to see a live preview here"}
@@ -50,6 +51,17 @@
};
}}
>
{#if data.website.content_type === "Docs"}
<label>
Category:
<select name="category">
{#each data.categories as { id, category_name }}
<option value={id} selected={id === data.article.category}>{category_name}</option>
{/each}
</select>
</label>
{/if}
<label>
Title:
<input