mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +02:00
feat: integrate PhotoSwipe lightbox, enhance scrollbar functionality, and update layout components
- Added a new PhotoSwipe component for image lightbox functionality in the layout. - Enhanced scrollbar component with an auto-hide delay feature. - Updated global styles to improve scrollbar appearance and added styles for PhotoSwipe. - Included new Head layout component for better SEO and meta tag management. - Added images to existing posts for improved visual content. This commit improves user experience with enhanced image viewing and layout consistency.
This commit is contained in:
parent
ac9e839a75
commit
1af92d92c8
10 changed files with 131 additions and 51 deletions
52
src/components/PhotoSwipe.astro
Normal file
52
src/components/PhotoSwipe.astro
Normal file
|
@ -0,0 +1,52 @@
|
|||
<script>
|
||||
import PhotoSwipeLightbox from 'photoswipe/lightbox'
|
||||
import 'photoswipe/style.css'
|
||||
|
||||
// Store lightbox instance for later use
|
||||
let lightbox: PhotoSwipeLightbox | null = null
|
||||
const pswp = import('photoswipe')
|
||||
|
||||
// Initialize PhotoSwipe lightbox with custom configuration
|
||||
function createPhotoSwipe() {
|
||||
lightbox = new PhotoSwipeLightbox({
|
||||
gallery: 'article img',
|
||||
pswpModule: () => pswp,
|
||||
closeSVG: '<svg xmlns="http://www.w3.org/2000/svg" height="2.4rem" viewBox="0 -960 960 960" width="3.8rem" fill="#A0A09F"><path d="M480-424 284-228q-11 11-28 11t-28-11q-11-11-11-28t11-28l196-196-196-196q-11-11-11-28t11-28q11-11 28-11t28 11l196 196 196-196q11-11 28-11t28 11q11 11 11 28t-11 28L536-480l196 196q11 11 11 28t-11 28q-11 11-28 11t-28-11L480-424Z"/></svg>',
|
||||
zoomSVG: '<svg xmlns="http://www.w3.org/2000/svg" height="2.4rem" viewBox="0 -960 960 960" width="3.8rem" fill="#A0A09F"><path d="M340-540h-40q-17 0-28.5-11.5T260-580q0-17 11.5-28.5T300-620h40v-40q0-17 11.5-28.5T380-700q17 0 28.5 11.5T420-660v40h40q17 0 28.5 11.5T500-580q0 17-11.5 28.5T460-540h-40v40q0 17-11.5 28.5T380-460q-17 0-28.5-11.5T340-500v-40Zm40 220q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l224 224q11 11 11 28t-11 28q-11 11-28 11t-28-11L532-372q-30 24-69 38t-83 14Zm0-80q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z"/></svg>',
|
||||
wheelToZoom: true,
|
||||
arrowPrev: false,
|
||||
arrowNext: false,
|
||||
imageClickAction: 'close',
|
||||
tapAction: 'close',
|
||||
doubleTapAction: 'zoom',
|
||||
})
|
||||
|
||||
// Add custom filter to handle image data and dimensions
|
||||
lightbox.addFilter('domItemData', (itemData: any, element: Element) => {
|
||||
if (element instanceof HTMLImageElement) {
|
||||
itemData.src = element.src
|
||||
itemData.w = Number(element.naturalWidth || window.innerWidth)
|
||||
itemData.h = Number(element.naturalHeight || window.innerHeight)
|
||||
itemData.msrc = element.src
|
||||
}
|
||||
return itemData
|
||||
})
|
||||
|
||||
lightbox.init()
|
||||
}
|
||||
|
||||
// Cleanup function to destroy lightbox instance
|
||||
function cleanup() {
|
||||
if (lightbox) {
|
||||
lightbox.destroy()
|
||||
lightbox = null
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize PhotoSwipe when DOM is ready
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
createPhotoSwipe()
|
||||
})
|
||||
|
||||
document.addEventListener('astro:before-swap', cleanup)
|
||||
</script>
|
|
@ -14,6 +14,7 @@ function initScrollbar() {
|
|||
scrollbars: {
|
||||
theme: document.documentElement.classList.contains('dark') ? 'scrollbar-dark' : 'scrollbar-light',
|
||||
autoHide: 'scroll',
|
||||
autoHideDelay: 800,
|
||||
},
|
||||
overflow: {
|
||||
x: 'hidden',
|
||||
|
|
|
@ -4,6 +4,8 @@ published: 1977-07-18
|
|||
tags: ["鲁迅"]
|
||||
---
|
||||
|
||||

|
||||
|
||||
我冒了严寒,回到相隔二千余里,别了二十余年的故乡去。
|
||||
|
||||
时候既然是深冬;渐近故乡时,天气又阴晦了,冷风吹进船舱中,呜呜的响,从蓬隙向外一望,苍黄的天底下,远近横着几个萧索的荒村,没有一些活气。我的心禁不住悲凉起来了。
|
||||
|
|
|
@ -4,6 +4,8 @@ published: 1984-09-17
|
|||
tags: ["黑泽明"]
|
||||
---
|
||||
|
||||

|
||||
|
||||
一天,天色已晚。 仆人纪宁正在罗生门下等待雨停。
|
||||
|
||||
除了他,宽大的门下空无一人。 只有一只蟋蟀栖息在一根大柱子上,柱子上有的地方已经脱漆。 罗生门位于铃作大寺街上,除了这个人之外,应该还有两三个人,包括避雨的一笠和搓着乌鸦帽的真江吉。 但是,除了这个人之外,一个人也没有。
|
||||
|
|
|
@ -15,6 +15,7 @@ const { verification = {}, twitterID = '', facebookID = '', facebookLink = '', g
|
|||
const { google = '', bing = '', yandex = '', baidu = '' } = verification
|
||||
const { cdn, commentURL = '', imageHostURL = '', customGoogleAnalyticsURL = '', customUmamiAnalyticsURL = '', customUmamiAnalyticsJS = '' } = themeConfig.preload
|
||||
---
|
||||
<head>
|
||||
<!-- Basic -->
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
@ -142,3 +143,4 @@ const { cdn, commentURL = '', imageHostURL = '', customGoogleAnalyticsURL = '',
|
|||
/>
|
||||
)
|
||||
}
|
||||
</head>
|
|
@ -1,9 +1,11 @@
|
|||
---
|
||||
import Head from '@/components/Head.astro'
|
||||
import PhotoSwipe from '@/components/PhotoSwipe.astro'
|
||||
import Scrollbar from '@/components/Scrollbar.astro'
|
||||
import ThemeToggle from '@/components/ThemeToggle.astro'
|
||||
import themeConfig from '@/config'
|
||||
import Head from '@/layouts/Head.astro'
|
||||
import '@/styles/global.css'
|
||||
import '@/styles/photoswipe.css'
|
||||
|
||||
interface Props {
|
||||
postTitle?: string
|
||||
|
@ -22,9 +24,7 @@ const colorMode = themeConfig.color.mode
|
|||
class:list={[fontStyle, colorMode]}
|
||||
data-overlayscrollbars-initialize
|
||||
>
|
||||
<head>
|
||||
<Head {postTitle} {postDescription} {postImage} />
|
||||
</head>
|
||||
<Head {postTitle} {postDescription} {postImage} />
|
||||
<body data-overlayscrollbars-initialize>
|
||||
<ThemeToggle />
|
||||
<main
|
||||
|
@ -34,5 +34,6 @@ const colorMode = themeConfig.color.mode
|
|||
<slot />
|
||||
</main>
|
||||
<Scrollbar />
|
||||
<PhotoSwipe />
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -7,7 +7,7 @@ html {
|
|||
--at-apply: 'scroll-smooth antialiased text-62.5%';
|
||||
}
|
||||
body {
|
||||
--at-apply: 'bg-background text-secondary text-1.6rem';
|
||||
--at-apply: 'bg-background c-secondary text-1.6rem';
|
||||
}
|
||||
@supports not (view-transition-name: none) {
|
||||
body {
|
||||
|
@ -17,30 +17,33 @@ body {
|
|||
* {
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
}
|
||||
*::-webkit-scrollbar {
|
||||
display: none;
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
h1, h2, h3 {
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
h1 {
|
||||
--at-apply: 'text-[3.6rem]';
|
||||
--at-apply: 'text-3.6rem';
|
||||
}
|
||||
h2 {
|
||||
--at-apply: 'text-[3rem]';
|
||||
--at-apply: 'text-3rem';
|
||||
}
|
||||
h3 {
|
||||
--at-apply: 'text-[2.4rem]';
|
||||
--at-apply: 'text-2.4rem';
|
||||
}
|
||||
h4 {
|
||||
--at-apply: 'text-[2rem]';
|
||||
--at-apply: 'text-2rem';
|
||||
}
|
||||
h5 {
|
||||
--at-apply: 'text-[1.8rem]';
|
||||
--at-apply: 'text-1.8rem';
|
||||
}
|
||||
h6 {
|
||||
--at-apply: 'text-[1.6rem]';
|
||||
--at-apply: 'text-1.6rem';
|
||||
}
|
||||
article img {
|
||||
cursor: zoom-in;
|
||||
}
|
||||
/* Horizontal reveal animation on theme toggle */
|
||||
@keyframes reveal {
|
||||
|
@ -64,4 +67,4 @@ html:not(.dark) {
|
|||
transition: none;
|
||||
animation: none;
|
||||
z-index: -1;
|
||||
}
|
||||
}
|
17
src/styles/photoswipe.css
Normal file
17
src/styles/photoswipe.css
Normal file
|
@ -0,0 +1,17 @@
|
|||
.pswp__button {
|
||||
--at-apply: 'flex items-center justify-center transition';
|
||||
}
|
||||
.pswp__button--zoom,
|
||||
.pswp__button--close {
|
||||
--at-apply: 'mt-2 lg:mt-4 active:scale-90';
|
||||
}
|
||||
.pswp__button--zoom svg:hover,
|
||||
.pswp__button--close svg:hover {
|
||||
fill: #BEBEBE;
|
||||
}
|
||||
.pswp__button--close {
|
||||
--at-apply: 'mr-4 lg:mr-8';
|
||||
}
|
||||
.pswp__button--zoom {
|
||||
--at-apply: 'mr--6 lg:mr-0';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue