From 56d16d7bf3fdc6f81f98ee754fee97ac5f7f110a Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Sat, 27 Aug 2022 18:51:40 +0300 Subject: [PATCH] added support for draft markdowns --- src/components/SearchInput/SearchInput.tsx | 1 - src/i18n/utils.ts | 2 +- src/pages/[...slug].astro | 16 +++++++++------- src/services/ArticleService.ts | 2 +- src/types/main.d.ts | 1 + 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/SearchInput/SearchInput.tsx b/src/components/SearchInput/SearchInput.tsx index 00e8f16..d535d5e 100644 --- a/src/components/SearchInput/SearchInput.tsx +++ b/src/components/SearchInput/SearchInput.tsx @@ -48,7 +48,6 @@ const SearchInput: Component = (props) => { resetSearch(); return; } - console.log(param); setSearch(param); }); diff --git a/src/i18n/utils.ts b/src/i18n/utils.ts index 8532dc1..0273a25 100644 --- a/src/i18n/utils.ts +++ b/src/i18n/utils.ts @@ -14,7 +14,7 @@ export function formatArticlesByLangs(data: Record [key, key.split("/").slice(6)[0]]); const formatted = formatArticlesByLangs(modules); - return entries.map(([key, lang]) => { - const article = modules[key]; - const dirName = key.split("/").at(-3); - const published_at = new Date(article.frontmatter.published_at).toLocaleDateString("en-CA"); - const slug = `${lang !== DEFAULT_LANGUAGE ? `${lang}/` : ""}blog/${published_at}/${article.frontmatter.slug}`; + return entries + .map(([key, lang]) => { + const article = modules[key]; + const dirName = key.split("/").at(-3); + const published_at = new Date(article.frontmatter.published_at).toLocaleDateString("en-CA"); + const slug = `${lang !== DEFAULT_LANGUAGE ? `${lang}/` : ""}blog/${published_at}/${article.frontmatter.slug}`; - return { params: { slug }, props: { article, alternateLangs: Object.keys(formatted[dirName]) } }; - }); + return { params: { slug }, props: { article, alternateLangs: Object.keys(formatted[dirName]) } }; + }) + .filter(({ props: { article } }) => !article.frontmatter.draft); } const { diff --git a/src/services/ArticleService.ts b/src/services/ArticleService.ts index 8a5bcbc..c6fedbd 100644 --- a/src/services/ArticleService.ts +++ b/src/services/ArticleService.ts @@ -24,7 +24,7 @@ class ArticleService { } } - return articles; + return articles.filter((article) => !article.frontmatter.draft); } } diff --git a/src/types/main.d.ts b/src/types/main.d.ts index 07e13bb..a0fcc75 100644 --- a/src/types/main.d.ts +++ b/src/types/main.d.ts @@ -39,6 +39,7 @@ declare global { tags: Array; published_at: string; lang?: string; + draft?: boolean; }; type ProjectType = {