@flyo/nitro-astro 1.4.0 → 1.4.2

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 CHANGED
@@ -1,9 +1,24 @@
1
- # nitro-astro
2
- Flyo Nitro for Astro Framework [foo]
1
+ # Flyo Nitro Astro Framework Integration
3
2
 
4
- ## Install
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:
5
4
 
6
- The astro.config.mjs file:
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 package, execute the following command:
16
+
17
+ ```bash
18
+ astro add @flyo/nitro-astro
19
+ ```
20
+
21
+ Then, revise and adjust the configuration in your `astro.config.mjs`:
7
22
 
8
23
  ```js
9
24
  import flyoNitroIntegration from '@flyo/nitro-astro';
@@ -11,11 +26,11 @@ import flyoNitroIntegration from '@flyo/nitro-astro';
11
26
  export default defineConfig({
12
27
  integrations: [
13
28
  flyoNitroIntegration({
14
- accessToken: 'N0vxfdfd275jSoEvFion7dfdfsdfasdfasd4n95zFroAZ', // switch between dev and prod token depending on the enviroment
15
- liveEdit: true, // on dev and preview system this should be enabled, as this allows to reload the application inside the flyo preview frame when things change
29
+ accessToken: 'ADD_YOUR_TOKEN_HERE', // Switch between dev and prod tokens depending on the environment
30
+ liveEdit: true, // Enable on dev and preview systems for application reloading in the Flyo preview frame upon changes
16
31
  components: {
17
- // define where the flyo components are located the suffix .astro is no required. Object key is the value from flyo, while object value is the component inside astro components folder
18
- // [!] Adding new elements requires the dev process to restart (it seems)
32
+ // 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
33
+ // [!] Adding new elements requires restarting the development process
19
34
  "FlyoElementName": "AstroElementName",
20
35
  "AnotherFlyoElement": "subfolder/AnotherFlyoElement"
21
36
  }
@@ -24,89 +39,121 @@ export default defineConfig({
24
39
  });
25
40
  ```
26
41
 
27
- Add a `[...slug].astro` file in pages directory with the following exmaple content as a catch all cms handler:
42
+ ### Pages
43
+
44
+ Add a `[...slug].astro` file in the pages directory with the following example content as a catch-all CMS handler:
28
45
 
29
46
  ```astro
30
47
  ---
31
48
  import Layout from '../layouts/Layout.astro';
32
- import { PagesApi } from '@flyo/nitro-js'
49
+ import { usePagesApi } from '@flyo/nitro-astro';
33
50
  import FlyoNitroPage from '@flyo/nitro-astro/FlyoNitroPage.astro'
51
+ import MetaInfoPage from '@flyo/nitro-astro/MetaInfoPage.astro';
34
52
 
35
53
  const { slug } = Astro.params;
36
- const page = await new PagesApi().page({slug: slug === undefined ? '' : slug})
54
+ let page;
55
+ try {
56
+ page = await usePagesApi().page({slug: slug === undefined ? '' : slug})
57
+ } catch (e) {
58
+ return new Response(e.body.name, {
59
+ status: e.status,
60
+ statusText: 'Not Found'
61
+ });
62
+ }
37
63
  ---
38
64
  <Layout title={page.title}>
39
- <FlyoNitroPage page={page} />
65
+ <MetaInfoPage page={page} slot="head" />
66
+ <FlyoNitroPage page={page} />
40
67
  </Layout>
41
68
  ```
42
69
 
43
- To recieve the config in the layout:
70
+ To receive the config in the layout:
44
71
 
45
72
  ```astro
46
73
  ---
47
- import { ConfigApi } from '@flyo/nitro-js';
74
+ import { useConfigApi } from "@flyo/nitro-astro";
48
75
 
49
- const config = await new ConfigApi().config()
76
+ const config = await useConfigApi().config();
50
77
  const { title } = Astro.props;
51
78
  ---
52
79
  <!doctype html>
53
80
  <html lang="en">
54
- <head>
55
- <title>{title}</title>
56
- </head>
57
- <body>
58
- {config.containers.nav.items.map((item: object) => (
59
- <a style="background-color: red; color: white" href={item.href}>
60
- {item.label}<br />
61
- </a>
62
- ))}
63
- <div class="container">
64
- <slot />
65
- </div>
66
- </body>
81
+ <head>
82
+ <title>{title}</title>
83
+ <!-- Auto-inject meta information for pages and entities -->
84
+ <slot name="head" />
85
+ </head>
86
+ <body>
87
+ {config.containers.nav.items.map((item: object) => (
88
+ <a style="background-color: red; color: white" href={item.href}>
89
+ {item.label}<br />
90
+ </a>
91
+ ))}
92
+ <div class="container">
93
+ <slot />
94
+ </div>
95
+ </body>
67
96
  </html>
68
97
  ```
69
98
 
70
- Entity Detail Example
71
-
72
- ```astro
73
- ---
74
- import { EntitiesApi } from '@flyo/nitro-js'
75
-
76
- const { slug } = Astro.params;
77
- const data = await new EntitiesApi().entityBySlug(slug);
78
- const isProd = import.meta.env.PROD;
79
- ---
80
- <h1>{ slug }</h1>
81
- <img src={ data.model.image.source } style="width:100%" />
82
- { isProd && <script is:inline define:vars={{ api: data.entity.entity_metric.api }}>fetch(api)</script> }
83
- ```
99
+ ### Blocks
84
100
 
85
101
  Block Component Example:
86
102
 
87
103
  ```astro
88
104
  ---
89
- import FlyoNitroBlock from '@flyo/nitro-astro/FlyoNitroBlock.astro';
90
- const { block } = Astro.props
105
+ import { Image } from "astro:assets"
106
+ import { editableBlock } from '@flyo/nitro-astro'
107
+ import BlockSlot from '@flyo/nitro-astro/BlockSlot.astro'
108
+ const { block } = Astro.props;
91
109
  ---
92
- <!-- content variable -->
93
- <div set:html={block.content.content.html} />
110
+ <!-- Make the block editable if necessary -->
111
+ <div {...editableBlock(block)}>
112
+
113
+ <!-- Content variable -->
114
+ <div set:html={block.content.content.html} />
94
115
 
95
- <!-- handling items -->
96
- {block.items.map((item: object) => (
116
+ <!-- Handling items -->
117
+ {block.items.map((item: object) => (
97
118
  <div>
98
- { item.title }
99
- <a href={item.link.routes.detail}>Go to Detail</a>
119
+ { item.title }
120
+ <a href={item.link.routes.detail}>Go to Detail</a>
100
121
  </div>
101
- ))}
122
+ ))}
102
123
 
103
- <!-- handling slots -->
104
- {block.slots.slotcontainername.content.map((block: object) => (
105
- <FlyoNitroBlock block={block} />
106
- ))}
124
+ <!-- Image Proxy -->
125
+ <Image src={block.content.image.source} alt={block.content.alt ?? ''} width={1920} height={768} />
126
+
127
+ <!-- Handling slots -->
128
+ <BlockSlot slot={block.slots.mysuperslotname} />
129
+ </div>
107
130
  ```
108
131
 
109
- ## Development
132
+ ### Entities
133
+
134
+ Entity Detail Example:
110
135
 
111
- 1. `npm install`
112
- 2. `npm run build`
136
+ ```astro
137
+ ---
138
+ import { useEntitiesApi } from '@flyo/nitro-astro';
139
+ import MetaInfoEntity from '@flyo/nitro-astro/MetaInfoEntity.astro';
140
+
141
+ const { slug } = Astro.params;
142
+ let response = null;
143
+ try {
144
+ response = await useEntitiesApi().entityBySlug({ slug });
145
+ } catch (e) {
146
+ return new Response(e.body, {
147
+ status: e.status,
148
+ statusText: 'Not Found'
149
+ });
150
+ }
151
+ const isProd = import.meta.env.PROD;
152
+ ---
153
+ <Layout>
154
+ <MetaInfoEntity response={response} slot="head" />
155
+ <h1>{ slug }</h1>
156
+ <img src={ response.model.image.source } style="width:100%" />
157
+ </Layout>
158
+ { isProd && <script is:inline define:vars={{ api: response.entity.entity_metric.api }}>fetch(api)</script> }
159
+ ```
@@ -2,32 +2,23 @@
2
2
  const { title, image, description, jsonld } = Astro.props;
3
3
  const jsonLdString = jsonld ? JSON.stringify(jsonld) : null;
4
4
  ---
5
-
6
- <!-- Title Meta Tags -->
7
5
  {title && (
8
6
  <meta name="title" content={title} />
9
7
  <meta property="og:title" content={title} />
10
8
  <meta name="twitter:title" content={title} />
11
9
  )}
12
-
13
- <!-- Description Meta Tags -->
14
10
  {description && (
15
11
  <meta name="description" content={description} />
16
12
  <meta property="og:description" content={description} />
17
13
  <meta name="twitter:description" content={description} />
18
14
  )}
19
-
20
- <!-- Image Meta Tags -->
21
15
  {image && (
22
16
  <meta name="image" content={image} />
23
17
  <meta property="og:image" content={image} />
24
18
  <meta name="twitter:image" content={image} />
25
19
  )}
26
-
27
- <!-- Other Meta Tags -->
28
- <meta property="og:type" content="website" />
29
- <meta name="twitter:card" content="summary_large_image" />
30
-
31
20
  {jsonLdString && (
32
21
  <script type="application/ld+json" set:html={ jsonLdString } />
33
- )}
22
+ )}
23
+ <meta property="og:type" content="website" />
24
+ <meta name="twitter:card" content="summary_large_image" />
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "@flyo/nitro-astro",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Astro Framework",
5
5
  "main": "./dist/nitro-astro.js",
6
6
  "module": "./dist/nitro-astro.mjs",
7
+ "keywords": [
8
+ "astro-integration",
9
+ "astro-component",
10
+ "astro",
11
+ "flyo",
12
+ "headless",
13
+ "cms",
14
+ "nitro",
15
+ "withastro"
16
+ ],
7
17
  "exports": {
8
18
  ".": {
9
19
  "types": "./dist/index.d.ts",