Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vcci-news-frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Văn Hoàng
vcci-news-frontend
Commits
fb919ebc
Commit
fb919ebc
authored
Oct 27, 2026
by
Phạm Quang Bảo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: build sitemap
parent
d67fb27c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
15 deletions
+29
-15
sitemap.ts
src/app/sitemap.ts
+29
-15
No files found.
src/app/sitemap.ts
View file @
fb919ebc
...
@@ -61,31 +61,45 @@ type PagedRows<T> = {
...
@@ -61,31 +61,45 @@ type PagedRows<T> = {
};
};
};
};
const
fetchAllNewsPosts
=
async
():
Promise
<
PostRow
[]
>
=>
{
// Chia nhỏ request để tránh nginx trả 504 khi lấy quá nhiều bản ghi một lúc
const
pageSize
=
5000
;
const
POST_PAGE_SIZE
=
500
;
const
maxPages
=
20
;
const
POST_MAX_PAGES
=
100
;
// đủ cho 50.000 bài viết
const
all
:
PostRow
[]
=
[];
const
POST_PAGE_RETRIES
=
3
;
const
RETRY_DELAY_MS
=
1500
;
for
(
let
page
=
1
;
page
<=
maxPages
;
page
++
)
{
const
sleep
=
(
ms
:
number
)
=>
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
ms
));
const
fetchPostPage
=
async
(
page
:
number
):
Promise
<
PagedRows
<
PostRow
>
|
null
>
=>
{
for
(
let
attempt
=
1
;
attempt
<=
POST_PAGE_RETRIES
;
attempt
++
)
{
try
{
try
{
const
response
=
(
await
getApiV10Post
({
return
(
await
getApiV10Post
({
page
,
page
,
pageSize
,
pageSize
:
POST_PAGE_SIZE
,
sortField
:
"published_at"
,
sortField
:
"published_at"
,
sortOrder
:
"desc"
,
sortOrder
:
"desc"
,
filters
:
"is_hidden==false,is_active==true,type==news"
,
filters
:
"is_hidden==false,is_active==true,type==news"
,
}))
as
unknown
as
PagedRows
<
PostRow
>
;
}))
as
unknown
as
PagedRows
<
PostRow
>
;
const
rows
=
response
?.
responseData
?.
rows
??
[];
all
.
push
(...
rows
);
const
count
=
Number
(
response
?.
responseData
?.
count
??
0
);
if
(
rows
.
length
<
pageSize
||
all
.
length
>=
count
)
break
;
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
warn
(
"[sitemap] Failed to fetch posts page"
,
page
,
error
);
console
.
warn
(
`[sitemap] Failed to fetch posts page
${
page
}
(attempt
${
attempt
}
/
${
POST_PAGE_RETRIES
}
)`
,
error
);
break
;
if
(
attempt
<
POST_PAGE_RETRIES
)
await
sleep
(
RETRY_DELAY_MS
)
;
}
}
}
}
return
null
;
};
const
fetchAllNewsPosts
=
async
():
Promise
<
PostRow
[]
>
=>
{
const
all
:
PostRow
[]
=
[];
for
(
let
page
=
1
;
page
<=
POST_MAX_PAGES
;
page
++
)
{
const
response
=
await
fetchPostPage
(
page
);
if
(
!
response
)
break
;
const
rows
=
response
?.
responseData
?.
rows
??
[];
all
.
push
(...
rows
);
const
count
=
Number
(
response
?.
responseData
?.
count
??
0
);
if
(
rows
.
length
<
POST_PAGE_SIZE
||
(
count
>
0
&&
all
.
length
>=
count
))
break
;
}
return
all
;
return
all
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment