mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 19:01:35 +01:00
Add categories for docs template
This commit is contained in:
@@ -7,7 +7,7 @@ import { render } from "svelte/server";
|
||||
import BlogIndex from "$lib/templates/blog/BlogIndex.svelte";
|
||||
import BlogArticle from "$lib/templates/blog/BlogArticle.svelte";
|
||||
import DocsIndex from "$lib/templates/docs/DocsIndex.svelte";
|
||||
import DocsEntry from "$lib/templates/docs/DocsEntry.svelte";
|
||||
import DocsArticle from "$lib/templates/docs/DocsArticle.svelte";
|
||||
import { dev } from "$app/environment";
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch, cookies, parent }) => {
|
||||
@@ -38,10 +38,20 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, parent }) =
|
||||
};
|
||||
|
||||
export const actions: Actions = {
|
||||
publishWebsite: async ({ request }) => {
|
||||
const data = await request.formData();
|
||||
const websiteOverview = JSON.parse(data.get("website-overview") as string);
|
||||
publishWebsite: async ({ fetch, params, cookies }) => {
|
||||
const websiteOverviewData = await fetch(
|
||||
`${API_BASE_PREFIX}/website_overview?id=eq.${params.websiteId}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`,
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const websiteOverview = await websiteOverviewData.json();
|
||||
generateStaticFiles(websiteOverview, false);
|
||||
|
||||
return { success: true, message: "Successfully published website" };
|
||||
@@ -77,9 +87,15 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
||||
{
|
||||
({ head, body } = render(DocsIndex, {
|
||||
props: {
|
||||
favicon: websiteData.favicon_image
|
||||
? `${API_BASE_PREFIX}/rpc/retrieve_file?id=${websiteData.favicon_image}`
|
||||
: "",
|
||||
title: websiteData.title,
|
||||
logoType: websiteData.logo_type,
|
||||
logo: websiteData.logo_text,
|
||||
logo:
|
||||
websiteData.logo_type === "text"
|
||||
? websiteData.logo_text
|
||||
: `${API_BASE_PREFIX}/rpc/retrieve_file?id=${websiteData.logo_image}`,
|
||||
mainContent: md(websiteData.main_content ?? "", false),
|
||||
articles: websiteData.articles ?? [],
|
||||
footerAdditionalText: md(websiteData.additional_text ?? "")
|
||||
@@ -101,7 +117,7 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
||||
|
||||
await mkdir(uploadDir, { recursive: true });
|
||||
await writeFile(join(uploadDir, "index.html"), indexFileContents);
|
||||
await mkdir(join(uploadDir, websiteData.content_type === "Blog" ? "articles" : "documents"), {
|
||||
await mkdir(join(uploadDir, "articles"), {
|
||||
recursive: true
|
||||
});
|
||||
|
||||
@@ -137,11 +153,17 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
||||
break;
|
||||
case "Docs":
|
||||
{
|
||||
({ head, body } = render(DocsEntry, {
|
||||
({ head, body } = render(DocsArticle, {
|
||||
props: {
|
||||
favicon: websiteData.favicon_image
|
||||
? `${API_BASE_PREFIX}/rpc/retrieve_file?id=${websiteData.favicon_image}`
|
||||
: "",
|
||||
title: article.title,
|
||||
logoType: websiteData.logo_type,
|
||||
logo: websiteData.logo_text,
|
||||
logo:
|
||||
websiteData.logo_type === "text"
|
||||
? websiteData.logo_text
|
||||
: `${API_BASE_PREFIX}/rpc/retrieve_file?id=${websiteData.logo_image}`,
|
||||
coverImage: article.cover_image
|
||||
? `${API_BASE_PREFIX}/rpc/retrieve_file?id=${article.cover_image}`
|
||||
: "",
|
||||
@@ -156,22 +178,18 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
||||
|
||||
const articleFileContents = head.concat(body);
|
||||
|
||||
await writeFile(
|
||||
join(
|
||||
uploadDir,
|
||||
websiteData.content_type === "Blog" ? "articles" : "documents",
|
||||
`${articleFileName}.html`
|
||||
),
|
||||
articleFileContents
|
||||
);
|
||||
await writeFile(join(uploadDir, "articles", `${articleFileName}.html`), articleFileContents);
|
||||
}
|
||||
|
||||
const commonStyles = await readFile(`${process.cwd()}/template-styles/common-styles.css`, {
|
||||
encoding: "utf-8"
|
||||
});
|
||||
const specificStyles = await readFile(`${process.cwd()}/template-styles/blog-styles.css`, {
|
||||
encoding: "utf-8"
|
||||
});
|
||||
const specificStyles = await readFile(
|
||||
`${process.cwd()}/template-styles/${websiteData.content_type.toLowerCase()}-styles.css`,
|
||||
{
|
||||
encoding: "utf-8"
|
||||
}
|
||||
);
|
||||
await writeFile(
|
||||
join(uploadDir, "styles.css"),
|
||||
commonStyles
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
<WebsiteEditor
|
||||
id={data.website.id}
|
||||
contentType={data.website.content_type}
|
||||
title={data.website.title}
|
||||
previewContent={data.websitePreviewUrl}
|
||||
fullPreview={true}
|
||||
@@ -19,15 +20,13 @@
|
||||
<h2>
|
||||
<a href="#publish-website">Publish website</a>
|
||||
</h2>
|
||||
|
||||
{JSON.stringify(data.websiteOverview.articles)}
|
||||
<p>
|
||||
The preview area on this page allows you to see exactly how your website will look when it is
|
||||
is published. If you are happy with the results, click the button below and your website will
|
||||
be published on the Internet.
|
||||
</p>
|
||||
|
||||
<form method="POST" action="?/publishWebsite" use:enhance>
|
||||
<input type="hidden" name="website-overview" value={JSON.stringify(data.websiteOverview)} />
|
||||
<button type="submit">Publish</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user