mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Remove unncessary fields from docs templates and add category article order
This commit is contained in:
@@ -136,5 +136,3 @@ FROM
|
|||||||
JOIN internal.home ho ON w.id = ho.website_id
|
JOIN internal.home ho ON w.id = ho.website_id
|
||||||
JOIN internal.footer f ON w.id = f.website_id;
|
JOIN internal.footer f ON w.id = f.website_id;
|
||||||
|
|
||||||
GRANT SELECT ON api.website_overview TO authenticated_user;
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
-- migrate:up
|
||||||
|
CREATE OR REPLACE VIEW api.website_overview WITH ( security_invoker = ON
|
||||||
|
) AS
|
||||||
|
SELECT
|
||||||
|
w.id,
|
||||||
|
w.user_id,
|
||||||
|
w.content_type,
|
||||||
|
w.title,
|
||||||
|
s.accent_color_light_theme,
|
||||||
|
s.accent_color_dark_theme,
|
||||||
|
s.favicon_image,
|
||||||
|
h.logo_type,
|
||||||
|
h.logo_text,
|
||||||
|
h.logo_image,
|
||||||
|
ho.main_content,
|
||||||
|
f.additional_text,
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
JSON_AGG(
|
||||||
|
JSON_BUILD_OBJECT(
|
||||||
|
'id', a.id, 'title', a.title, 'meta_description', a.meta_description, 'meta_author', a.meta_author, 'cover_image', a.cover_image, 'publication_date', a.publication_date, 'main_content', a.main_content, 'created_at', a.created_at, 'last_modified_at', a.last_modified_at
|
||||||
|
)
|
||||||
|
)
|
||||||
|
FROM
|
||||||
|
internal.article a
|
||||||
|
WHERE
|
||||||
|
a.website_id = w.id
|
||||||
|
) AS articles,
|
||||||
|
CASE WHEN w.content_type = 'Docs' THEN
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
JSON_OBJECT_AGG(
|
||||||
|
COALESCE(
|
||||||
|
category_name, 'Uncategorized'
|
||||||
|
), articles
|
||||||
|
)
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
dc.category_name,
|
||||||
|
dc.category_weight AS category_weight,
|
||||||
|
JSON_AGG(
|
||||||
|
JSON_BUILD_OBJECT(
|
||||||
|
'id', a.id, 'title', a.title, 'meta_description', a.meta_description, 'meta_author', a.meta_author, 'cover_image', a.cover_image, 'publication_date', a.publication_date, 'main_content', a.main_content, 'created_at', a.created_at, 'last_modified_at', a.last_modified_at
|
||||||
|
) ORDER BY a.article_weight DESC NULLS LAST
|
||||||
|
) AS articles
|
||||||
|
FROM
|
||||||
|
internal.article a
|
||||||
|
LEFT JOIN internal.docs_category dc ON a.category = dc.id
|
||||||
|
WHERE
|
||||||
|
a.website_id = w.id
|
||||||
|
GROUP BY
|
||||||
|
dc.id,
|
||||||
|
dc.category_name,
|
||||||
|
dc.category_weight
|
||||||
|
ORDER BY
|
||||||
|
category_weight DESC NULLS LAST
|
||||||
|
) AS categorized_articles)
|
||||||
|
ELSE
|
||||||
|
NULL
|
||||||
|
END AS categorized_articles
|
||||||
|
FROM
|
||||||
|
internal.website w
|
||||||
|
JOIN internal.settings s ON w.id = s.website_id
|
||||||
|
JOIN internal.header h ON w.id = h.website_id
|
||||||
|
JOIN internal.home ho ON w.id = ho.website_id
|
||||||
|
JOIN internal.footer f ON w.id = f.website_id;
|
||||||
|
|
||||||
|
GRANT SELECT ON api.website_overview TO authenticated_user;
|
||||||
|
|
||||||
|
-- migrate:down
|
||||||
|
DROP VIEW api.website_overview;
|
||||||
|
|
||||||
|
CREATE VIEW api.website_overview WITH ( security_invoker = ON
|
||||||
|
) AS
|
||||||
|
SELECT
|
||||||
|
w.id,
|
||||||
|
w.user_id,
|
||||||
|
w.content_type,
|
||||||
|
w.title,
|
||||||
|
s.accent_color_light_theme,
|
||||||
|
s.accent_color_dark_theme,
|
||||||
|
s.favicon_image,
|
||||||
|
h.logo_type,
|
||||||
|
h.logo_text,
|
||||||
|
h.logo_image,
|
||||||
|
ho.main_content,
|
||||||
|
f.additional_text,
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
JSON_AGG(
|
||||||
|
JSON_BUILD_OBJECT(
|
||||||
|
'id', a.id, 'title', a.title, 'meta_description', a.meta_description, 'meta_author', a.meta_author, 'cover_image', a.cover_image, 'publication_date', a.publication_date, 'main_content', a.main_content, 'created_at', a.created_at, 'last_modified_at', a.last_modified_at
|
||||||
|
)
|
||||||
|
)
|
||||||
|
FROM
|
||||||
|
internal.article a
|
||||||
|
WHERE
|
||||||
|
a.website_id = w.id
|
||||||
|
) AS articles,
|
||||||
|
CASE WHEN w.content_type = 'Docs' THEN
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
JSON_OBJECT_AGG(
|
||||||
|
COALESCE(
|
||||||
|
category_name, 'Uncategorized'
|
||||||
|
), articles
|
||||||
|
)
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
dc.category_name,
|
||||||
|
dc.category_weight AS category_weight,
|
||||||
|
JSON_AGG(
|
||||||
|
JSON_BUILD_OBJECT(
|
||||||
|
'id', a.id, 'title', a.title, 'meta_description', a.meta_description, 'meta_author', a.meta_author, 'cover_image', a.cover_image, 'publication_date', a.publication_date, 'main_content', a.main_content, 'created_at', a.created_at, 'last_modified_at', a.last_modified_at
|
||||||
|
)
|
||||||
|
) AS articles
|
||||||
|
FROM
|
||||||
|
internal.article a
|
||||||
|
LEFT JOIN internal.docs_category dc ON a.category = dc.id
|
||||||
|
WHERE
|
||||||
|
a.website_id = w.id
|
||||||
|
GROUP BY
|
||||||
|
dc.id,
|
||||||
|
dc.category_name,
|
||||||
|
dc.category_weight
|
||||||
|
ORDER BY
|
||||||
|
category_weight DESC NULLS LAST
|
||||||
|
) AS categorized_articles)
|
||||||
|
ELSE
|
||||||
|
NULL
|
||||||
|
END AS categorized_articles
|
||||||
|
FROM
|
||||||
|
internal.website w
|
||||||
|
JOIN internal.settings s ON w.id = s.website_id
|
||||||
|
JOIN internal.header h ON w.id = h.website_id
|
||||||
|
JOIN internal.home ho ON w.id = ho.website_id
|
||||||
|
JOIN internal.footer f ON w.id = f.website_id;
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<nav>
|
<nav>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{#if isDocsTemplate}
|
{#if isDocsTemplate && Object.keys(categorizedArticles).length > 0}
|
||||||
<input type="checkbox" id="toggle-sidebar" hidden />
|
<input type="checkbox" id="toggle-sidebar" hidden />
|
||||||
<label for="toggle-sidebar">
|
<label for="toggle-sidebar">
|
||||||
<svg
|
<svg
|
||||||
|
|||||||
@@ -10,8 +10,6 @@
|
|||||||
logo,
|
logo,
|
||||||
mainContent,
|
mainContent,
|
||||||
categorizedArticles,
|
categorizedArticles,
|
||||||
coverImage,
|
|
||||||
publicationDate,
|
|
||||||
footerAdditionalText
|
footerAdditionalText
|
||||||
}: {
|
}: {
|
||||||
favicon: string;
|
favicon: string;
|
||||||
@@ -20,8 +18,6 @@
|
|||||||
logo: string;
|
logo: string;
|
||||||
mainContent: string;
|
mainContent: string;
|
||||||
categorizedArticles: { [key: string]: { title: string }[] };
|
categorizedArticles: { [key: string]: { title: string }[] };
|
||||||
coverImage: string;
|
|
||||||
publicationDate: string;
|
|
||||||
footerAdditionalText: string;
|
footerAdditionalText: string;
|
||||||
} = $props();
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
@@ -32,13 +28,7 @@
|
|||||||
|
|
||||||
<header>
|
<header>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<hgroup>
|
|
||||||
<p>{publicationDate}</p>
|
|
||||||
<h1>{title}</h1>
|
<h1>{title}</h1>
|
||||||
</hgroup>
|
|
||||||
{#if coverImage}
|
|
||||||
<img src={coverImage} alt="" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
logoType,
|
logoType,
|
||||||
logo,
|
logo,
|
||||||
mainContent,
|
mainContent,
|
||||||
articles,
|
|
||||||
categorizedArticles,
|
categorizedArticles,
|
||||||
footerAdditionalText
|
footerAdditionalText
|
||||||
}: {
|
}: {
|
||||||
@@ -18,7 +17,6 @@
|
|||||||
logoType: "text" | "image";
|
logoType: "text" | "image";
|
||||||
logo: string;
|
logo: string;
|
||||||
mainContent: string;
|
mainContent: string;
|
||||||
articles: { title: string; publication_date: string; meta_description: string }[];
|
|
||||||
categorizedArticles: { [key: string]: { title: string }[] };
|
categorizedArticles: { [key: string]: { title: string }[] };
|
||||||
footerAdditionalText: string;
|
footerAdditionalText: string;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent
|
|||||||
let baseFetchUrl = `${API_BASE_PREFIX}/article?website_id=eq.${params.websiteId}&select=id,title`;
|
let baseFetchUrl = `${API_BASE_PREFIX}/article?website_id=eq.${params.websiteId}&select=id,title`;
|
||||||
if (website.content_type === "Docs") {
|
if (website.content_type === "Docs") {
|
||||||
baseFetchUrl +=
|
baseFetchUrl +=
|
||||||
",docs_category(category_name,category_weight)&order=docs_category(category_weight).desc.nullslast,article_weight.desc.nullslast";
|
",article_weight,docs_category(category_name,category_weight)&order=docs_category(category_weight).desc.nullslast,article_weight.desc.nullslast";
|
||||||
}
|
}
|
||||||
|
|
||||||
const parameters = new URLSearchParams();
|
const parameters = new URLSearchParams();
|
||||||
|
|||||||
@@ -76,10 +76,10 @@
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<ul class="unpadded">
|
<ul class="unpadded">
|
||||||
{#each data.articles as { id, title, docs_category } (id)}
|
{#each data.articles as { id, title, article_weight, docs_category } (id)}
|
||||||
<li class="article-card">
|
<li class="article-card">
|
||||||
<p>
|
<p>
|
||||||
<strong>{title}</strong>
|
<strong>{title} {article_weight ? `(${article_weight})` : ""}</strong>
|
||||||
{#if docs_category?.category_name}
|
{#if docs_category?.category_name}
|
||||||
<br />
|
<br />
|
||||||
<small>
|
<small>
|
||||||
|
|||||||
@@ -95,10 +95,18 @@
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
{#if data.website.content_type === "Blog"}
|
||||||
<label>
|
<label>
|
||||||
Publication date:
|
Publication date:
|
||||||
<input type="date" name="publication-date" value={data.article.publication_date} required />
|
<input
|
||||||
|
type="date"
|
||||||
|
name="publication-date"
|
||||||
|
value={data.article.publication_date}
|
||||||
|
required
|
||||||
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="file-field">
|
<div class="file-field">
|
||||||
<label>
|
<label>
|
||||||
Cover image:
|
Cover image:
|
||||||
@@ -113,6 +121,8 @@
|
|||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
Main content:
|
Main content:
|
||||||
<textarea
|
<textarea
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
|||||||
? websiteData.logo_text
|
? websiteData.logo_text
|
||||||
: `${API_BASE_PREFIX}/rpc/retrieve_file?id=${websiteData.logo_image}`,
|
: `${API_BASE_PREFIX}/rpc/retrieve_file?id=${websiteData.logo_image}`,
|
||||||
mainContent: md(websiteData.main_content ?? "", false),
|
mainContent: md(websiteData.main_content ?? "", false),
|
||||||
articles: websiteData.articles ?? [],
|
|
||||||
categorizedArticles: websiteData.categorized_articles ?? [],
|
categorizedArticles: websiteData.categorized_articles ?? [],
|
||||||
footerAdditionalText: md(websiteData.additional_text ?? "")
|
footerAdditionalText: md(websiteData.additional_text ?? "")
|
||||||
}
|
}
|
||||||
@@ -165,10 +164,6 @@ const generateStaticFiles = async (websiteData: any, isPreview: boolean = true)
|
|||||||
websiteData.logo_type === "text"
|
websiteData.logo_type === "text"
|
||||||
? websiteData.logo_text
|
? websiteData.logo_text
|
||||||
: `${API_BASE_PREFIX}/rpc/retrieve_file?id=${websiteData.logo_image}`,
|
: `${API_BASE_PREFIX}/rpc/retrieve_file?id=${websiteData.logo_image}`,
|
||||||
coverImage: article.cover_image
|
|
||||||
? `${API_BASE_PREFIX}/rpc/retrieve_file?id=${article.cover_image}`
|
|
||||||
: "",
|
|
||||||
publicationDate: article.publication_date,
|
|
||||||
mainContent: md(article.main_content ?? ""),
|
mainContent: md(article.main_content ?? ""),
|
||||||
categorizedArticles: websiteData.categorized_articles ?? [],
|
categorizedArticles: websiteData.categorized_articles ?? [],
|
||||||
footerAdditionalText: md(websiteData.additional_text ?? "")
|
footerAdditionalText: md(websiteData.additional_text ?? "")
|
||||||
|
|||||||
Reference in New Issue
Block a user