mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 02:41:35 +01:00
Add categories to docs article list
This commit is contained in:
@@ -6,9 +6,16 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent
|
||||
const sortBy = url.searchParams.get("article_sort");
|
||||
const filterBy = url.searchParams.get("article_filter");
|
||||
|
||||
const parameters = new URLSearchParams();
|
||||
const { website, home } = await parent();
|
||||
|
||||
const 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`;
|
||||
let docsSortString = "";
|
||||
if (website.content_type === "Docs") {
|
||||
baseFetchUrl += ",docs_category(category_name,category_weight)";
|
||||
docsSortString = "docs_category(category_weight).desc,";
|
||||
}
|
||||
|
||||
const parameters = new URLSearchParams();
|
||||
|
||||
if (searchQuery) {
|
||||
parameters.append("title_description_search", `wfts(english).${searchQuery}`);
|
||||
@@ -17,16 +24,16 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent
|
||||
switch (sortBy) {
|
||||
case null:
|
||||
case "creation-time":
|
||||
parameters.append("order", "created_at.desc");
|
||||
parameters.append("order", `${docsSortString}created_at.desc`);
|
||||
break;
|
||||
case "last-modified":
|
||||
parameters.append("order", "last_modified_at.desc");
|
||||
parameters.append("order", `${docsSortString}last_modified_at.desc`);
|
||||
break;
|
||||
case "title-a-to-z":
|
||||
parameters.append("order", "title.asc");
|
||||
parameters.append("order", `${docsSortString}title.asc`);
|
||||
break;
|
||||
case "title-z-to-a":
|
||||
parameters.append("order", "title.desc");
|
||||
parameters.append("order", `${docsSortString}title.desc`);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -63,7 +70,6 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent
|
||||
});
|
||||
|
||||
const articles = await articlesData.json();
|
||||
const { website, home } = await parent();
|
||||
|
||||
return {
|
||||
totalArticleCount,
|
||||
|
||||
@@ -86,10 +86,31 @@
|
||||
</details>
|
||||
|
||||
<ul class="unpadded">
|
||||
{#each data.articles as { id, title } (id)}
|
||||
{#each data.articles as { id, title, docs_category } (id)}
|
||||
<li class="article-card">
|
||||
<p>
|
||||
<strong>{title}</strong>
|
||||
{#if docs_category?.category_name}
|
||||
<br />
|
||||
<small>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 16 16"
|
||||
fill="currentColor"
|
||||
width="16"
|
||||
height="16"
|
||||
style="vertical-align: middle"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M4.5 2A2.5 2.5 0 0 0 2 4.5v2.879a2.5 2.5 0 0 0 .732 1.767l4.5 4.5a2.5 2.5 0 0 0 3.536 0l2.878-2.878a2.5 2.5 0 0 0 0-3.536l-4.5-4.5A2.5 2.5 0 0 0 7.38 2H4.5ZM5 6a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
|
||||
clip-rule="evenodd"
|
||||
></path>
|
||||
</svg>
|
||||
|
||||
{docs_category.category_name}
|
||||
</small>
|
||||
{/if}
|
||||
</p>
|
||||
|
||||
<div class="article-card__actions">
|
||||
|
||||
Reference in New Issue
Block a user