diff --git a/apps/blog/scripts/build-routes.mjs b/apps/blog/scripts/build-routes.mjs index 735aa7c79..9c62d8aeb 100644 --- a/apps/blog/scripts/build-routes.mjs +++ b/apps/blog/scripts/build-routes.mjs @@ -47,7 +47,7 @@ const constructUrl = (path, lang) => `/${lang}/${path}`; * @returns {Promise} */ async function fetchArticleRoutes(lang, skip = 0, take = 50) { - const url = `${API_BASE_URL}/articles?skip=${skip}&take=${take}`; + const url = `${API_BASE_URL}/articles?skip=${skip}&take=${take}&showHidden`; try { const { data, total } = await fetch(url, { headers: { diff --git a/libs/blog-bff/articles/api/src/lib/api.ts b/libs/blog-bff/articles/api/src/lib/api.ts index dcbc9d84d..a99c4f562 100644 --- a/libs/blog-bff/articles/api/src/lib/api.ts +++ b/libs/blog-bff/articles/api/src/lib/api.ts @@ -38,6 +38,7 @@ app.get('/', async (c) => { featuredImageUrl: articles.imageUrl, readingTime: articles.readingTime, publishDate: articles.publishDate, + hidden: articles.publishDate, author: { slug: authors.slug, name: authors.name, @@ -50,6 +51,7 @@ app.get('/', async (c) => { and( eq(articles.status, ArticleStatus.Publish), eq(articles.language, dbLangMap[c.var.lang]), + ...showHiddenFilter(articles, queryParams.showHidden), ...withCategoryFilters(articles, queryParams.category), ), ) @@ -64,6 +66,7 @@ app.get('/', async (c) => { and( eq(articleCounts.lang, dbLangMap[c.var.lang]), eq(articleCounts.status, ArticleStatus.Publish), + ...showHiddenFilter(articleCounts, queryParams.showHidden), ...withCategoryFilters(articleCounts, queryParams.category), ), ) @@ -140,6 +143,13 @@ app.get('/:id/related', async (c) => { export default app; +function showHiddenFilter( + table: typeof articles | typeof articleCounts, + showHidden?: string, +) { + return showHidden !== undefined ? [] : [eq(table.isHidden, false)]; +} + function withCategoryFilters( table: typeof articles | typeof articleCounts, category?: string, diff --git a/libs/blog-bff/shared/schema/src/lib/schema.ts b/libs/blog-bff/shared/schema/src/lib/schema.ts index 85bfaa0f3..13831a209 100644 --- a/libs/blog-bff/shared/schema/src/lib/schema.ts +++ b/libs/blog-bff/shared/schema/src/lib/schema.ts @@ -74,6 +74,7 @@ export const articles = sqliteTable( .$type() .notNull(), seo: text('seo', { mode: 'json' }).$type(), + isHidden: integer('is_hidden', { mode: 'boolean' }).notNull(), categories: text('categories', { mode: 'json' }) .notNull() .$type(), @@ -100,36 +101,42 @@ export const articles = sqliteTable( uniqueIndex('article_slug_idx').on(table.slug), index('article_guide_covering_idx').on( table.status, + table.isHidden, table.language, table.isGuide, table.publishDate, ), index('article_recommended_covering_idx').on( table.status, + table.isHidden, table.language, table.isRecommended, table.publishDate, ), index('article_news_covering_idx').on( table.status, + table.isHidden, table.language, table.isNews, table.publishDate, ), index('article_in_depth_covering_idx').on( table.status, + table.isHidden, table.language, table.isInDepth, table.publishDate, ), index('article_covering_idx').on( table.status, + table.isHidden, table.language, table.publishDate, ), index('article_author_covering_idx').on( table.authorId, table.status, + table.isHidden, table.language, table.publishDate, ), @@ -145,6 +152,7 @@ export const articleCounts = sqliteTable( isGuide: integer('is_guide', { mode: 'boolean' }).notNull(), isInDepth: integer('is_in_depth', { mode: 'boolean' }).notNull(), isRecommended: integer('is_recommended', { mode: 'boolean' }).notNull(), + isHidden: integer('is_hidden', { mode: 'boolean' }).notNull(), rowCount: integer('row_count').notNull(), }, (table) => [ @@ -155,6 +163,7 @@ export const articleCounts = sqliteTable( table.isGuide, table.isInDepth, table.isRecommended, + table.isHidden, ), ], );