Skip to content

Commit 7d4a788

Browse files
committed
Replaced bespoke Swiper and Leaflet integration with Astro Swiper and
Astro Leaflet
1 parent 8eddbc6 commit 7d4a788

File tree

7 files changed

+84
-131
lines changed

7 files changed

+84
-131
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ This project initially started as a bare bones port of [hello-gatsby-starter](ht
5656
- Display map at geo coordinates and zoom level using `Map` component (need to also include `extra: ['map']` is frontmatter to load CSS/JS assets for page)
5757
- Calculates and show reading time for blog posts
5858
- CSS/JS assets of external libraries loaded only when needed on a per page and per package basis - no unnecessary bloat
59-
- Masonry Photo gallery and lightbox using PhotoSwipe (including display of EXIF tags)
60-
- Carousel component using Swiper
59+
- Masonry Photo gallery and lightbox using [PhotoSwipe](https://photoswipe.com) (including display of EXIF tags)
60+
- Carousel component using [Swiper](https://swiperjs.com/)
6161
- Documentation pages (modelled after astro docs starter but using Tailwind)
6262

6363
## External Packages
@@ -78,11 +78,11 @@ The start uses the following external packages:
7878
- Local full text search using [Lunr](https://lunrjs.com)
7979
- Math equations using [KaTeX](https://katex.org) via [remark-math and rehype-katex](https://github.com/remarkjs/remark-math)
8080
- Diagrams using [Mermaid](https://mermaid-js.github.io/mermaid/#/), [Markmap](https://markmap.js.org) and [PlantUML](https://plantuml.com)
81-
- Open Street Map using [Leaflet](https://leafletjs.com/)
81+
- Open Street Map using [Leaflet](https://leafletjs.com/) via [Astro Leaflet](https://github.com/pascal-brand38/astro-leaflet)
8282
- [reading-time](https://github.com/ngryman/reading-time)
8383
- [PhotoSwipe](https://photoswipe.com)
8484
- [exifr](https://mutiny.cz/exifr/)
85-
- [Swiper](https://swiperjs.com/)
85+
- [Swiper](https://swiperjs.com/) via [Astro Swiper](https://github.com/pascal-brand38/astro-swiper)
8686
- [Remark Emoji](https://github.com/rhysd/remark-emoji)
8787
- Masonry layout using [Astro Masonry](https://github.com/OlivierEstevez/astro-masonry)
8888

@@ -266,3 +266,5 @@ All commands are run from the root of the project, from a terminal:
266266
- Improved photoswipe implementation
267267
- replaced TailwindCSS masonry with astro-masonry
268268
- Updated Katex CSS to 0.16.23
269+
- Replaced bespoke leaflet integration with [Astro Leaflet](https://github.com/pascal-brand38/astro-leaflet)
270+
- Replaced bespoke Swiper integration with [Astro Swiper](https://github.com/pascal-brand38/astro-swiper)

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"@tailwindcss/forms": "^0.5.10",
2323
"@tailwindcss/typography": "^0.5.19",
2424
"@types/alpinejs": "^3.13.11",
25-
"@types/leaflet": "^1.9.20",
2625
"@typescript-eslint/parser": "^8.45.0",
2726
"alpinejs": "^3.15.0",
2827
"astro": "5.14.1",
@@ -58,19 +57,16 @@
5857
"@tailwindcss/vite": "^4.1.14",
5958
"astro-geo-map": "^2.0.0",
6059
"astro-icon": "^1.1.5",
60+
"astro-leaflet": "^1.8.1",
6161
"astro-masonry": "^1.2.2",
6262
"astro-mermaid": "^1.1.0",
6363
"astro-plantuml": "^0.1.4",
6464
"astro-seo": "^0.8.4",
65+
"astro-swiper": "^1.1.0",
6566
"hero-patterns": "^2.1.0",
66-
"katex": "^0.16.23",
67-
"leaflet": "^1.9.4",
6867
"lunr": "^2.3.9",
69-
"mermaid": "^11.12.0",
7068
"photoswipe": "^5.4.4",
7169
"photoswipe-dynamic-caption-plugin": "^1.2.7",
72-
"playwright": "^1.55.1",
73-
"swiper": "^12.0.2",
7470
"tailwindcss": "^4.1.14"
7571
},
7672
"packageManager": "[email protected]+sha512.e804f889f1cecc40d572db084eec3e4881739f8dec69c0ff10d2d1beff9a4e309383ba27b5b750059d7f4c149535b6cd0d2cb1ed3aeb739239a4284a68f40cfa"

pnpm-lock.yaml

Lines changed: 24 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/carousel.astro

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
---
2-
import 'swiper/css/bundle'
2+
import { Swiper, SwiperWrapper, SwiperSlide } from 'astro-swiper'
3+
import { SwiperButtonPrev, SwiperButtonNext, SwiperPagination } from 'astro-swiper'
4+
import type { AstroSwiperType } from 'astro-swiper'
5+
import type { ImageMetadata } from 'astro'
6+
7+
const astroSwiperOptions: AstroSwiperType = {
8+
options: {
9+
cssMode: true,
10+
loop: true,
11+
spaceBetween: 30,
12+
centeredSlides: true,
13+
autoplay: {
14+
delay: 5000,
15+
disableOnInteraction: false,
16+
waitForTransition: false
17+
},
18+
pagination: {
19+
el: '.swiper-pagination',
20+
clickable: true
21+
},
22+
navigation: {
23+
nextEl: '.swiper-button-next',
24+
prevEl: '.swiper-button-prev'
25+
},
26+
mousewheel: true,
27+
keyboard: true
28+
}
29+
}
330
431
export interface Props {
532
pages: {
@@ -21,17 +48,15 @@ const folderFiles = Object.keys(imageFiles).filter((image) => imagepaths.include
2148
const images = folderFiles.map((image) => imageFiles[image])
2249
---
2350

24-
<div
51+
<Swiper
52+
options={astroSwiperOptions.options}
2553
style="--swiper-navigation-color: #fff; --swiper-pagination-color: #fff"
26-
class:list={[
27-
'swiper mySwiper not-prose mx-auto w-full max-w-(--breakpoint-xl) rounded-lg',
28-
`h-[500px]`
29-
]}
54+
class="not-prose mx-auto h-[500px] w-full max-w-(--breakpoint-xl) rounded-lg"
3055
>
31-
<div class="swiper-wrapper">
56+
<SwiperWrapper>
3257
{
3358
pages.map((page, i) => (
34-
<div class="swiper-slide relative">
59+
<SwiperSlide class="relative">
3560
<div class="absolute bottom-0 left-0 z-10 h-full w-full bg-linear-to-t from-gray-800 opacity-25 xl:rounded-lg" />
3661
<img
3762
src={images[i].src}
@@ -43,39 +68,11 @@ const images = folderFiles.map((image) => imageFiles[image])
4368
{page.description && <p class="text-base text-gray-300 italic">{page.description}</p>}
4469
<slot />
4570
</div>
46-
</div>
71+
</SwiperSlide>
4772
))
4873
}
49-
</div>
50-
<div class="swiper-button-next"></div>
51-
<div class="swiper-button-prev"></div>
52-
<div class="swiper-pagination"></div>
53-
</div>
54-
55-
<!-- Swiper JS -->
56-
<script>
57-
// @ts-ignore
58-
import Swiper from 'swiper/bundle'
59-
60-
new Swiper('.mySwiper', {
61-
cssMode: true,
62-
// lazy: true,
63-
loop: true,
64-
spaceBetween: 30,
65-
centeredSlides: true,
66-
autoplay: {
67-
delay: 5000,
68-
disableOnInteraction: false
69-
},
70-
pagination: {
71-
el: '.swiper-pagination',
72-
clickable: true
73-
},
74-
navigation: {
75-
nextEl: '.swiper-button-next',
76-
prevEl: '.swiper-button-prev'
77-
},
78-
mousewheel: true,
79-
keyboard: true
80-
})
81-
</script>
74+
</SwiperWrapper>
75+
<SwiperButtonPrev />
76+
<SwiperButtonNext />
77+
<SwiperPagination />
78+
</Swiper>

src/components/map.astro

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,20 @@
11
---
2+
import { Leaflet } from 'astro-leaflet'
3+
24
export interface Props {
35
text?: string
46
loc: [number, number]
57
zoom: number
68
}
79
810
const { text, loc, zoom } = Astro.props
9-
10-
// import 'leaflet/dist/leaflet.css'
1111
---
1212

13-
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" crossorigin="" />
14-
<map-inner data-text={text} data-lat={loc[0]} data-lng={loc[1]} data-zoom={zoom}></map-inner>
15-
<div id="map" class="mb-3 h-96"></div>
16-
<script>
17-
import L from 'leaflet'
18-
19-
class MapInner extends HTMLElement {
20-
constructor() {
21-
super()
22-
23-
const loc: [number, number] = [Number(this.dataset.lat), Number(this.dataset.lng)]
24-
25-
const map = L.map('map', { scrollWheelZoom: false }).setView(loc, Number(this.dataset.zoom))
26-
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
27-
maxZoom: 19,
28-
attribution:
29-
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
30-
}).addTo(map)
31-
const marker = L.marker(loc).addTo(map)
32-
if (this.dataset.text) {
33-
marker.bindPopup(this.dataset.text || 'Location').openPopup()
34-
}
35-
}
36-
}
37-
38-
customElements.define('map-inner', MapInner)
39-
</script>
13+
<Leaflet
14+
options={{
15+
tileByName: 'OSM',
16+
center: loc,
17+
zoom: zoom,
18+
markers: [{ latlng: loc, options: { title: text } }]
19+
}}
20+
/>

src/content/blog/2022-08-23-sample-mdx-post.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ The above title is a variable declared in MDX.
2424

2525
The following is the Map component defined in this starter
2626

27-
<Map loc={[37.33214, -122.02992]} zoom={17} />
27+
<Map loc={[37.33214, -122.02992]} zoom={17} text="Apple" />

0 commit comments

Comments
 (0)