Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/blog/scripts/build-routes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const constructUrl = (path, lang) => `/${lang}/${path}`;
* @returns {Promise<void>}
*/
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: {
Expand Down
10 changes: 10 additions & 0 deletions libs/blog-bff/articles/api/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
),
)
Expand All @@ -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),
),
)
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions libs/blog-bff/shared/schema/src/lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const articles = sqliteTable(
.$type<ArticleTranslation[]>()
.notNull(),
seo: text('seo', { mode: 'json' }).$type<SeoData>(),
isHidden: integer('is_hidden', { mode: 'boolean' }).notNull(),
categories: text('categories', { mode: 'json' })
.notNull()
.$type<string[]>(),
Expand All @@ -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,
),
Expand All @@ -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) => [
Expand All @@ -155,6 +163,7 @@ export const articleCounts = sqliteTable(
table.isGuide,
table.isInDepth,
table.isRecommended,
table.isHidden,
),
],
);