MCPcopy
hub / github.com/TanStack/router / addCrawlPageTask

Function addCrawlPageTask

packages/start-plugin-core/src/prerender.ts:156–282  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

154 return Array.from(prerendered)
155
156 function addCrawlPageTask(page: Page) {
157 // Was the page already seen?
158 if (seen.has(page.path)) return
159
160 // Add the page to the seen set
161 seen.add(page.path)
162
163 if (page.fromCrawl) {
164 startConfig.pages.push(page)
165 }
166
167 // If not enabled, skip
168 if (!(page.prerender?.enabled ?? true)) return
169
170 // If there is a filter link, check if the page should be prerendered
171 if (startConfig.prerender?.filter && !startConfig.prerender.filter(page))
172 return
173
174 // Resolve the merged default and page-specific prerender options
175 const prerenderOptions = {
176 ...startConfig.prerender,
177 ...page.prerender,
178 }
179
180 // Add the task
181 queue.add(async () => {
182 logger.info(`Crawling: ${page.path}`)
183 const retries = retriesByPath.get(page.path) || 0
184 try {
185 // Fetch the route
186
187 const res = await localFetch(
188 withTrailingSlash(withBase(page.path, routerBasePath)),
189 {
190 headers: {
191 ...(prerenderOptions.headers ?? {}),
192 },
193 },
194 prerenderOptions.maxRedirects,
195 )
196
197 if (!res.ok) {
198 if (isRedirectResponse(res)) {
199 logger.warn(`Max redirects reached for ${page.path}`)
200 }
201 throw new Error(`Failed to fetch ${page.path}: ${res.statusText}`, {
202 cause: res,
203 })
204 }
205
206 const cleanPagePath = (
207 prerenderOptions.outputPath || page.path
208 ).split(/[?#]/)[0]!
209
210 // Guess route type and populate fileName
211 const contentType = res.headers.get('content-type') || ''
212 const isImplicitHTML =
213 !cleanPagePath.endsWith('.html') && contentType.includes('html')

Callers 1

prerenderPagesFunction · 0.85

Calls 14

localFetchFunction · 0.85
isRedirectResponseFunction · 0.85
extractLinksFunction · 0.85
addMethod · 0.80
filterMethod · 0.80
endsWithMethod · 0.80
includesMethod · 0.80
onSuccessMethod · 0.80
infoMethod · 0.65
getMethod · 0.65
warnMethod · 0.65
textMethod · 0.65

Tested by

no test coverage detected