mirror of
https://github.com/afoim/fuwari.git
synced 2026-01-31 09:03:18 +08:00
refactor(License): 使用内联脚本替换动态URL更新逻辑
移除原有的动态URL更新函数,改为直接在脚本中设置当前URL,简化实现并提高可靠性
This commit is contained in:
@@ -21,9 +21,18 @@ const postUrl = decodeURIComponent(Astro.url.toString());
|
||||
<div class="transition font-bold text-black/75 dark:text-white/75">
|
||||
{title}
|
||||
</div>
|
||||
<a href={postUrl} class="license-url link text-[var(--primary)] opacity-0 transition-opacity">
|
||||
{postUrl}
|
||||
</a>
|
||||
|
||||
<a id="current-link" style="display:none;" class="link text-[var(--primary)]"></a>
|
||||
|
||||
<script>
|
||||
const currentLink = document.getElementById('current-link');
|
||||
const url = window.location.href;
|
||||
|
||||
currentLink.textContent = url; // 显示文本 = 当前 URL
|
||||
currentLink.href = url; // 点击跳转 = 当前 URL
|
||||
currentLink.style.display = 'inline'; // 显示出来
|
||||
</script>
|
||||
|
||||
<div class="flex gap-6 mt-2">
|
||||
<div>
|
||||
<div class="transition text-black/30 dark:text-white/30 text-sm">作者</div>
|
||||
@@ -41,16 +50,4 @@ const postUrl = decodeURIComponent(Astro.url.toString());
|
||||
<Icon name="fa6-brands:creative-commons" class="transition text-[15rem] absolute pointer-events-none right-6 top-1/2 -translate-y-1/2 text-black/5 dark:text-white/5"></Icon>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function updateLicenseUrl() {
|
||||
const links = document.querySelectorAll('.license-url');
|
||||
links.forEach(link => {
|
||||
const url = decodeURIComponent(window.location.href);
|
||||
link.setAttribute('href', url);
|
||||
link.textContent = url;
|
||||
link.classList.remove('opacity-0');
|
||||
});
|
||||
}
|
||||
updateLicenseUrl();
|
||||
document.addEventListener('astro:page-load', updateLicenseUrl);
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user