@jamwidgets/astro 0.5.0 → 0.5.1
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 +43 -0
- package/dist/loader.js +9 -6
- package/package.json +2 -2
- package/src/Embed.astro +2 -1
- package/src/loader.ts +11 -6
package/README.md
CHANGED
|
@@ -58,6 +58,49 @@ const posts = await getCollection("posts");
|
|
|
58
58
|
))}
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
Render a post's Markdown body with Astro's content component:
|
|
62
|
+
|
|
63
|
+
```astro
|
|
64
|
+
---
|
|
65
|
+
import { getEntry, render } from "astro:content";
|
|
66
|
+
import { Image } from "astro:assets";
|
|
67
|
+
const post = await getEntry("posts", "hello-world");
|
|
68
|
+
if (!post) throw new Error("Post not found");
|
|
69
|
+
const { Content } = await render(post);
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
{post.data.coverImage && (
|
|
73
|
+
<Image
|
|
74
|
+
src={post.data.coverImage}
|
|
75
|
+
inferSize
|
|
76
|
+
layout="full-width"
|
|
77
|
+
alt={post.data.title}
|
|
78
|
+
/>
|
|
79
|
+
)}
|
|
80
|
+
<article><Content /></article>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`post.data.content` is Markdown, not an HTML string. Do not render it with
|
|
84
|
+
`set:html`; use Astro's `render()` and `<Content />` as above.
|
|
85
|
+
|
|
86
|
+
For responsive uploaded images, authorize Jamwidgets' asset host in your Astro
|
|
87
|
+
config. Astro will then generate correctly sized image variants for Markdown
|
|
88
|
+
images. The hostname below is for Jamwidgets Cloud; self-hosted deployments use
|
|
89
|
+
the hostname configured by `ASSET_BASE_URL` (or fall back to
|
|
90
|
+
`<AWS_S3_BUCKET>.s3.<AWS_S3_REGION>.amazonaws.com`):
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import { defineConfig } from "astro/config";
|
|
94
|
+
|
|
95
|
+
export default defineConfig({
|
|
96
|
+
image: {
|
|
97
|
+
domains: ["assets.jamwidgets.com"],
|
|
98
|
+
layout: "constrained",
|
|
99
|
+
responsiveStyles: true,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
61
104
|
### Loader Options
|
|
62
105
|
|
|
63
106
|
```ts
|
package/dist/loader.js
CHANGED
|
@@ -30,7 +30,7 @@ export function jamwidgetsPostsLoader(options) {
|
|
|
30
30
|
return {
|
|
31
31
|
name: "jamwidgets-posts-loader",
|
|
32
32
|
async load(context) {
|
|
33
|
-
const { store, logger } = context;
|
|
33
|
+
const { store, logger, renderMarkdown } = context;
|
|
34
34
|
try {
|
|
35
35
|
const url = new URL(`${baseUrl}/posts`);
|
|
36
36
|
url.searchParams.set("limit", String(limit));
|
|
@@ -50,12 +50,15 @@ export function jamwidgetsPostsLoader(options) {
|
|
|
50
50
|
throw new Error(`Failed to fetch posts: ${response.status} ${response.statusText}`);
|
|
51
51
|
}
|
|
52
52
|
const data = await response.json();
|
|
53
|
+
const entries = await Promise.all(data.posts.map(async (post) => ({
|
|
54
|
+
id: post.slug,
|
|
55
|
+
data: { ...post },
|
|
56
|
+
body: post.content,
|
|
57
|
+
rendered: await renderMarkdown(post.content),
|
|
58
|
+
})));
|
|
53
59
|
store.clear();
|
|
54
|
-
for (const
|
|
55
|
-
store.set(
|
|
56
|
-
id: post.slug,
|
|
57
|
-
data: { ...post },
|
|
58
|
-
});
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
store.set(entry);
|
|
59
62
|
}
|
|
60
63
|
logger.info(`Loaded ${data.posts.length} posts from Jamwidgets`);
|
|
61
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamwidgets/astro",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Astro components and content loader for Jamwidgets (forms, comments, reactions, posts)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@jamwidgets/core": "^0.4.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"astro": "^5.
|
|
63
|
+
"astro": "^5.9.0 || ^6.0.0 || ^7.0.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"astro": "^7.1.3",
|
package/src/Embed.astro
CHANGED
package/src/loader.ts
CHANGED
|
@@ -78,7 +78,7 @@ export function jamwidgetsPostsLoader(options: JamwidgetsPostsLoaderOptions): Lo
|
|
|
78
78
|
name: "jamwidgets-posts-loader",
|
|
79
79
|
|
|
80
80
|
async load(context: LoaderContext) {
|
|
81
|
-
const { store, logger } = context;
|
|
81
|
+
const { store, logger, renderMarkdown } = context;
|
|
82
82
|
|
|
83
83
|
try {
|
|
84
84
|
const url = new URL(`${baseUrl}/posts`);
|
|
@@ -106,13 +106,18 @@ export function jamwidgetsPostsLoader(options: JamwidgetsPostsLoaderOptions): Lo
|
|
|
106
106
|
|
|
107
107
|
const data: ApiResponse = await response.json();
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
for (const post of data.posts) {
|
|
112
|
-
store.set({
|
|
109
|
+
const entries = await Promise.all(
|
|
110
|
+
data.posts.map(async (post) => ({
|
|
113
111
|
id: post.slug,
|
|
114
112
|
data: { ...post },
|
|
115
|
-
|
|
113
|
+
body: post.content,
|
|
114
|
+
rendered: await renderMarkdown(post.content),
|
|
115
|
+
})),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
store.clear();
|
|
119
|
+
for (const entry of entries) {
|
|
120
|
+
store.set(entry);
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
logger.info(`Loaded ${data.posts.length} posts from Jamwidgets`);
|