Skip to content

Commit 51a339c

Browse files
authored
feat: explicitly hide articles (#473)
1 parent 00766ea commit 51a339c

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

apps/blog/scripts/build-routes.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const constructUrl = (path, lang) => `/${lang}/${path}`;
4747
* @returns {Promise<void>}
4848
*/
4949
async function fetchArticleRoutes(lang, skip = 0, take = 50) {
50-
const url = `${API_BASE_URL}/articles?skip=${skip}&take=${take}`;
50+
const url = `${API_BASE_URL}/articles?skip=${skip}&take=${take}&showHidden`;
5151
try {
5252
const { data, total } = await fetch(url, {
5353
headers: {

libs/blog-bff/articles/api/src/lib/api.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ app.get('/', async (c) => {
3838
featuredImageUrl: articles.imageUrl,
3939
readingTime: articles.readingTime,
4040
publishDate: articles.publishDate,
41+
hidden: articles.publishDate,
4142
author: {
4243
slug: authors.slug,
4344
name: authors.name,
@@ -50,6 +51,7 @@ app.get('/', async (c) => {
5051
and(
5152
eq(articles.status, ArticleStatus.Publish),
5253
eq(articles.language, dbLangMap[c.var.lang]),
54+
...showHiddenFilter(articles, queryParams.showHidden),
5355
...withCategoryFilters(articles, queryParams.category),
5456
),
5557
)
@@ -64,6 +66,7 @@ app.get('/', async (c) => {
6466
and(
6567
eq(articleCounts.lang, dbLangMap[c.var.lang]),
6668
eq(articleCounts.status, ArticleStatus.Publish),
69+
...showHiddenFilter(articleCounts, queryParams.showHidden),
6770
...withCategoryFilters(articleCounts, queryParams.category),
6871
),
6972
)
@@ -140,6 +143,13 @@ app.get('/:id/related', async (c) => {
140143

141144
export default app;
142145

146+
function showHiddenFilter(
147+
table: typeof articles | typeof articleCounts,
148+
showHidden?: string,
149+
) {
150+
return showHidden !== undefined ? [] : [eq(table.isHidden, false)];
151+
}
152+
143153
function withCategoryFilters(
144154
table: typeof articles | typeof articleCounts,
145155
category?: string,

libs/blog-bff/shared/schema/src/lib/schema.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const articles = sqliteTable(
7474
.$type<ArticleTranslation[]>()
7575
.notNull(),
7676
seo: text('seo', { mode: 'json' }).$type<SeoData>(),
77+
isHidden: integer('is_hidden', { mode: 'boolean' }).notNull(),
7778
categories: text('categories', { mode: 'json' })
7879
.notNull()
7980
.$type<string[]>(),
@@ -100,36 +101,42 @@ export const articles = sqliteTable(
100101
uniqueIndex('article_slug_idx').on(table.slug),
101102
index('article_guide_covering_idx').on(
102103
table.status,
104+
table.isHidden,
103105
table.language,
104106
table.isGuide,
105107
table.publishDate,
106108
),
107109
index('article_recommended_covering_idx').on(
108110
table.status,
111+
table.isHidden,
109112
table.language,
110113
table.isRecommended,
111114
table.publishDate,
112115
),
113116
index('article_news_covering_idx').on(
114117
table.status,
118+
table.isHidden,
115119
table.language,
116120
table.isNews,
117121
table.publishDate,
118122
),
119123
index('article_in_depth_covering_idx').on(
120124
table.status,
125+
table.isHidden,
121126
table.language,
122127
table.isInDepth,
123128
table.publishDate,
124129
),
125130
index('article_covering_idx').on(
126131
table.status,
132+
table.isHidden,
127133
table.language,
128134
table.publishDate,
129135
),
130136
index('article_author_covering_idx').on(
131137
table.authorId,
132138
table.status,
139+
table.isHidden,
133140
table.language,
134141
table.publishDate,
135142
),
@@ -145,6 +152,7 @@ export const articleCounts = sqliteTable(
145152
isGuide: integer('is_guide', { mode: 'boolean' }).notNull(),
146153
isInDepth: integer('is_in_depth', { mode: 'boolean' }).notNull(),
147154
isRecommended: integer('is_recommended', { mode: 'boolean' }).notNull(),
155+
isHidden: integer('is_hidden', { mode: 'boolean' }).notNull(),
148156
rowCount: integer('row_count').notNull(),
149157
},
150158
(table) => [
@@ -155,6 +163,7 @@ export const articleCounts = sqliteTable(
155163
table.isGuide,
156164
table.isInDepth,
157165
table.isRecommended,
166+
table.isHidden,
158167
),
159168
],
160169
);

0 commit comments

Comments
 (0)