From 8c363ac9254bbd6dcc6a25837a221d528b1cedfe Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 17 Aug 2022 21:31:41 +0100 Subject: [PATCH] feat: editor tags input --- src/models/page.model.ts | 9 ++++++++- src/pages/dashboard/[subdomain]/editor.tsx | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/models/page.model.ts b/src/models/page.model.ts index d92be27f..0ee11c3a 100644 --- a/src/models/page.model.ts +++ b/src/models/page.model.ts @@ -42,6 +42,7 @@ export async function createOrUpdatePage(input: { pageId?: string siteId: string slug?: string + tags?: string title?: string content?: string published?: boolean @@ -77,7 +78,13 @@ export async function createOrUpdatePage(input: { mime_type: "text/markdown", }, }), - tags: [input.isPost ? "post" : "page"], + tags: [ + input.isPost ? "post" : "page", + ...(input.tags + ?.split(",") + .map((tag) => tag.trim()) + .filter((tag) => tag) || []), + ], applications: ["xlog"], ...(input.slug && { attributes: [ diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index 6dd1f60d..45d244fe 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -59,6 +59,7 @@ export default function SubdomainEditor() { published: false, excerpt: "", slug: "", + tags: "", }) const [content, setContent] = useState("") @@ -149,6 +150,10 @@ export default function SubdomainEditor() { page.data.date_published !== new Date("9999-01-01").toISOString(), excerpt: page.data.summary?.content || "", slug: page.data.slug!, + tags: + page.data.tags + ?.filter((tag) => tag !== "post" && tag !== "page") + ?.join(", ") || "", }) }, [page.data]) @@ -242,7 +247,6 @@ export default function SubdomainEditor() { label="Page slug" id="slug" isBlock - placeholder="some-slug" onChange={(e: ChangeEvent) => updateValue("slug", e.target.value) } @@ -266,6 +270,19 @@ export default function SubdomainEditor() { } /> +
+ ) => + updateValue("tags", e.target.value) + } + help="Separate multiple tags with commas" + /> +