@jamwidgets/astro 0.5.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -2
- package/dist/loader.d.ts +7 -0
- package/dist/loader.js +41 -1
- package/package.json +7 -4
- package/src/Announcements.astro +24 -8
- package/src/Embed.astro +7 -4
- package/src/Gallery.astro +8 -0
- package/src/GalleryIndex.astro +8 -0
- package/src/Poll.astro +7 -4
- package/src/RandomPhoto.astro +8 -0
- package/src/index.ts +11 -0
- package/src/loader.ts +50 -0
package/README.md
CHANGED
|
@@ -11,6 +11,18 @@ Astro components and content loader for [Jamwidgets](https://jamwidgets.com) - w
|
|
|
11
11
|
npm install @jamwidgets/astro
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
## Galleries
|
|
15
|
+
|
|
16
|
+
```astro
|
|
17
|
+
---
|
|
18
|
+
import GalleryIndex from "@jamwidgets/astro/GalleryIndex";
|
|
19
|
+
import Gallery from "@jamwidgets/astro/Gallery";
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
<GalleryIndex siteKey="your-key" deepLink />
|
|
23
|
+
<Gallery siteKey="your-key" slug="field-notes" tag="portraits" />
|
|
24
|
+
```
|
|
25
|
+
|
|
14
26
|
## Setup
|
|
15
27
|
|
|
16
28
|
Add your Jamwidgets site key to your `.env`:
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* Re-exports all types, API functions, and controllers from @jamwidgets/core.
|
|
6
6
|
*/
|
|
7
7
|
export { DEFAULT_ENDPOINT, API_PATH, VISITOR_STORAGE_KEY, type JamwidgetsConfig, type SeriphConfig, // deprecated alias
|
|
8
|
-
type Comment, type ReactionCounts, type FormSubmitResponse, type SubscribeResponse, type JamwidgetsPost, type SeriphPost, // deprecated alias
|
|
9
|
-
type Announcement, type AnnouncementType, type Poll, type PollOption, type PollSettings, type PollWithResults, type ShowResultsMode, type FeedbackType, buildUrl, getSiteKey, getVisitorId, setVisitorId, type SubmitFormOptions, submitForm, type FetchCommentsOptions, fetchComments, type PostCommentOptions, postComment, type FetchReactionsOptions, type FetchReactionsResponse, fetchReactions, type AddReactionOptions, addReaction, type RemoveReactionOptions, removeReaction, type SubscribeOptions, subscribe, type JoinWaitlistOptions, type JoinWaitlistResponse, joinWaitlist, type ViewCountsOptions, type ViewCounts, type RecordViewResponse, getViewCounts, recordView, type SubmitFeedbackOptions, type SubmitFeedbackResponse, submitFeedback, type FetchPollOptions, fetchPoll, type VotePollOptions, type VotePollResponse, votePoll, type FetchAnnouncementsOptions, fetchAnnouncements, type DismissAnnouncementOptions, dismissAnnouncement, type FetchPostsOptions, fetchPosts, type FetchPostOptions, fetchPost, type SiteConfig, fetchSiteConfig, POWERED_BY_URL, POWERED_BY_LABEL, type ControllerStatus, type ControllerListener, type SubscribeState, type FormState, type ReactionsState, type CommentsState, type WaitlistState, type ViewCountsState, type FeedbackState, type PollState, type AnnouncementsState, SubscribeController, WaitlistController, FormController, ReactionsController, CommentsController, ViewCountsController, FeedbackController, PollController, AnnouncementsController, } from "@jamwidgets/core";
|
|
8
|
+
type Comment, type ReactionCounts, type FormSubmitResponse, type SubscribeResponse, type JamwidgetsPost, type JamwidgetsGallery, type GalleryPhoto, type GallerySummary, type SeriphPost, // deprecated alias
|
|
9
|
+
type Announcement, type AnnouncementType, type Poll, type PollOption, type PollSettings, type PollWithResults, type ShowResultsMode, type FeedbackType, buildUrl, getSiteKey, getVisitorId, setVisitorId, type SubmitFormOptions, submitForm, type FetchCommentsOptions, fetchComments, type PostCommentOptions, postComment, type FetchReactionsOptions, type FetchReactionsResponse, fetchReactions, type AddReactionOptions, addReaction, type RemoveReactionOptions, removeReaction, type SubscribeOptions, subscribe, type JoinWaitlistOptions, type JoinWaitlistResponse, joinWaitlist, type ViewCountsOptions, type ViewCounts, type RecordViewResponse, getViewCounts, recordView, type SubmitFeedbackOptions, type SubmitFeedbackResponse, submitFeedback, type FetchPollOptions, fetchPoll, type VotePollOptions, type VotePollResponse, votePoll, type FetchAnnouncementsOptions, fetchAnnouncements, type DismissAnnouncementOptions, dismissAnnouncement, type FetchPostsOptions, fetchPosts, type FetchPostOptions, fetchPost, type FetchGalleriesOptions, fetchGalleries, type FetchGalleryOptions, fetchGallery, type FetchRandomPhotoOptions, fetchRandomPhoto, type SiteConfig, fetchSiteConfig, POWERED_BY_URL, POWERED_BY_LABEL, type ControllerStatus, type ControllerListener, type SubscribeState, type FormState, type ReactionsState, type CommentsState, type WaitlistState, type ViewCountsState, type FeedbackState, type PollState, type AnnouncementsState, SubscribeController, WaitlistController, FormController, ReactionsController, CommentsController, ViewCountsController, FeedbackController, PollController, AnnouncementsController, } from "@jamwidgets/core";
|
|
10
10
|
export { jamwidgetsPostsLoader, seriphPostsLoader, // deprecated alias
|
|
11
|
-
type JamwidgetsPostsLoaderOptions, type SeriphPostsLoaderOptions,
|
|
11
|
+
type JamwidgetsPostsLoaderOptions, type SeriphPostsLoaderOptions, // deprecated alias
|
|
12
|
+
jamwidgetsGalleriesLoader, type JamwidgetsGalleriesLoaderOptions, } from "./loader.js";
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export {
|
|
|
9
9
|
// Constants
|
|
10
10
|
DEFAULT_ENDPOINT, API_PATH, VISITOR_STORAGE_KEY,
|
|
11
11
|
// Helpers
|
|
12
|
-
buildUrl, getSiteKey, getVisitorId, setVisitorId, submitForm, fetchComments, postComment, fetchReactions, addReaction, removeReaction, subscribe, joinWaitlist, getViewCounts, recordView, submitFeedback, fetchPoll, votePoll, fetchAnnouncements, dismissAnnouncement, fetchPosts, fetchPost, fetchSiteConfig, POWERED_BY_URL, POWERED_BY_LABEL, SubscribeController, WaitlistController, FormController, ReactionsController, CommentsController, ViewCountsController, FeedbackController, PollController, AnnouncementsController, } from "@jamwidgets/core";
|
|
12
|
+
buildUrl, getSiteKey, getVisitorId, setVisitorId, submitForm, fetchComments, postComment, fetchReactions, addReaction, removeReaction, subscribe, joinWaitlist, getViewCounts, recordView, submitFeedback, fetchPoll, votePoll, fetchAnnouncements, dismissAnnouncement, fetchPosts, fetchPost, fetchGalleries, fetchGallery, fetchRandomPhoto, fetchSiteConfig, POWERED_BY_URL, POWERED_BY_LABEL, SubscribeController, WaitlistController, FormController, ReactionsController, CommentsController, ViewCountsController, FeedbackController, PollController, AnnouncementsController, } from "@jamwidgets/core";
|
|
13
13
|
// Re-export loader (Astro-specific)
|
|
14
14
|
export { jamwidgetsPostsLoader, seriphPostsLoader, // deprecated alias
|
|
15
|
-
} from "./loader.js";
|
|
15
|
+
jamwidgetsGalleriesLoader, } from "./loader.js";
|
package/dist/loader.d.ts
CHANGED
|
@@ -45,3 +45,10 @@ export type SeriphPostsLoaderOptions = JamwidgetsPostsLoaderOptions;
|
|
|
45
45
|
export declare function jamwidgetsPostsLoader(options: JamwidgetsPostsLoaderOptions): Loader;
|
|
46
46
|
/** @deprecated Use jamwidgetsPostsLoader instead */
|
|
47
47
|
export declare const seriphPostsLoader: typeof jamwidgetsPostsLoader;
|
|
48
|
+
export interface JamwidgetsGalleriesLoaderOptions {
|
|
49
|
+
siteKey: string;
|
|
50
|
+
endpoint?: string;
|
|
51
|
+
origin?: string;
|
|
52
|
+
onError?: "throw" | "warn" | "ignore";
|
|
53
|
+
}
|
|
54
|
+
export declare function jamwidgetsGalleriesLoader(options: JamwidgetsGalleriesLoaderOptions): Loader;
|
package/dist/loader.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* export const collections = { posts };
|
|
18
18
|
*/
|
|
19
|
-
import { DEFAULT_ENDPOINT, API_PATH, getSiteKey, fetchPosts as coreFetchPosts, fetchPost as coreFetchPost, } from "@jamwidgets/core";
|
|
19
|
+
import { DEFAULT_ENDPOINT, API_PATH, getSiteKey, fetchPosts as coreFetchPosts, fetchPost as coreFetchPost, fetchGalleries as coreFetchGalleries, fetchGallery as coreFetchGallery, } from "@jamwidgets/core";
|
|
20
20
|
export { coreFetchPosts as fetchPosts, coreFetchPost as fetchPost };
|
|
21
21
|
/**
|
|
22
22
|
* Creates an Astro content loader that fetches posts from Jamwidgets.
|
|
@@ -77,3 +77,43 @@ export function jamwidgetsPostsLoader(options) {
|
|
|
77
77
|
}
|
|
78
78
|
/** @deprecated Use jamwidgetsPostsLoader instead */
|
|
79
79
|
export const seriphPostsLoader = jamwidgetsPostsLoader;
|
|
80
|
+
export function jamwidgetsGalleriesLoader(options) {
|
|
81
|
+
const { endpoint = DEFAULT_ENDPOINT, origin, onError = "throw" } = options;
|
|
82
|
+
const siteKey = getSiteKey({ siteKey: options.siteKey });
|
|
83
|
+
return {
|
|
84
|
+
name: "jamwidgets-galleries-loader",
|
|
85
|
+
async load({ store, logger }) {
|
|
86
|
+
try {
|
|
87
|
+
const summaries = [];
|
|
88
|
+
let after;
|
|
89
|
+
do {
|
|
90
|
+
const page = await coreFetchGalleries({
|
|
91
|
+
siteKey,
|
|
92
|
+
endpoint,
|
|
93
|
+
origin,
|
|
94
|
+
limit: 100,
|
|
95
|
+
after,
|
|
96
|
+
});
|
|
97
|
+
summaries.push(...page.galleries);
|
|
98
|
+
after = page.nextCursor;
|
|
99
|
+
} while (after);
|
|
100
|
+
const galleries = [];
|
|
101
|
+
for (const summary of summaries) {
|
|
102
|
+
galleries.push(await coreFetchGallery({ siteKey, endpoint, origin, slug: summary.slug }));
|
|
103
|
+
}
|
|
104
|
+
const entries = galleries.filter((gallery) => gallery !== null);
|
|
105
|
+
store.clear();
|
|
106
|
+
for (const gallery of entries)
|
|
107
|
+
store.set({ id: gallery.slug, data: { ...gallery } });
|
|
108
|
+
logger.info(`Loaded ${entries.length} galleries from Jamwidgets at build time`);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
112
|
+
if (onError === "throw")
|
|
113
|
+
throw error;
|
|
114
|
+
if (onError === "warn")
|
|
115
|
+
logger.warn(`Error loading galleries: ${message}`);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamwidgets/astro",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Astro components and content
|
|
3
|
+
"version": "0.6.3",
|
|
4
|
+
"description": "Astro components and content loaders for Jamwidgets",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/jamwidgets/astro.git"
|
|
@@ -33,7 +33,10 @@
|
|
|
33
33
|
"./Announcements": "./src/Announcements.astro",
|
|
34
34
|
"./Feedback": "./src/Feedback.astro",
|
|
35
35
|
"./Waitlist": "./src/Waitlist.astro",
|
|
36
|
-
"./Embed": "./src/Embed.astro"
|
|
36
|
+
"./Embed": "./src/Embed.astro",
|
|
37
|
+
"./Gallery": "./src/Gallery.astro",
|
|
38
|
+
"./GalleryIndex": "./src/GalleryIndex.astro",
|
|
39
|
+
"./RandomPhoto": "./src/RandomPhoto.astro"
|
|
37
40
|
},
|
|
38
41
|
"files": [
|
|
39
42
|
"src",
|
|
@@ -57,7 +60,7 @@
|
|
|
57
60
|
],
|
|
58
61
|
"license": "MIT",
|
|
59
62
|
"dependencies": {
|
|
60
|
-
"@jamwidgets/core": "^0.
|
|
63
|
+
"@jamwidgets/core": "^0.5.2"
|
|
61
64
|
},
|
|
62
65
|
"peerDependencies": {
|
|
63
66
|
"astro": "^5.9.0 || ^6.0.0 || ^7.0.0"
|
package/src/Announcements.astro
CHANGED
|
@@ -89,6 +89,16 @@ import Theme from "./Theme.astro";
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
function safeLinkUrl(value?: string): string | null {
|
|
93
|
+
if (!value) return null;
|
|
94
|
+
try {
|
|
95
|
+
const url = new URL(value, window.location.href);
|
|
96
|
+
return url.protocol === "http:" || url.protocol === "https:" ? url.href : null;
|
|
97
|
+
} catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
92
102
|
function renderAnnouncements(announcements: Announcement[]) {
|
|
93
103
|
container.innerHTML = "";
|
|
94
104
|
|
|
@@ -97,25 +107,31 @@ import Theme from "./Theme.astro";
|
|
|
97
107
|
el.className = `jamwidgets-announcement jamwidgets-announcement-${announcement.announcementType}`;
|
|
98
108
|
el.dataset.announcementId = announcement.id;
|
|
99
109
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
const contentEl = document.createElement("span");
|
|
111
|
+
contentEl.className = "jamwidgets-announcement-content";
|
|
112
|
+
contentEl.textContent = announcement.content;
|
|
113
|
+
el.append(contentEl);
|
|
114
|
+
|
|
115
|
+
const linkUrl = safeLinkUrl(announcement.linkUrl);
|
|
116
|
+
if (linkUrl) {
|
|
117
|
+
const link = document.createElement("a");
|
|
118
|
+
link.className = "jamwidgets-announcement-link";
|
|
119
|
+
link.href = linkUrl;
|
|
120
|
+
link.textContent = announcement.linkText || "Learn more";
|
|
121
|
+
el.append(" ", link);
|
|
104
122
|
}
|
|
105
123
|
|
|
106
124
|
if (announcement.isDismissible) {
|
|
107
|
-
|
|
125
|
+
el.insertAdjacentHTML("beforeend", `
|
|
108
126
|
<button type="button" class="jamwidgets-announcement-dismiss" aria-label="Dismiss">
|
|
109
127
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
110
128
|
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
111
129
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
112
130
|
</svg>
|
|
113
131
|
</button>
|
|
114
|
-
|
|
132
|
+
`);
|
|
115
133
|
}
|
|
116
134
|
|
|
117
|
-
el.innerHTML = content;
|
|
118
|
-
|
|
119
135
|
// Handle dismiss
|
|
120
136
|
const dismissBtn = el.querySelector(".jamwidgets-announcement-dismiss");
|
|
121
137
|
dismissBtn?.addEventListener("click", async () => {
|
package/src/Embed.astro
CHANGED
|
@@ -188,11 +188,13 @@ import Theme from "./Theme.astro";
|
|
|
188
188
|
const inputType = poll!.settings.multiSelect ? "checkbox" : "radio";
|
|
189
189
|
optionEl.innerHTML = `
|
|
190
190
|
<label class="jamwidgets-poll-label ${isSelected ? "jamwidgets-selected" : ""}">
|
|
191
|
-
<input type="${inputType}"
|
|
192
|
-
<span class="jamwidgets-poll-text"
|
|
191
|
+
<input type="${inputType}" ${isSelected ? "checked" : ""} />
|
|
192
|
+
<span class="jamwidgets-poll-text"></span>
|
|
193
193
|
</label>
|
|
194
194
|
`;
|
|
195
195
|
const input = optionEl.querySelector("input")!;
|
|
196
|
+
input.name = `poll-${poll!.id}`;
|
|
197
|
+
input.value = option.id;
|
|
196
198
|
input.addEventListener("change", () => {
|
|
197
199
|
if (poll!.settings.multiSelect) {
|
|
198
200
|
if (input.checked) {
|
|
@@ -215,7 +217,7 @@ import Theme from "./Theme.astro";
|
|
|
215
217
|
optionEl.innerHTML = `
|
|
216
218
|
<div class="jamwidgets-poll-result ${isSelected ? "jamwidgets-voted" : ""}">
|
|
217
219
|
<div class="jamwidgets-poll-bar" style="width: ${percent}%"></div>
|
|
218
|
-
<span class="jamwidgets-poll-text"
|
|
220
|
+
<span class="jamwidgets-poll-text"></span>
|
|
219
221
|
<span class="jamwidgets-poll-percent">${percent}%</span>
|
|
220
222
|
</div>
|
|
221
223
|
`;
|
|
@@ -223,10 +225,11 @@ import Theme from "./Theme.astro";
|
|
|
223
225
|
// Show without results (voted but results hidden)
|
|
224
226
|
optionEl.innerHTML = `
|
|
225
227
|
<div class="jamwidgets-poll-result jamwidgets-no-results ${isSelected ? "jamwidgets-voted" : ""}">
|
|
226
|
-
<span class="jamwidgets-poll-text"
|
|
228
|
+
<span class="jamwidgets-poll-text"></span>
|
|
227
229
|
</div>
|
|
228
230
|
`;
|
|
229
231
|
}
|
|
232
|
+
optionEl.querySelector(".jamwidgets-poll-text")!.textContent = option.text;
|
|
230
233
|
optionsEl.appendChild(optionEl);
|
|
231
234
|
});
|
|
232
235
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props { siteKey: string; slug: string; endpoint?: string; tag?: string }
|
|
3
|
+
const { siteKey, slug, endpoint, tag } = Astro.props;
|
|
4
|
+
---
|
|
5
|
+
<jamwidgets-gallery site-key={siteKey} slug={slug} endpoint={endpoint} tag={tag} />
|
|
6
|
+
<script>
|
|
7
|
+
import "@jamwidgets/core/gallery-elements";
|
|
8
|
+
</script>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props { siteKey: string; endpoint?: string; deepLink?: boolean }
|
|
3
|
+
const { siteKey, endpoint, deepLink = false } = Astro.props;
|
|
4
|
+
---
|
|
5
|
+
<jamwidgets-gallery-index site-key={siteKey} endpoint={endpoint} deep-link={deepLink ? "" : undefined} />
|
|
6
|
+
<script>
|
|
7
|
+
import "@jamwidgets/core/gallery-elements";
|
|
8
|
+
</script>
|
package/src/Poll.astro
CHANGED
|
@@ -172,11 +172,13 @@ import Theme from "./Theme.astro";
|
|
|
172
172
|
const inputType = poll!.settings.multiSelect ? "checkbox" : "radio";
|
|
173
173
|
optionEl.innerHTML = `
|
|
174
174
|
<label class="jamwidgets-poll-label ${isSelected ? "jamwidgets-selected" : ""}">
|
|
175
|
-
<input type="${inputType}"
|
|
176
|
-
<span class="jamwidgets-poll-text"
|
|
175
|
+
<input type="${inputType}" ${isSelected ? "checked" : ""} />
|
|
176
|
+
<span class="jamwidgets-poll-text"></span>
|
|
177
177
|
</label>
|
|
178
178
|
`;
|
|
179
179
|
const input = optionEl.querySelector("input")!;
|
|
180
|
+
input.name = `poll-${poll!.id}`;
|
|
181
|
+
input.value = option.id;
|
|
180
182
|
input.addEventListener("change", () => {
|
|
181
183
|
if (poll!.settings.multiSelect) {
|
|
182
184
|
if (input.checked) {
|
|
@@ -199,7 +201,7 @@ import Theme from "./Theme.astro";
|
|
|
199
201
|
optionEl.innerHTML = `
|
|
200
202
|
<div class="jamwidgets-poll-result ${isSelected ? "jamwidgets-voted" : ""}">
|
|
201
203
|
<div class="jamwidgets-poll-bar" style="width: ${percent}%"></div>
|
|
202
|
-
<span class="jamwidgets-poll-text"
|
|
204
|
+
<span class="jamwidgets-poll-text"></span>
|
|
203
205
|
<span class="jamwidgets-poll-percent">${percent}%</span>
|
|
204
206
|
</div>
|
|
205
207
|
`;
|
|
@@ -207,10 +209,11 @@ import Theme from "./Theme.astro";
|
|
|
207
209
|
// Show without results (voted but results hidden)
|
|
208
210
|
optionEl.innerHTML = `
|
|
209
211
|
<div class="jamwidgets-poll-result jamwidgets-no-results ${isSelected ? "jamwidgets-voted" : ""}">
|
|
210
|
-
<span class="jamwidgets-poll-text"
|
|
212
|
+
<span class="jamwidgets-poll-text"></span>
|
|
211
213
|
</div>
|
|
212
214
|
`;
|
|
213
215
|
}
|
|
216
|
+
optionEl.querySelector(".jamwidgets-poll-text")!.textContent = option.text;
|
|
214
217
|
optionsEl.appendChild(optionEl);
|
|
215
218
|
});
|
|
216
219
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props { siteKey: string; slug: string; endpoint?: string; tag?: string; seed?: string }
|
|
3
|
+
const { siteKey, slug, endpoint, tag, seed } = Astro.props;
|
|
4
|
+
---
|
|
5
|
+
<jamwidgets-random-photo site-key={siteKey} slug={slug} endpoint={endpoint} tag={tag} seed={seed} />
|
|
6
|
+
<script>
|
|
7
|
+
import "@jamwidgets/core/gallery-elements";
|
|
8
|
+
</script>
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,9 @@ export {
|
|
|
20
20
|
type FormSubmitResponse,
|
|
21
21
|
type SubscribeResponse,
|
|
22
22
|
type JamwidgetsPost,
|
|
23
|
+
type JamwidgetsGallery,
|
|
24
|
+
type GalleryPhoto,
|
|
25
|
+
type GallerySummary,
|
|
23
26
|
type SeriphPost, // deprecated alias
|
|
24
27
|
type Announcement,
|
|
25
28
|
type AnnouncementType,
|
|
@@ -94,6 +97,12 @@ export {
|
|
|
94
97
|
fetchPosts,
|
|
95
98
|
type FetchPostOptions,
|
|
96
99
|
fetchPost,
|
|
100
|
+
type FetchGalleriesOptions,
|
|
101
|
+
fetchGalleries,
|
|
102
|
+
type FetchGalleryOptions,
|
|
103
|
+
fetchGallery,
|
|
104
|
+
type FetchRandomPhotoOptions,
|
|
105
|
+
fetchRandomPhoto,
|
|
97
106
|
|
|
98
107
|
// Site config + powered-by attribution
|
|
99
108
|
type SiteConfig,
|
|
@@ -130,4 +139,6 @@ export {
|
|
|
130
139
|
seriphPostsLoader, // deprecated alias
|
|
131
140
|
type JamwidgetsPostsLoaderOptions,
|
|
132
141
|
type SeriphPostsLoaderOptions, // deprecated alias
|
|
142
|
+
jamwidgetsGalleriesLoader,
|
|
143
|
+
type JamwidgetsGalleriesLoaderOptions,
|
|
133
144
|
} from "./loader.js";
|
package/src/loader.ts
CHANGED
|
@@ -27,6 +27,10 @@ import {
|
|
|
27
27
|
type SeriphPost, // deprecated alias
|
|
28
28
|
type FetchPostsOptions,
|
|
29
29
|
type FetchPostOptions,
|
|
30
|
+
fetchGalleries as coreFetchGalleries,
|
|
31
|
+
fetchGallery as coreFetchGallery,
|
|
32
|
+
type JamwidgetsGallery,
|
|
33
|
+
type GallerySummary,
|
|
30
34
|
} from "@jamwidgets/core";
|
|
31
35
|
import type { Loader, LoaderContext } from "astro/loaders";
|
|
32
36
|
|
|
@@ -137,3 +141,49 @@ export function jamwidgetsPostsLoader(options: JamwidgetsPostsLoaderOptions): Lo
|
|
|
137
141
|
|
|
138
142
|
/** @deprecated Use jamwidgetsPostsLoader instead */
|
|
139
143
|
export const seriphPostsLoader = jamwidgetsPostsLoader;
|
|
144
|
+
|
|
145
|
+
export interface JamwidgetsGalleriesLoaderOptions {
|
|
146
|
+
siteKey: string;
|
|
147
|
+
endpoint?: string;
|
|
148
|
+
origin?: string;
|
|
149
|
+
onError?: "throw" | "warn" | "ignore";
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function jamwidgetsGalleriesLoader(options: JamwidgetsGalleriesLoaderOptions): Loader {
|
|
153
|
+
const { endpoint = DEFAULT_ENDPOINT, origin, onError = "throw" } = options;
|
|
154
|
+
const siteKey = getSiteKey({ siteKey: options.siteKey });
|
|
155
|
+
return {
|
|
156
|
+
name: "jamwidgets-galleries-loader",
|
|
157
|
+
async load({ store, logger }: LoaderContext) {
|
|
158
|
+
try {
|
|
159
|
+
const summaries: GallerySummary[] = [];
|
|
160
|
+
let after: string | undefined;
|
|
161
|
+
do {
|
|
162
|
+
const page = await coreFetchGalleries({
|
|
163
|
+
siteKey,
|
|
164
|
+
endpoint,
|
|
165
|
+
origin,
|
|
166
|
+
limit: 100,
|
|
167
|
+
after,
|
|
168
|
+
});
|
|
169
|
+
summaries.push(...page.galleries);
|
|
170
|
+
after = page.nextCursor;
|
|
171
|
+
} while (after);
|
|
172
|
+
const galleries: Array<JamwidgetsGallery | null> = [];
|
|
173
|
+
for (const summary of summaries) {
|
|
174
|
+
galleries.push(
|
|
175
|
+
await coreFetchGallery({ siteKey, endpoint, origin, slug: summary.slug }),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
const entries = galleries.filter((gallery): gallery is JamwidgetsGallery => gallery !== null);
|
|
179
|
+
store.clear();
|
|
180
|
+
for (const gallery of entries) store.set({ id: gallery.slug, data: { ...gallery } });
|
|
181
|
+
logger.info(`Loaded ${entries.length} galleries from Jamwidgets at build time`);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
184
|
+
if (onError === "throw") throw error;
|
|
185
|
+
if (onError === "warn") logger.warn(`Error loading galleries: ${message}`);
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|