@flyo/nitro-astro 2.0.7 → 2.0.9
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 +263 -0
- package/package.json +4 -2
package/README.md
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# Flyo Nitro Astro Framework Integration
|
|
2
|
+
|
|
3
|
+
The Flyo Nitro Astro Framework Integration provides a comprehensive solution for implementing the Flyo Nitro CMS within the Astro (astro.build) environment. This guide details the integration process, emphasizing the use of Nitro [configurations](https://dev.flyo.cloud/dev/nitro/#die-grundlagen-von-nitro) within the Astro layout framework. Key highlights include:
|
|
4
|
+
|
|
5
|
+
- **Nitro Configuration in Astro**: This section explores methods for incorporating Nitro configurations into the Astro layout, offering step-by-step instructions for seamless integration that leverages the strengths of both systems.
|
|
6
|
+
- **Page Resolution and Block Integration**: Learn to manage and resolve pages within the Astro framework, including integrating Nitro's dynamic [blocks](https://dev.flyo.cloud/dev/nitro/block.html). This part provides insights into creating responsive and interactive web pages using Nitro block technology.
|
|
7
|
+
- **Fetching Entity Details**: Focus on techniques for retrieving and displaying detailed information about entities within Astro. This segment covers data fetching, handling, and presentation methods.
|
|
8
|
+
- **Image Service Integration**: Understand the integration of Flyo Storage's image service, as detailed in [Flyo Storage Documentation](https://dev.flyo.cloud/dev/infos/images.html). This section delves into working with images in Astro, including uploading, retrieving, and displaying images from Flyo Storage.
|
|
9
|
+
- **Meta Information Extraction**: The guide concludes with extracting and utilizing meta information, discussing the importance of meta tags for SEO and user engagement within the Astro framework.
|
|
10
|
+
|
|
11
|
+
This guide targets developers and web designers aiming to combine Flyo Nitro CMS and Astro framework capabilities to create dynamic, efficient, and feature-rich websites.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
To install the `@flyo/nitro-astro` package, execute the following command:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @flyo/nitro-astro
|
|
19
|
+
# yarn add @flyo/nitro-astro
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then, revise and adjust the configuration in your `astro.config.mjs`:
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import flyoNitroIntegration from "@flyo/nitro-astro";
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
site: "https://myflyowebsite.com", // required to make the sitemap.xml work
|
|
29
|
+
integrations: [
|
|
30
|
+
flyoNitroIntegration({
|
|
31
|
+
accessToken: "ADD_YOUR_TOKEN_HERE", // Switch between dev and prod tokens depending on the environment
|
|
32
|
+
liveEdit: true, // Enable on dev and preview systems for application reloading in the Flyo preview frame upon changes
|
|
33
|
+
components: {
|
|
34
|
+
// Define where the Flyo components are located. The suffix .astro is not required. The object key is the value from Flyo, while the object value is the component in the Astro components folder
|
|
35
|
+
// [!] Adding new elements requires restarting the development process
|
|
36
|
+
FlyoElementName: "AstroElementName",
|
|
37
|
+
AnotherFlyoElement: "subfolder/AnotherFlyoElement",
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
output: "server",
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
> [!WARNING]
|
|
46
|
+
> The nitro astro integration requires an SSR setup which is done by using `output: 'server'`.
|
|
47
|
+
|
|
48
|
+
### Pages
|
|
49
|
+
|
|
50
|
+
Add a `[...slug].astro` file in the pages directory with the following example content as a catch-all CMS handler:
|
|
51
|
+
|
|
52
|
+
```astro
|
|
53
|
+
---
|
|
54
|
+
import Layout from "../layouts/Layout.astro";
|
|
55
|
+
import { usePagesApi, useConfig } from "@flyo/nitro-astro";
|
|
56
|
+
import FlyoNitroPage from "@flyo/nitro-astro/FlyoNitroPage.astro";
|
|
57
|
+
import MetaInfoPage from "@flyo/nitro-astro/MetaInfoPage.astro";
|
|
58
|
+
|
|
59
|
+
const { slug } = Astro.params;
|
|
60
|
+
const resolveSlug = slug === undefined ? "" : slug;
|
|
61
|
+
const config = await useConfig(Astro);
|
|
62
|
+
let page;
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
if (!config.pages.includes(resolveSlug)) {
|
|
66
|
+
return new Response("Not Found", {
|
|
67
|
+
status: 404,
|
|
68
|
+
statusText: "Page Not Found",
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
page = await usePagesApi().page({ slug: resolveSlug });
|
|
73
|
+
} catch (e) {
|
|
74
|
+
return new Response(e.body.name, {
|
|
75
|
+
status: 404,
|
|
76
|
+
statusText: "Page Not Found",
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
<Layout title={page.title}>
|
|
82
|
+
<MetaInfoPage page={page} slot="head" />
|
|
83
|
+
<FlyoNitroPage page={page} />
|
|
84
|
+
</Layout>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
To receive the config in the layout in `src/layouts/Layout.astro`:
|
|
88
|
+
|
|
89
|
+
```astro
|
|
90
|
+
---
|
|
91
|
+
import { useConfig } from "@flyo/nitro-astro";
|
|
92
|
+
|
|
93
|
+
const config = await useConfig(Astro);
|
|
94
|
+
const { title } = Astro.props;
|
|
95
|
+
const currentPath = Astro.url.pathname;
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
<!doctype html>
|
|
99
|
+
<html lang="en">
|
|
100
|
+
<head>
|
|
101
|
+
<title>{title}</title>
|
|
102
|
+
<meta charset="UTF-8" />
|
|
103
|
+
<meta name="viewport" content="width=device-width" />
|
|
104
|
+
<!-- Auto-inject meta information for pages and entities -->
|
|
105
|
+
<slot name="head" />
|
|
106
|
+
</head>
|
|
107
|
+
<body>
|
|
108
|
+
{
|
|
109
|
+
config.containers.nav.items.map((item: object) => (
|
|
110
|
+
<a
|
|
111
|
+
style="background-color: red; color: white"
|
|
112
|
+
href={item.href}
|
|
113
|
+
class={`nav-class ${currentPath === item.href ? "text-red" : ""}`}
|
|
114
|
+
>
|
|
115
|
+
{item.label}
|
|
116
|
+
<br />
|
|
117
|
+
</a>
|
|
118
|
+
))
|
|
119
|
+
}
|
|
120
|
+
<div class="container">
|
|
121
|
+
<slot />
|
|
122
|
+
</div>
|
|
123
|
+
</body>
|
|
124
|
+
</html>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Blocks
|
|
128
|
+
|
|
129
|
+
Block Component Example (which are mostly located in `src/components/flyo`):
|
|
130
|
+
|
|
131
|
+
```astro
|
|
132
|
+
---
|
|
133
|
+
import { Image } from "astro:assets";
|
|
134
|
+
import { editableBlock } from "@flyo/nitro-astro";
|
|
135
|
+
import BlockSlot from "@flyo/nitro-astro/BlockSlot.astro";
|
|
136
|
+
const { block } = Astro.props;
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
<!-- Make the block editable if necessary -->
|
|
140
|
+
<div {...editableBlock(block)}>
|
|
141
|
+
<!-- Content variable -->
|
|
142
|
+
<div set:html={block.content.content.html} />
|
|
143
|
+
|
|
144
|
+
<!-- Handling items -->
|
|
145
|
+
{
|
|
146
|
+
block.items.map((item: object) => (
|
|
147
|
+
<div>
|
|
148
|
+
{item.title}
|
|
149
|
+
<a href={item.link.routes.detail}>Go to Detail</a>
|
|
150
|
+
</div>
|
|
151
|
+
))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
<!-- Image Proxy -->
|
|
155
|
+
<Image
|
|
156
|
+
src={block.content.image.source}
|
|
157
|
+
alt={block.content.alt ?? ""}
|
|
158
|
+
width={1920}
|
|
159
|
+
height={768}
|
|
160
|
+
/>
|
|
161
|
+
|
|
162
|
+
<!-- Handling slots -->
|
|
163
|
+
<BlockSlot slot={block.slots.mysuperslotname} />
|
|
164
|
+
</div>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Entities
|
|
168
|
+
|
|
169
|
+
The **Entity Details** API provides all the information about an entity and the associated model data configured in the Flyo interface. You can request detail pages either by using a slug (with an additional schema ID) or by a unique ID.
|
|
170
|
+
|
|
171
|
+
#### Example: Request by slug (type ID 9999)
|
|
172
|
+
|
|
173
|
+
For a blog post, use `src/pages/blog/[slug].astro` with `entityBySlug`. Since slugs can be unique within an entity but may not be unique across the entire system, it’s recommended to include the schema ID to fetch the correct entity.
|
|
174
|
+
|
|
175
|
+
```astro
|
|
176
|
+
---
|
|
177
|
+
import Layout from "../../layouts/Layout.astro";
|
|
178
|
+
import { useEntitiesApi } from "@flyo/nitro-astro";
|
|
179
|
+
import MetaInfoEntity from "@flyo/nitro-astro/MetaInfoEntity.astro";
|
|
180
|
+
|
|
181
|
+
const { slug } = Astro.params;
|
|
182
|
+
let response = null;
|
|
183
|
+
try {
|
|
184
|
+
response = await useEntitiesApi().entityBySlug({
|
|
185
|
+
slug,
|
|
186
|
+
lang: Astro.currentLocale,
|
|
187
|
+
typeId: 9999,
|
|
188
|
+
});
|
|
189
|
+
} catch (e) {
|
|
190
|
+
return new Response(e.body, {
|
|
191
|
+
status: 404,
|
|
192
|
+
statusText: "Entity Not Found",
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
const isProd = import.meta.env.PROD;
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
<Layout>
|
|
199
|
+
<MetaInfoEntity response={response} slot="head" />
|
|
200
|
+
<h1>{slug}</h1>
|
|
201
|
+
<img src={response.model.image.source} style="width:100%" />
|
|
202
|
+
</Layout>
|
|
203
|
+
{
|
|
204
|
+
isProd && (
|
|
205
|
+
<script is:inline define:vars={{ api: response.entity.entity_metric.api }}>
|
|
206
|
+
fetch(api)
|
|
207
|
+
</script>
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
#### Example: Request by unique ID
|
|
213
|
+
|
|
214
|
+
For fetching by unique ID, use `src/pages/blog/[uniqueid].astro` with `entityByUniqueid`. The unique ID is globally unique across the entire system, making it reliable for fetching specific entities.
|
|
215
|
+
|
|
216
|
+
```astro
|
|
217
|
+
const { uniqueid } = Astro.params;
|
|
218
|
+
// ....
|
|
219
|
+
await useEntitiesApi().entityByUniqueid({
|
|
220
|
+
uniqueid,
|
|
221
|
+
lang: Astro.currentLocale,
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Multiple Languages (i18n)
|
|
226
|
+
|
|
227
|
+
Refer to the [Astro internationalization documentation](https://docs.astro.build/en/guides/internationalization/) to configure languages. Ensure that the languages used in Flyo are defined in the `locales` array, and set the default language in `defaultLocale` in `astro.config.mjs`.
|
|
228
|
+
|
|
229
|
+
```astro
|
|
230
|
+
import { defineConfig } from "astro/config"
|
|
231
|
+
export default defineConfig({
|
|
232
|
+
i18n: {
|
|
233
|
+
defaultLocale: "en",
|
|
234
|
+
locales: ["en", "fr"],
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
All endpoints accept a `lang` parameter to retrieve data in the desired language. The **Nitro Astro** package handles this automatically. However, since the Entity Details page is custom-built, you need to manually pass the language parameter.
|
|
240
|
+
|
|
241
|
+
+ For slug-based requests:
|
|
242
|
+
```js
|
|
243
|
+
await useEntitiesApi().entityBySlug({ slug, lang: Astro.currentLocale });
|
|
244
|
+
```
|
|
245
|
+
+ For unique ID-based requests:
|
|
246
|
+
```js
|
|
247
|
+
await useEntitiesApi().entityByUniqueid({ uniqueid, lang: Astro.currentLocale });
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
> [!NOTE]
|
|
251
|
+
> If your entity details are internationalized (i18n), you need to create separate detail pages for each language.
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
.
|
|
255
|
+
├── de
|
|
256
|
+
│ └── detail
|
|
257
|
+
│ └── [slug].astro
|
|
258
|
+
├── fr
|
|
259
|
+
│ └── detail
|
|
260
|
+
│ └── [slug].astro
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
The above structure would be `/de/detail/[slug].astro` and `/fr/detail/[slug].astro`.
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flyo/nitro-astro",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "Connecting Flyo Headless Content Hub into your Astro project.",
|
|
5
|
+
"homepage": "https://dev.flyo.cloud/nitro",
|
|
5
6
|
"keywords": [
|
|
6
|
-
"withastro"
|
|
7
|
+
"withastro",
|
|
8
|
+
"flyo"
|
|
7
9
|
],
|
|
8
10
|
"main": "./dist/nitro-astro.js",
|
|
9
11
|
"module": "./dist/nitro-astro.mjs",
|