-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+
server/api/__sitemap__/urls.ts
to fetch all threads id of each forum
+ exported type `ApiForumThreadsID` @ api/types.ts * set sitemap url sources and enable multiple sitemaps @ nuxt.config.ts * fix nuxt/nuxt#23101 (comment) @ server/tsconfig.json @ fe * fix `CursorPaginator->nextCursor()` might return null when it's the last page * rename variable `primaryKey` to `cursorKey & `paginators` to `paginator` @ `App\Http\ControllersThreadsIDQuery->query()` * move class `App\Http\Controllers\Topic\BilibiliVote` to `App\Http\BilibiliVoteQuery` for preventing duplicated class name with `App\Eloquent\Model\BilibiliVote` * change the default value of config `session.driver` from `database` to `file` @ config/session.php @ be
- Loading branch information
Showing
7 changed files
with
48 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { ApiForumThreadsID, ApiForums } from '@/api/types'; | ||
import type { Tid } from '@/utils'; | ||
|
||
export default defineSitemapEventHandler(async event => { | ||
const baseUrlWithDomain = useSiteConfig(event).url; | ||
const endpointPrefix = useRuntimeConfig().public.apiEndpointPrefix; | ||
const fetchOptions = { | ||
headers: { | ||
Accept: 'application/json', | ||
Authorization: event.headers.get('Authorization') ?? '' | ||
} | ||
}; | ||
const forums = await $fetch<ApiForums['response']>(`${endpointPrefix}/forums`, fetchOptions); | ||
|
||
return (await Promise.all(forums.map(async ({ fid }) => { | ||
const tids: Tid[] = []; | ||
let hasMore = true; | ||
let cursor = 0; | ||
while (hasMore) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const threads = await $fetch<ApiForumThreadsID['response']>( | ||
`${endpointPrefix}/forums/${fid}/threads/tid`, | ||
{ query: { cursor }, ...fetchOptions } | ||
); | ||
tids.push(...threads.tid); | ||
hasMore = threads.pages.nextCursor !== null; | ||
cursor = threads.pages.nextCursor ?? Infinity; | ||
} | ||
|
||
return tids.map(tid => asSitemapUrl({ loc: `${baseUrlWithDomain}/posts/tid/${tid}` })); | ||
}))).flat(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extends": "../.nuxt/tsconfig.server.json" | ||
"extends": "../../.nuxt/tsconfig.server.json" | ||
} |