MCPcopy Create free account
hub / github.com/TanStack/router / addCrawlPageTask

Function addCrawlPageTask

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

Source from the content-addressed store, hash-verified

109 return Array.from(prerendered)
110
111 function addCrawlPageTask(page: Page) {
112 if (seen.has(page.path)) return
113
114 seen.add(page.path)
115
116 if (page.fromCrawl) {
117 startConfig.pages.push(page)
118 }
119
120 if (!(page.prerender?.enabled ?? true)) return
121
122 if (
123 startConfig.prerender?.filter &&
124 !startConfig.prerender.filter(page)
125 ) {
126 return
127 }
128
129 const prerenderOptions = {
130 ...startConfig.prerender,
131 ...page.prerender,
132 }
133
134 queue.add(async () => {
135 logger.info(`Crawling: ${page.path}`)
136 const retries = retriesByPath.get(page.path) || 0
137
138 try {
139 const res = await requestWithRedirects(
140 withTrailingSlash(withBase(page.path, routerBasePath)),
141 {
142 headers: {
143 ...(prerenderOptions.headers ?? {}),
144 },
145 },
146 prerenderOptions.maxRedirects,
147 )
148
149 if (!res.ok) {
150 if (isRedirectResponse(res)) {
151 logger.warn(`Max redirects reached for ${page.path}`)
152 }
153
154 throw new Error(`Failed to fetch ${page.path}: ${res.statusText}`, {
155 cause: res,
156 })
157 }
158
159 const cleanPagePath = (
160 prerenderOptions.outputPath || page.path
161 ).split(/[?#]/)[0]!
162
163 const contentType = res.headers.get('content-type') || ''
164 const isImplicitHTML =
165 !cleanPagePath.endsWith('.html') && contentType.includes('html')
166
167 const routeWithIndex = cleanPagePath.endsWith('/')
168 ? cleanPagePath + 'index'

Callers 1

prerenderPagesFunction · 0.85

Calls 13

requestWithRedirectsFunction · 0.85
isRedirectResponseFunction · 0.85
extractLinksFunction · 0.85
normalizeRetryDelayFunction · 0.85
addMethod · 0.80
filterMethod · 0.80
onSuccessMethod · 0.80
infoMethod · 0.65
getMethod · 0.65
warnMethod · 0.65
textMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected