@flyo/nitro-astro 2.1.2 → 2.3.0
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 +560 -3
- package/components/DebugInfo.astro +43 -0
- package/components/DebugInfo.test.ts +120 -0
- package/components/DebugInfo.ts +2 -0
- package/components/FlyoWysiwyg.astro +32 -0
- package/components/FlyoWysiwyg.test.ts +24 -0
- package/components/FlyoWysiwyg.ts +2 -0
- package/dist/nitro-astro.js +4 -3
- package/dist/nitro-astro.mjs +108 -103
- package/dist/types/components/DebugInfo.d.ts +3 -0
- package/dist/types/components/DebugInfo.test.d.ts +1 -0
- package/dist/types/components/FlyoWysiwyg.d.ts +3 -0
- package/dist/types/components/FlyoWysiwyg.test.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +19 -6
package/README.md
CHANGED
|
@@ -22,14 +22,21 @@ npm install @flyo/nitro-astro
|
|
|
22
22
|
Then, revise and adjust the configuration in your `astro.config.mjs`:
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
|
+
import { loadEnv } from "vite"
|
|
26
|
+
import { defineConfig } from "astro/config";
|
|
25
27
|
import flyoNitroIntegration from "@flyo/nitro-astro";
|
|
26
28
|
|
|
29
|
+
const {
|
|
30
|
+
FLYO_ACCESS_TOKEN,
|
|
31
|
+
FLYO_LIVE_EDIT
|
|
32
|
+
} = loadEnv(process.env.NODE_ENV, process.cwd() + "/", "");
|
|
33
|
+
|
|
27
34
|
export default defineConfig({
|
|
28
35
|
site: "https://myflyowebsite.com", // required to make the sitemap.xml work
|
|
29
36
|
integrations: [
|
|
30
37
|
flyoNitroIntegration({
|
|
31
|
-
accessToken:
|
|
32
|
-
liveEdit:
|
|
38
|
+
accessToken: FLYO_ACCESS_TOKEN, // Switch between dev and prod tokens depending on the environment
|
|
39
|
+
liveEdit: FLYO_LIVE_EDIT, // Enable on dev and preview systems for application reloading in the Flyo preview frame upon changes
|
|
33
40
|
components: {
|
|
34
41
|
// 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
42
|
// [!] Adding new elements requires restarting the development process
|
|
@@ -45,6 +52,59 @@ export default defineConfig({
|
|
|
45
52
|
> [!WARNING]
|
|
46
53
|
> The nitro astro integration requires an SSR setup which is done by using `output: 'server'`.
|
|
47
54
|
|
|
55
|
+
## Configuration Options
|
|
56
|
+
|
|
57
|
+
The `flyoNitroIntegration` accepts the following configuration options:
|
|
58
|
+
|
|
59
|
+
### Required Options
|
|
60
|
+
|
|
61
|
+
- **`accessToken`** (string, required): Your Flyo access token for authentication. This is either the production or development token from the Flyo Cloud interface. Keep in mind that requests with production accessToken will be effectively cached by the Flyo CDN, but development accessToken requests will not be cached.
|
|
62
|
+
|
|
63
|
+
- **`components`** (object, required): Object containing component definitions where the key is the component name defined in the Flyo Interface, and the value is the name of the component inside the components directory. The `.astro` suffix is not required.
|
|
64
|
+
```js
|
|
65
|
+
components: {
|
|
66
|
+
Text: "Text",
|
|
67
|
+
CardsGrid: "CardsGrid",
|
|
68
|
+
SlotContainer: "subfolder/SlotContainer",
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Optional Options
|
|
73
|
+
|
|
74
|
+
- **`liveEdit`** (string | boolean | number, default: `false`): Enables live editing mode. If enabled, the application will reload when changes are made in the Flyo preview frame. This should be enabled on dev and preview systems.
|
|
75
|
+
|
|
76
|
+
- **`componentsDir`** (string, default: `"src/components/flyo"`): Directory path where your Flyo components are located.
|
|
77
|
+
|
|
78
|
+
- **`fallbackComponent`** (string, optional): Name of a fallback component to use when a requested component is not found. This component will only be used in live editing mode. Example: `"BlockNotFound"` would reference `{componentsDir}/BlockNotFound.astro`.
|
|
79
|
+
|
|
80
|
+
- **`clientCacheHeaderTtl`** (number, default: `900`): TTL (Time-To-Live) for client-side cache headers, in seconds. Default is 900 seconds (15 minutes). Only available if `liveEdit` is disabled. Use `0` to disable client caching.
|
|
81
|
+
|
|
82
|
+
- **`serverCacheHeaderTtl`** (number, default: `1200`): TTL (Time-To-Live) for server-side cache headers, in seconds. Default is 1200 seconds (20 minutes). Only available if `liveEdit` is disabled. Use `0` to disable server caching.
|
|
83
|
+
|
|
84
|
+
### Complete Configuration Example
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
export default defineConfig({
|
|
88
|
+
site: "https://myflyowebsite.com",
|
|
89
|
+
integrations: [
|
|
90
|
+
flyoNitroIntegration({
|
|
91
|
+
accessToken: FLYO_ACCESS_TOKEN,
|
|
92
|
+
liveEdit: FLYO_LIVE_EDIT,
|
|
93
|
+
componentsDir: "src/components/flyo",
|
|
94
|
+
fallbackComponent: "BlockNotFound",
|
|
95
|
+
clientCacheHeaderTtl: 600, // 10 minutes
|
|
96
|
+
serverCacheHeaderTtl: 1800, // 30 minutes
|
|
97
|
+
components: {
|
|
98
|
+
Text: "Text",
|
|
99
|
+
CardsGrid: "CardsGrid",
|
|
100
|
+
SlotContainer: "SlotContainer",
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
output: "server",
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
48
108
|
### Pages
|
|
49
109
|
|
|
50
110
|
Add a `[...slug].astro` file in the pages directory with the following example content as a catch-all CMS handler:
|
|
@@ -121,7 +181,26 @@ const currentPath = Astro.url.pathname;
|
|
|
121
181
|
|
|
122
182
|
### Blocks
|
|
123
183
|
|
|
124
|
-
Block
|
|
184
|
+
Block components are the building blocks of your Flyo pages. They receive a `block` prop containing all the data from Flyo.
|
|
185
|
+
|
|
186
|
+
#### Basic Block Component Example
|
|
187
|
+
|
|
188
|
+
Located in `src/components/flyo/Text.astro`:
|
|
189
|
+
|
|
190
|
+
```astro
|
|
191
|
+
---
|
|
192
|
+
import { editable } from "@flyo/nitro-astro";
|
|
193
|
+
const { block } = Astro.props;
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
<!-- Make the block editable if necessary -->
|
|
197
|
+
<div {...editable(block)}>
|
|
198
|
+
<!-- Content variable -->
|
|
199
|
+
<div set:html={block.content.content.html} />
|
|
200
|
+
</div>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Block with Items and Images
|
|
125
204
|
|
|
126
205
|
```astro
|
|
127
206
|
---
|
|
@@ -159,6 +238,217 @@ const { block } = Astro.props;
|
|
|
159
238
|
</div>
|
|
160
239
|
```
|
|
161
240
|
|
|
241
|
+
#### Cards Grid Component Example
|
|
242
|
+
|
|
243
|
+
Example of a component that displays a grid of cards with items (`src/components/flyo/CardsGrid.astro`):
|
|
244
|
+
|
|
245
|
+
```astro
|
|
246
|
+
---
|
|
247
|
+
import { Image } from "astro:assets";
|
|
248
|
+
import { editable } from "@flyo/nitro-astro";
|
|
249
|
+
const { block } = Astro.props;
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
{
|
|
253
|
+
block.items.map((item: any) => (
|
|
254
|
+
<div {...editable(block)} style="background-color:#F0F0F0; padding:20px; margin-bottom:10px;">
|
|
255
|
+
<h2 class="text-xl">{item.title}</h2>
|
|
256
|
+
{item.image && (
|
|
257
|
+
<Image
|
|
258
|
+
src={item.image.source}
|
|
259
|
+
alt={item.title}
|
|
260
|
+
width="200"
|
|
261
|
+
height="200"
|
|
262
|
+
/>
|
|
263
|
+
)}
|
|
264
|
+
<a href={item.link.routes.detail} class="underline">
|
|
265
|
+
Go to Detail
|
|
266
|
+
</a>
|
|
267
|
+
</div>
|
|
268
|
+
))
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
#### Slot Container Component Example
|
|
273
|
+
|
|
274
|
+
Slots allow you to nest blocks within blocks (`src/components/flyo/SlotContainer.astro`):
|
|
275
|
+
|
|
276
|
+
```astro
|
|
277
|
+
---
|
|
278
|
+
import BlockSlot from "@flyo/nitro-astro/BlockSlot.astro";
|
|
279
|
+
const { block } = Astro.props;
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
<BlockSlot slot={block.slots.slotcontainername} />
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Available Components
|
|
286
|
+
|
|
287
|
+
### Core Components
|
|
288
|
+
|
|
289
|
+
These components are provided by the package and can be imported directly:
|
|
290
|
+
|
|
291
|
+
#### `FlyoNitroPage`
|
|
292
|
+
|
|
293
|
+
Renders an entire Flyo page with all its blocks.
|
|
294
|
+
|
|
295
|
+
```astro
|
|
296
|
+
---
|
|
297
|
+
import FlyoNitroPage from "@flyo/nitro-astro/FlyoNitroPage.astro";
|
|
298
|
+
const page = await usePagesApi().page({ slug });
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
<FlyoNitroPage page={page} />
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
#### `FlyoNitroBlock`
|
|
305
|
+
|
|
306
|
+
Renders a single Flyo block. This component automatically maps the block's component name to your custom components.
|
|
307
|
+
|
|
308
|
+
```astro
|
|
309
|
+
---
|
|
310
|
+
import FlyoNitroBlock from "@flyo/nitro-astro/FlyoNitroBlock.astro";
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
<FlyoNitroBlock block={block} />
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
#### `BlockSlot`
|
|
317
|
+
|
|
318
|
+
Renders the contents of a Flyo block slot, allowing for nested block structures.
|
|
319
|
+
|
|
320
|
+
```astro
|
|
321
|
+
---
|
|
322
|
+
import BlockSlot from "@flyo/nitro-astro/BlockSlot.astro";
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
<BlockSlot slot={block.slots.myslotname} />
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
#### `MetaInfo`
|
|
329
|
+
|
|
330
|
+
Generic component for adding meta tags (title, description, image, JSON-LD).
|
|
331
|
+
|
|
332
|
+
```astro
|
|
333
|
+
---
|
|
334
|
+
import MetaInfo from "@flyo/nitro-astro/MetaInfo.astro";
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
<MetaInfo
|
|
338
|
+
title="Page Title"
|
|
339
|
+
description="Page description"
|
|
340
|
+
image="https://example.com/image.jpg"
|
|
341
|
+
jsonld={jsonldObject}
|
|
342
|
+
slot="head"
|
|
343
|
+
/>
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
#### `MetaInfoPage`
|
|
347
|
+
|
|
348
|
+
Specialized meta component for Flyo pages.
|
|
349
|
+
|
|
350
|
+
```astro
|
|
351
|
+
---
|
|
352
|
+
import MetaInfoPage from "@flyo/nitro-astro/MetaInfoPage.astro";
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
<MetaInfoPage page={page} slot="head" />
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### `MetaInfoEntity`
|
|
359
|
+
|
|
360
|
+
Specialized meta component for Flyo entities.
|
|
361
|
+
|
|
362
|
+
```astro
|
|
363
|
+
---
|
|
364
|
+
import MetaInfoEntity from "@flyo/nitro-astro/MetaInfoEntity.astro";
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
<MetaInfoEntity response={entityResponse} slot="head" />
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
#### `FallbackComponent`
|
|
371
|
+
|
|
372
|
+
Automatically used when a component is not found (only in live edit mode). You can customize this behavior with the `fallbackComponent` configuration option.
|
|
373
|
+
|
|
374
|
+
### Wysiwyg
|
|
375
|
+
|
|
376
|
+
The `FlyoWysiwyg` component renders ProseMirror/TipTap JSON content. It handles standard nodes automatically and allows you to provide custom components for specific node types.
|
|
377
|
+
|
|
378
|
+
#### Basic Usage
|
|
379
|
+
|
|
380
|
+
```astro
|
|
381
|
+
---
|
|
382
|
+
import FlyoWysiwyg from "@flyo/nitro-astro/FlyoWysiwyg.astro";
|
|
383
|
+
const { block } = Astro.props;
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
<FlyoWysiwyg json={block.content.json} />
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
#### Custom Node Components
|
|
390
|
+
|
|
391
|
+
You can override the default rendering of specific node types by providing custom components:
|
|
392
|
+
|
|
393
|
+
```astro
|
|
394
|
+
---
|
|
395
|
+
import FlyoWysiwyg from "@flyo/nitro-astro/FlyoWysiwyg.astro";
|
|
396
|
+
import CustomImage from "./wysiwyg/CustomImage.astro";
|
|
397
|
+
import CustomVideo from "./wysiwyg/CustomVideo.astro";
|
|
398
|
+
|
|
399
|
+
const { block } = Astro.props;
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
<FlyoWysiwyg
|
|
403
|
+
json={block.content.json}
|
|
404
|
+
components={{
|
|
405
|
+
image: CustomImage,
|
|
406
|
+
video: CustomVideo
|
|
407
|
+
}}
|
|
408
|
+
/>
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
#### Custom Image Component Example
|
|
412
|
+
|
|
413
|
+
Here's an example of a custom image component (`src/components/flyo/wysiwyg/Image.astro`):
|
|
414
|
+
|
|
415
|
+
```astro
|
|
416
|
+
---
|
|
417
|
+
const { node } = Astro.props;
|
|
418
|
+
const { src, alt, title } = node.attrs;
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
<img src={src.source} alt={alt} title={title} style="max-width: 100%; height: auto;" />
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
The `node` prop contains all attributes from the ProseMirror node. For images, you typically get:
|
|
425
|
+
- `src`: The image source (can be an object with a `source` property when using Flyo storage)
|
|
426
|
+
- `alt`: Alternative text
|
|
427
|
+
- `title`: Image title
|
|
428
|
+
|
|
429
|
+
#### Complete Text Block with Wysiwyg Example
|
|
430
|
+
|
|
431
|
+
```astro
|
|
432
|
+
---
|
|
433
|
+
import { editable } from "@flyo/nitro-astro";
|
|
434
|
+
import FlyoWysiwyg from "@flyo/nitro-astro/FlyoWysiwyg.astro";
|
|
435
|
+
import Image from "./wysiwyg/Image.astro";
|
|
436
|
+
|
|
437
|
+
const { block } = Astro.props;
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
<div {...editable(block)}>
|
|
441
|
+
<div class="p-4">
|
|
442
|
+
<FlyoWysiwyg
|
|
443
|
+
json={block.content.content.json}
|
|
444
|
+
components={{
|
|
445
|
+
image: Image
|
|
446
|
+
}}
|
|
447
|
+
/>
|
|
448
|
+
</div>
|
|
449
|
+
</div>
|
|
450
|
+
```
|
|
451
|
+
|
|
162
452
|
### Entities
|
|
163
453
|
|
|
164
454
|
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.
|
|
@@ -263,3 +553,270 @@ All endpoints accept a `lang` parameter to retrieve data in the desired language
|
|
|
263
553
|
```
|
|
264
554
|
|
|
265
555
|
The above structure would be `/de/detail/[slug].astro` and `/fr/detail/[slug].astro`.
|
|
556
|
+
|
|
557
|
+
## API Functions
|
|
558
|
+
|
|
559
|
+
The Flyo Nitro Astro package provides several API functions to interact with the Flyo Nitro CMS:
|
|
560
|
+
|
|
561
|
+
### Configuration APIs
|
|
562
|
+
|
|
563
|
+
#### `useConfig(astro: AstroGlobal)`
|
|
564
|
+
|
|
565
|
+
Returns the resolved configuration object that includes navigation containers and other config data. This is typically used in layouts and pages.
|
|
566
|
+
|
|
567
|
+
```astro
|
|
568
|
+
---
|
|
569
|
+
import { useConfig } from "@flyo/nitro-astro";
|
|
570
|
+
|
|
571
|
+
const config = await useConfig(Astro);
|
|
572
|
+
// Access navigation items
|
|
573
|
+
config.containers.nav.items.map((item) => ...)
|
|
574
|
+
// Access available pages
|
|
575
|
+
config.pages.includes(slug)
|
|
576
|
+
---
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
#### `useConfigApi()`
|
|
580
|
+
|
|
581
|
+
Returns the ConfigApi instance for making custom configuration requests.
|
|
582
|
+
|
|
583
|
+
```astro
|
|
584
|
+
---
|
|
585
|
+
import { useConfigApi } from "@flyo/nitro-astro";
|
|
586
|
+
|
|
587
|
+
const configApi = useConfigApi();
|
|
588
|
+
const config = await configApi.config({ lang: "en" });
|
|
589
|
+
---
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
#### `useConfiguration()`
|
|
593
|
+
|
|
594
|
+
Returns the API main configuration which holds the access key and is globally available.
|
|
595
|
+
|
|
596
|
+
```typescript
|
|
597
|
+
import { useConfiguration } from "@flyo/nitro-astro";
|
|
598
|
+
|
|
599
|
+
const configuration = useConfiguration();
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### Page APIs
|
|
603
|
+
|
|
604
|
+
#### `usePagesApi()`
|
|
605
|
+
|
|
606
|
+
Returns the PagesApi instance for fetching Flyo pages.
|
|
607
|
+
|
|
608
|
+
```astro
|
|
609
|
+
---
|
|
610
|
+
import { usePagesApi } from "@flyo/nitro-astro";
|
|
611
|
+
|
|
612
|
+
const pagesApi = usePagesApi();
|
|
613
|
+
const page = await pagesApi.page({ slug: "about" });
|
|
614
|
+
---
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
### Entity APIs
|
|
618
|
+
|
|
619
|
+
#### `useEntitiesApi()`
|
|
620
|
+
|
|
621
|
+
Returns the EntitiesApi instance for fetching entity details.
|
|
622
|
+
|
|
623
|
+
```astro
|
|
624
|
+
---
|
|
625
|
+
import { useEntitiesApi } from "@flyo/nitro-astro";
|
|
626
|
+
|
|
627
|
+
// Fetch by slug and type ID
|
|
628
|
+
const entity = await useEntitiesApi().entityBySlug({
|
|
629
|
+
slug: "my-post",
|
|
630
|
+
lang: Astro.currentLocale,
|
|
631
|
+
typeId: 54
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
// Or fetch by unique ID
|
|
635
|
+
const entity = await useEntitiesApi().entityByUniqueid({
|
|
636
|
+
uniqueid: "abc123",
|
|
637
|
+
lang: Astro.currentLocale
|
|
638
|
+
});
|
|
639
|
+
---
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
### Search APIs
|
|
643
|
+
|
|
644
|
+
#### `useSearchApi()`
|
|
645
|
+
|
|
646
|
+
Returns the SearchApi instance for performing search operations.
|
|
647
|
+
|
|
648
|
+
```astro
|
|
649
|
+
---
|
|
650
|
+
import { useSearchApi } from "@flyo/nitro-astro";
|
|
651
|
+
|
|
652
|
+
const searchApi = useSearchApi();
|
|
653
|
+
// Use the search API for custom search functionality
|
|
654
|
+
---
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
### Sitemap APIs
|
|
658
|
+
|
|
659
|
+
#### `useSitemapApi()`
|
|
660
|
+
|
|
661
|
+
Returns the SitemapApi instance. The sitemap is automatically generated at `/sitemap.xml`, but you can use this API for custom sitemap functionality.
|
|
662
|
+
|
|
663
|
+
```astro
|
|
664
|
+
---
|
|
665
|
+
import { useSitemapApi } from "@flyo/nitro-astro";
|
|
666
|
+
|
|
667
|
+
const sitemapApi = useSitemapApi();
|
|
668
|
+
const sitemap = await sitemapApi.sitemap();
|
|
669
|
+
---
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
### Version APIs
|
|
673
|
+
|
|
674
|
+
#### `useVersionApi()`
|
|
675
|
+
|
|
676
|
+
Returns the VersionApi instance for checking API versions.
|
|
677
|
+
|
|
678
|
+
```astro
|
|
679
|
+
---
|
|
680
|
+
import { useVersionApi } from "@flyo/nitro-astro";
|
|
681
|
+
|
|
682
|
+
const versionApi = useVersionApi();
|
|
683
|
+
// Use for version-specific functionality
|
|
684
|
+
---
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
### Helper Functions
|
|
688
|
+
|
|
689
|
+
#### `editable(block)`
|
|
690
|
+
|
|
691
|
+
Makes a block editable in the Flyo live edit mode. Returns an object with the `data-flyo-uid` attribute.
|
|
692
|
+
|
|
693
|
+
```astro
|
|
694
|
+
---
|
|
695
|
+
import { editable } from "@flyo/nitro-astro";
|
|
696
|
+
const { block } = Astro.props;
|
|
697
|
+
---
|
|
698
|
+
|
|
699
|
+
<div {...editable(block)}>
|
|
700
|
+
<!-- Block content -->
|
|
701
|
+
</div>
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
> **Note**: `editableBlock` is also available as a backwards-compatible alias for `editable`.
|
|
705
|
+
|
|
706
|
+
## Built-in Features
|
|
707
|
+
|
|
708
|
+
### Automatic Sitemap Generation
|
|
709
|
+
|
|
710
|
+
The integration automatically creates a `/sitemap.xml` route that includes all your Flyo pages and entities. Make sure to set the `site` property in your `astro.config.mjs`:
|
|
711
|
+
|
|
712
|
+
```js
|
|
713
|
+
export default defineConfig({
|
|
714
|
+
site: "https://myflyowebsite.com",
|
|
715
|
+
// ... rest of config
|
|
716
|
+
});
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
### Image Service Integration
|
|
720
|
+
|
|
721
|
+
The package includes an automatic image service that integrates with Flyo Storage's image transformation capabilities. Images are automatically processed through Flyo's CDN with support for:
|
|
722
|
+
|
|
723
|
+
- Dynamic resizing (`width` and `height`)
|
|
724
|
+
- Format conversion (defaults to WebP)
|
|
725
|
+
- Lazy loading
|
|
726
|
+
- Proper dimensions to prevent CLS
|
|
727
|
+
|
|
728
|
+
```astro
|
|
729
|
+
---
|
|
730
|
+
import { Image } from "astro:assets";
|
|
731
|
+
---
|
|
732
|
+
|
|
733
|
+
<Image
|
|
734
|
+
src={block.content.image.source}
|
|
735
|
+
alt="Description"
|
|
736
|
+
width={1920}
|
|
737
|
+
height={768}
|
|
738
|
+
/>
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
The image URL is automatically transformed to: `https://storage.flyo.cloud/image_xxx.jpg/thumb/1920x768?format=webp`
|
|
742
|
+
|
|
743
|
+
### Development Toolbar
|
|
744
|
+
|
|
745
|
+
When running in development mode, the integration adds a custom toolbar with quick links to:
|
|
746
|
+
- Flyo Cloud Login
|
|
747
|
+
- Flyo Nitro Developer Portal
|
|
748
|
+
- Flyo Nitro API Documentation
|
|
749
|
+
|
|
750
|
+
### Middleware & Caching
|
|
751
|
+
|
|
752
|
+
The integration automatically adds middleware that:
|
|
753
|
+
- Resolves the Flyo configuration on each request
|
|
754
|
+
- Sets appropriate cache headers for production (configurable via `clientCacheHeaderTtl` and `serverCacheHeaderTtl`)
|
|
755
|
+
- Disables caching when `liveEdit` is enabled
|
|
756
|
+
|
|
757
|
+
Cache headers set:
|
|
758
|
+
- `Cache-Control`: Client-side caching
|
|
759
|
+
- `CDN-Cache-Control`: CDN caching
|
|
760
|
+
- `Vercel-CDN-Cache-Control`: Vercel-specific caching
|
|
761
|
+
|
|
762
|
+
### Live Edit Mode
|
|
763
|
+
|
|
764
|
+
When `liveEdit` is enabled, the integration:
|
|
765
|
+
- Injects JavaScript to enable page refresh from the Flyo interface
|
|
766
|
+
- Wires up all elements with `data-flyo-uid` for direct editing
|
|
767
|
+
- Highlights and enables click-to-edit functionality
|
|
768
|
+
- Shows fallback components when blocks are missing
|
|
769
|
+
|
|
770
|
+
## Best Practices
|
|
771
|
+
|
|
772
|
+
### Component Organization
|
|
773
|
+
|
|
774
|
+
Organize your Flyo components in a dedicated directory (default: `src/components/flyo`):
|
|
775
|
+
|
|
776
|
+
```
|
|
777
|
+
src/
|
|
778
|
+
components/
|
|
779
|
+
flyo/
|
|
780
|
+
Text.astro
|
|
781
|
+
CardsGrid.astro
|
|
782
|
+
Hero.astro
|
|
783
|
+
wysiwyg/
|
|
784
|
+
Image.astro
|
|
785
|
+
Video.astro
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
### Error Handling
|
|
789
|
+
|
|
790
|
+
Always wrap API calls in try-catch blocks and return appropriate responses:
|
|
791
|
+
|
|
792
|
+
```astro
|
|
793
|
+
---
|
|
794
|
+
let page;
|
|
795
|
+
try {
|
|
796
|
+
page = await usePagesApi().page({ slug });
|
|
797
|
+
} catch (e) {
|
|
798
|
+
return new Response("Not Found", {
|
|
799
|
+
status: 404,
|
|
800
|
+
statusText: "Page Not Found"
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
---
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
### Environment Variables
|
|
807
|
+
|
|
808
|
+
Use environment variables for sensitive configuration:
|
|
809
|
+
|
|
810
|
+
```bash
|
|
811
|
+
# .env
|
|
812
|
+
FLYO_ACCESS_TOKEN=your_token_here
|
|
813
|
+
FLYO_LIVE_EDIT=true
|
|
814
|
+
```
|
|
815
|
+
|
|
816
|
+
### TypeScript Support
|
|
817
|
+
|
|
818
|
+
The package is fully typed and exports TypeScript types from `@flyo/nitro-typescript`:
|
|
819
|
+
|
|
820
|
+
```typescript
|
|
821
|
+
import type { Block, Page, Entity } from "@flyo/nitro-typescript";
|
|
822
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { useFlyoIntegration, useConfig } from "../index";
|
|
3
|
+
|
|
4
|
+
const integration = useFlyoIntegration();
|
|
5
|
+
const config = await useConfig(Astro);
|
|
6
|
+
|
|
7
|
+
// Get environment variables
|
|
8
|
+
const mode = import.meta.env.MODE;
|
|
9
|
+
const vercelDeploymentId = import.meta.env.VERCEL_DEPLOYMENT_ID || '-';
|
|
10
|
+
const vercelGitCommitSha = import.meta.env.VERCEL_GIT_COMMIT_SHA || '-';
|
|
11
|
+
|
|
12
|
+
// Get token and determine type
|
|
13
|
+
const token = integration.options.accessToken || '';
|
|
14
|
+
const tokenType = token.startsWith('p-') ? 'production' : (token.startsWith('d-') ? 'develop' : 'unknown');
|
|
15
|
+
|
|
16
|
+
// Get live edit / debug status
|
|
17
|
+
const debug = integration.options.liveEdit;
|
|
18
|
+
|
|
19
|
+
// Get API version from config.nitro
|
|
20
|
+
const apiVersion = config.nitro?.version?.toString() || '-';
|
|
21
|
+
const apiLastUpdate = config.nitro?.updated_at
|
|
22
|
+
? new Date(config.nitro.updated_at * 1000).toLocaleString('de-CH', {
|
|
23
|
+
day: '2-digit',
|
|
24
|
+
month: '2-digit',
|
|
25
|
+
year: 'numeric',
|
|
26
|
+
hour: '2-digit',
|
|
27
|
+
minute: '2-digit'
|
|
28
|
+
})
|
|
29
|
+
: '-';
|
|
30
|
+
|
|
31
|
+
const debugInfo = [
|
|
32
|
+
`liveedit:${debug}`,
|
|
33
|
+
`mode:${mode}`,
|
|
34
|
+
`apiversion:${apiVersion}`,
|
|
35
|
+
`apiversiondate:${apiLastUpdate}`,
|
|
36
|
+
`tokentype:${tokenType}`,
|
|
37
|
+
`did:${vercelDeploymentId}`,
|
|
38
|
+
`csha:${vercelGitCommitSha}`
|
|
39
|
+
].join(' | ');
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
<Fragment set:html={`<!-- ${debugInfo} -->`} />
|