mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +02:00
feat: add desktop back home button on posts page
This commit is contained in:
parent
b4bd409e4b
commit
cac96eca8c
7 changed files with 54 additions and 16 deletions
|
@ -24,7 +24,8 @@ interface Props {
|
|||
}
|
||||
|
||||
const { postTitle, postDescription, postSlug, supportedLangs = [] } = Astro.props
|
||||
const { isHome, isPost } = getPageInfo(Astro.url.pathname)
|
||||
const { isHome, isPost, getLocalizedPath } = getPageInfo(Astro.url.pathname)
|
||||
const localizedHome = getLocalizedPath('/')
|
||||
const { light: { background: lightMode }, dark: { background: darkMode } } = themeConfig.color
|
||||
const fontStyle = themeConfig.global.fontStyle === 'serif' ? 'font-serif' : 'font-sans'
|
||||
const mobileFooterMargin = isPost && themeConfig.comment?.waline?.serverURL
|
||||
|
@ -149,5 +150,22 @@ const mobileFooterMargin = isPost && themeConfig.comment?.waline?.serverURL
|
|||
document.addEventListener('astro:after-swap', setupThemeToggle)
|
||||
</script>
|
||||
|
||||
<!-- Back home >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
|
||||
<script define:vars={{ localizedHome }}>
|
||||
function setupBackButton() {
|
||||
document.getElementById('back-button')?.addEventListener('click', () => {
|
||||
if (document.referrer) {
|
||||
window.history.back()
|
||||
}
|
||||
else {
|
||||
window.location.href = localizedHome
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
setupBackButton()
|
||||
document.addEventListener('astro:after-swap', setupBackButton)
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue