MCPcopy Create free account
hub / github.com/driangle/taskmd / patchIndexHTML

Function patchIndexHTML

apps/cli/internal/web/export.go:266–285  ·  view source on GitHub ↗

patchIndexHTML injects the fetch interceptor and adjusts paths for static hosting.

(html string, basePath string)

Source from the content-addressed store, hash-verified

264
265// patchIndexHTML injects the fetch interceptor and adjusts paths for static hosting.
266func patchIndexHTML(html string, basePath string) string {
267 // Rewrite absolute asset paths to relative
268 html = strings.ReplaceAll(html, `="/assets/`, `="./assets/`)
269 html = strings.ReplaceAll(html, `="/favicon`, `="./favicon`)
270
271 // Ensure trailing slash on basePath
272 if !strings.HasSuffix(basePath, "/") {
273 basePath += "/"
274 }
275
276 // Always inject <base href> so relative paths resolve from root,
277 // even when served from subdirectory SPA fallbacks like /board/index.html.
278 baseTag := fmt.Sprintf(`<base href="%s">`, basePath)
279 html = strings.Replace(html, "<head>", "<head>\n "+baseTag, 1)
280
281 // Inject fetch interceptor and EventSource stub before </head>
282 html = strings.Replace(html, "</head>", fetchInterceptorScript()+"</head>", 1)
283
284 return html
285}
286
287func fetchInterceptorScript() string {
288 return `<script>

Calls 1

fetchInterceptorScriptFunction · 0.85