fix(hosting): preview link rewriting prepends storefront base_url
CTA buttons in section macros use short paths like /contact which resolve to site root instead of the storefront path. The preview JS now detects short paths (not starting with /platforms/, /storefront/, etc.) and prepends the store's base_url before adding _preview token. Example: /contact → /platforms/hosting/storefront/batirenovation-strasbourg/contact?_preview=... Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -221,20 +221,30 @@
|
|||||||
</div>
|
</div>
|
||||||
<style>header { margin-top: 48px !important; }</style>
|
<style>header { margin-top: 48px !important; }</style>
|
||||||
<script>
|
<script>
|
||||||
// Propagate preview token to all internal links
|
// Propagate preview token to all internal links (runs repeatedly to catch Alpine-rendered content)
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
(function() {
|
||||||
var params = new URLSearchParams(window.location.search);
|
var params = new URLSearchParams(window.location.search);
|
||||||
var token = params.get('_preview');
|
var token = params.get('_preview');
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
document.querySelectorAll('a[href]').forEach(function(a) {
|
var baseUrl = '{{ base_url | default("/") }}'.replace(/\/$/, '');
|
||||||
var href = a.getAttribute('href');
|
function fixLinks() {
|
||||||
if (href && (href.startsWith('/') || href.startsWith(window.location.origin)) && !href.startsWith('//')) {
|
document.querySelectorAll('a[href]').forEach(function(a) {
|
||||||
|
if (a.dataset.previewFixed) return;
|
||||||
|
var href = a.getAttribute('href');
|
||||||
|
if (!href || href.startsWith('http') || href.startsWith('//') || href.startsWith('#') || href.startsWith('mailto:') || href.startsWith('tel:')) return;
|
||||||
|
// Short paths like /contact from CMS sections → prepend base_url
|
||||||
|
if (href.match(/^\/[a-z]/) && !href.startsWith('/platforms/') && !href.startsWith('/storefront/') && !href.startsWith('/api/') && !href.startsWith('/admin/') && !href.startsWith('/store/')) {
|
||||||
|
href = baseUrl + href;
|
||||||
|
}
|
||||||
var url = new URL(href, window.location.origin);
|
var url = new URL(href, window.location.origin);
|
||||||
url.searchParams.set('_preview', token);
|
url.searchParams.set('_preview', token);
|
||||||
a.setAttribute('href', url.pathname + url.search);
|
a.setAttribute('href', url.pathname + url.search);
|
||||||
}
|
a.dataset.previewFixed = '1';
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
document.addEventListener('DOMContentLoaded', fixLinks);
|
||||||
|
setInterval(fixLinks, 1000);
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user