Skip to content

Commit 6ba0e80

Browse files
NetdocsCopilot
andcommitted
Don't base_url-prefix external CSS/JS URLs in theme
extraCss/extraJavaScript entries that are absolute URLs (http(s):// or protocol-relative //) were being rewritten as {base_url}{href}, producing broken links like ../../../https://cdn.example.com/x.css. Skip the base_url/asset rewrite for absolute external URLs in head.html and scripts.html, emitting them verbatim. Local asset paths are unchanged. Found while converting a real MkDocs site that references CDN-hosted CSS/JS. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9053be6 commit 6ba0e80

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/Netdocs.Theme.Material/templates/partials/head.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family={{ string.replace font_text ' ' '+' }}:300,300i,400,400i,700,700i%7C{{ string.replace font_code ' ' '+' }}:400,400i,700,700i&display=fallback">
3434
<style>:root{--md-text-font:"{{ font_text }}";--md-code-font:"{{ font_code }}"}</style>
3535
{{~ for href in stylesheets ~}}
36+
{{~ if (string.starts_with href "http") || (string.starts_with href "//") ~}}
37+
<link rel="stylesheet" href="{{ href }}">
38+
{{~ else ~}}
3639
<link rel="stylesheet" href="{{ base_url }}{{ asset href }}">
3740
{{~ end ~}}
41+
{{~ end ~}}
3842
{{~ # Helper functions for inline scripts (palette persistence, search index caching,
3943
# instant navigation). The vendored Material bundle references these globals during
4044
# init; without them it throws `__md_get is not defined`, which aborts the whole

src/Netdocs.Theme.Material/templates/partials/scripts.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030
</script>
3131
<script src="{{ base_url }}assets/vendor/material/javascripts/bundle.d7400e89.min.js"></script>
3232
{{~ for src in scripts ~}}
33+
{{~ if (string.starts_with src "http") || (string.starts_with src "//") ~}}
34+
<script src="{{ src }}" defer></script>
35+
{{~ else ~}}
3336
<script src="{{ base_url }}{{ asset src }}" defer></script>
3437
{{~ end ~}}
38+
{{~ end ~}}
3539
{{~ for js in inline_scripts ~}}
3640
<script>{{ js }}</script>
3741
{{~ end ~}}

0 commit comments

Comments
 (0)