Skip to content

Commit

Permalink
Fixed relative images not being resolved for instant navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Feb 3, 2024
1 parent bcad9ce commit a7c7110
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion material/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.caa56a14.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.8fd75fb4.min.js' | url }}"></script>
{% for script in config.extra_javascript %}
{{ script | script_tag }}
{% endfor %}
Expand Down
14 changes: 10 additions & 4 deletions src/templates/assets/javascripts/integrations/instant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,22 @@ function head(document: Document): Map<string, HTMLElement> {
/**
* Resolve relative URLs in the given document
*
* This function resolves relative `href` and `src` attributes, which can belong
* to all sorts of tags, like meta tags, links, images, scripts and more.
*
* @param document - Document
*
* @returns Document observable
*/
function resolve(document: Document): Observable<Document> {
for (const el of getElements<HTMLLinkElement>("[href], [src]", document))
for (const key in ["href", "src"]) {
for (const el of getElements("[href], [src]", document))
for (const key of ["href", "src"]) {
const value = el.getAttribute(key)
if (!/^(?:[a-z]+:)?\/\//i.test(value!))
el.href = el.href
if (value && !/^(?:[a-z]+:)?\/\//i.test(value)) {
// @ts-expect-error - trick: self-assign to resolve URL
el[key] = el[key]
break
}
}

// Return document observable
Expand Down

0 comments on commit a7c7110

Please sign in to comment.