@flyo/nitro-astro 1.4.4 → 2.0.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/middleware.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { defineMiddleware } from "astro:middleware";
2
+ import { useConfigApi, useFlyoIntegration } from "./index.ts";
3
+
4
+ let resolvedValue;
5
+
6
+ async function getConfigPromise(context) {
7
+ if (resolvedValue) {
8
+ // If the value is already resolved, return a resolved promise with the value
9
+ return resolvedValue;
10
+ }
11
+
12
+ // Fetch the config and store the resolved value
13
+ const value = await useConfigApi().config({
14
+ lang: context.currentLocale,
15
+ });
16
+ resolvedValue = value;
17
+ return value;
18
+ }
19
+
20
+ export const onRequest = defineMiddleware(async (context, next) => {
21
+ context.locals.config = getConfigPromise(context);
22
+
23
+ const liveEditEnabled = useFlyoIntegration().options.liveEdit;
24
+
25
+ if (!liveEditEnabled) {
26
+ const response = await next();
27
+
28
+ response.headers.set(
29
+ "Vercel-CDN-Cache-Control",
30
+ `max-age=${useFlyoIntegration().options.serverCacheHeaderTtl}`
31
+ );
32
+ response.headers.set(
33
+ "CDN-Cache-Control",
34
+ `max-age=${useFlyoIntegration().options.serverCacheHeaderTtl}`
35
+ );
36
+ response.headers.set(
37
+ "Cache-Control",
38
+ `max-age=${useFlyoIntegration().options.clientCacheHeaderTtl}`
39
+ );
40
+
41
+ return response;
42
+ }
43
+
44
+ return next();
45
+ });
package/module.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
1
3
  declare module "virtual:*" {
2
- const component: any;
3
- export default component;
4
- }
4
+ const component: any;
5
+ export default component;
6
+ }
package/package.json CHANGED
@@ -1,19 +1,23 @@
1
1
  {
2
2
  "name": "@flyo/nitro-astro",
3
- "version": "1.4.4",
4
- "description": "Astro Framework",
3
+ "version": "2.0.0",
4
+ "description": "Nitro Astro connecting Flyo Headless to Astro",
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
+ "scripts": {
8
+ "dev": "vite build --watch",
9
+ "build": "vite build"
10
+ },
11
+ "dependencies": {
12
+ "@flyo/nitro-typescript": "^1.0.9"
13
+ },
14
+ "devDependencies": {
15
+ "astro": "^4.10.1",
16
+ "typescript": "5.4.5",
17
+ "@types/node": "20.12.11",
18
+ "vite": "^5.2.13",
19
+ "vite-plugin-dts": "^3.9.1"
20
+ },
17
21
  "exports": {
18
22
  ".": {
19
23
  "types": "./dist/index.d.ts",
@@ -56,7 +60,9 @@
56
60
  "require": "./components/MetaInfoPage.ts"
57
61
  },
58
62
  "./sitemap.ts": "./sitemap.ts",
59
- "./cdn.ts": "./cdn.ts"
63
+ "./middleware.ts": "./middleware.ts",
64
+ "./cdn.ts": "./cdn.ts",
65
+ "./toolbar.ts": "./toolbar.ts"
60
66
  },
61
67
  "type": "module",
62
68
  "files": [
@@ -64,27 +70,30 @@
64
70
  "dist",
65
71
  "components",
66
72
  "sitemap.ts",
67
- "cdn.ts"
73
+ "cdn.ts",
74
+ "middleware.ts"
68
75
  ],
69
76
  "types": "./dist/index.d.ts",
70
77
  "author": "Basil Suter <git@nadar.io>",
71
78
  "license": "MIT",
72
- "scripts": {
73
- "release": "npm publish --access=public",
74
- "build": "vite build"
79
+ "release": {
80
+ "branches": [
81
+ "main",
82
+ {
83
+ "name": "next",
84
+ "prerelease": true
85
+ },
86
+ {
87
+ "name": "alpha",
88
+ "prerelease": true
89
+ }
90
+ ]
75
91
  },
76
- "devDependencies": {
77
- "astro": "^4.2.4",
78
- "typescript": "5.3.3",
79
- "vite": "^5.0.12",
80
- "vite-plugin-dts": "^3.7.2"
92
+ "publishConfig": {
93
+ "access": "public"
81
94
  },
82
95
  "repository": {
83
96
  "type": "git",
84
97
  "url": "https://github.com/flyocloud/nitro-astro"
85
- },
86
- "dependencies": {
87
- "@flyo/nitro-typescript": "^1.0.7",
88
- "nanostores": "^0.10.0"
89
98
  }
90
99
  }
package/sitemap.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { useSitemapApi } from "@flyo/nitro-astro"
1
+ import { useSitemapApi } from "./index.ts";
2
+ import type { AstroGlobal } from "astro";
2
3
 
3
4
  function buildUrl(path: string, domain: string) {
4
- return `${domain.replace(/\/$/, '')}/${path.replace(/^\//, '')}`;
5
+ return `${domain.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
5
6
  }
6
7
 
7
- export async function GET(config: any) {
8
+ export async function GET(config: AstroGlobal) {
8
9
  const sitemap = await useSitemapApi().sitemap();
9
10
 
10
11
  let xml = '<?xml version="1.0" encoding="UTF-8"?>';
@@ -12,22 +13,22 @@ export async function GET(config: any) {
12
13
 
13
14
  const routes = [];
14
15
  for (const item of sitemap) {
15
- if (item.entity_type === 'nitro-page') {
16
+ if (item.entity_type === "nitro-page") {
16
17
  if (routes.includes(item.entity_slug)) {
17
18
  continue;
18
19
  }
19
20
  routes.push(item.entity_slug);
20
21
  xml += `<url><loc>${buildUrl(item.entity_slug, config.site.origin)}</loc></url>`;
21
22
  } else if (item.routes?.detail) {
22
- xml += `<url><loc>${buildUrl(item.routes['detail'], config.site.origin)}</loc></url>`;
23
+ xml += `<url><loc>${buildUrl(item.routes["detail"], config.site.origin)}</loc></url>`;
23
24
  }
24
25
  }
25
26
 
26
- xml += '</urlset>';
27
+ xml += "</urlset>";
27
28
 
28
29
  return new Response(xml, {
29
30
  headers: {
30
- 'Content-Type': 'application/xml'
31
- }
32
- })
33
- }
31
+ "Content-Type": "application/xml",
32
+ },
33
+ });
34
+ }
package/README.md DELETED
@@ -1,167 +0,0 @@
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 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`:
22
-
23
- ```js
24
- import flyoNitroIntegration from '@flyo/nitro-astro';
25
-
26
- export default defineConfig({
27
- site: "https://myflyowebsite.com", // required to make the sitemap.xml work
28
- integrations: [
29
- flyoNitroIntegration({
30
- accessToken: 'ADD_YOUR_TOKEN_HERE', // Switch between dev and prod tokens depending on the environment
31
- liveEdit: true, // Enable on dev and preview systems for application reloading in the Flyo preview frame upon changes
32
- components: {
33
- // 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
34
- // [!] Adding new elements requires restarting the development process
35
- "FlyoElementName": "AstroElementName",
36
- "AnotherFlyoElement": "subfolder/AnotherFlyoElement"
37
- }
38
- })
39
- ],
40
- output: 'server'
41
- });
42
- ```
43
-
44
- > The nitro astro integration requires an SSR setup which is done by using `output: 'server'`.
45
-
46
- ### Pages
47
-
48
- Add a `[...slug].astro` file in the pages directory with the following example content as a catch-all CMS handler:
49
-
50
- ```astro
51
- ---
52
- import Layout from '../layouts/Layout.astro';
53
- import { usePagesApi } from '@flyo/nitro-astro';
54
- import FlyoNitroPage from '@flyo/nitro-astro/FlyoNitroPage.astro'
55
- import MetaInfoPage from '@flyo/nitro-astro/MetaInfoPage.astro';
56
-
57
- const { slug } = Astro.params;
58
- let page;
59
- try {
60
- page = await usePagesApi().page({slug: slug === undefined ? '' : slug})
61
- } catch (e) {
62
- return new Response(e.body.name, {
63
- status: 404,
64
- statusText: 'Page Not Found'
65
- });
66
- }
67
- ---
68
- <Layout title={page.title}>
69
- <MetaInfoPage page={page} slot="head" />
70
- <FlyoNitroPage page={page} />
71
- </Layout>
72
- ```
73
-
74
- To receive the config in the layout in `src/layouts/Layout.astro`:
75
-
76
- ```astro
77
- ---
78
- import { useConfigApi } from "@flyo/nitro-astro";
79
-
80
- const config = await useConfigApi().config();
81
- const { title } = Astro.props;
82
- const currentPath = Astro.url.pathname;
83
- ---
84
- <!doctype html>
85
- <html lang="en">
86
- <head>
87
- <title>{title}</title>
88
- <meta charset="UTF-8" />
89
- <meta name="viewport" content="width=device-width" />
90
- <!-- Auto-inject meta information for pages and entities -->
91
- <slot name="head" />
92
- </head>
93
- <body>
94
- {config.containers.nav.items.map((item: object) => (
95
- <a style="background-color: red; color: white" href={item.href} class={`nav-class ${currentPath === item.href ? 'text-red' : ''}`}>
96
- {item.label}<br />
97
- </a>
98
- ))}
99
- <div class="container">
100
- <slot />
101
- </div>
102
- </body>
103
- </html>
104
- ```
105
-
106
- ### Blocks
107
-
108
- Block Component Example (which are mostly located in `src/components/flyo`):
109
-
110
- ```astro
111
- ---
112
- import { Image } from "astro:assets"
113
- import { editableBlock } from '@flyo/nitro-astro'
114
- import BlockSlot from '@flyo/nitro-astro/BlockSlot.astro'
115
- const { block } = Astro.props;
116
- ---
117
- <!-- Make the block editable if necessary -->
118
- <div {...editableBlock(block)}>
119
-
120
- <!-- Content variable -->
121
- <div set:html={block.content.content.html} />
122
-
123
- <!-- Handling items -->
124
- {block.items.map((item: object) => (
125
- <div>
126
- { item.title }
127
- <a href={item.link.routes.detail}>Go to Detail</a>
128
- </div>
129
- ))}
130
-
131
- <!-- Image Proxy -->
132
- <Image src={block.content.image.source} alt={block.content.alt ?? ''} width={1920} height={768} />
133
-
134
- <!-- Handling slots -->
135
- <BlockSlot slot={block.slots.mysuperslotname} />
136
- </div>
137
- ```
138
-
139
- ### Entities
140
-
141
- Entity Detail Example, for a file which is located in `src/pages/blog/[slug].astro`:
142
-
143
- ```astro
144
- ---
145
- import Layout from '../../layouts/Layout.astro';
146
- import { useEntitiesApi } from '@flyo/nitro-astro';
147
- import MetaInfoEntity from '@flyo/nitro-astro/MetaInfoEntity.astro';
148
-
149
- const { slug } = Astro.params;
150
- let response = null;
151
- try {
152
- response = await useEntitiesApi().entityBySlug({ slug });
153
- } catch (e) {
154
- return new Response(e.body, {
155
- status: 404,
156
- statusText: 'Entity Not Found'
157
- });
158
- }
159
- const isProd = import.meta.env.PROD;
160
- ---
161
- <Layout>
162
- <MetaInfoEntity response={response} slot="head" />
163
- <h1>{ slug }</h1>
164
- <img src={ response.model.image.source } style="width:100%" />
165
- </Layout>
166
- { isProd && <script is:inline define:vars={{ api: response.entity.entity_metric.api }}>fetch(api)</script> }
167
- ```
package/dist/cdn.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Create an astro ExternalImageService for flyo where the base url with transormations looks like https://storage.flyo.cloud/image_7a158241.jpg/thumb/250x250?format=webp
3
- */
4
- import type { ExternalImageService } from "astro";
5
- declare const service: ExternalImageService;
6
- export default service;
@@ -1,2 +0,0 @@
1
- import BlockSlot from "./BlockSlot.astro";
2
- export default BlockSlot;
@@ -1,2 +0,0 @@
1
- import FallbackComponent from "./FallbackComponent.astro";
2
- export default FallbackComponent;
@@ -1,2 +0,0 @@
1
- import FlyoNitroBlock from "./FlyoNitroBlock.astro";
2
- export default FlyoNitroBlock;
@@ -1,2 +0,0 @@
1
- import FlyoNitroPage from "./FlyoNitroPage.astro";
2
- export default FlyoNitroPage;
@@ -1,2 +0,0 @@
1
- import MetaInfo from "./MetaInfo.astro";
2
- export default MetaInfo;
@@ -1,2 +0,0 @@
1
- import MetaInfoEntity from "./MetaInfoEntity.astro";
2
- export default MetaInfoEntity;
@@ -1,2 +0,0 @@
1
- import MetaInfoPage from "./MetaInfoPage.astro";
2
- export default MetaInfoPage;
package/dist/index.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { AstroIntegration } from "astro";
2
- import { Configuration, ConfigApi, EntitiesApi, PagesApi, SearchApi, SitemapApi, VersionApi, Block, ConfigResponse } from '@flyo/nitro-typescript';
3
- export type IntegrationOptions = {
4
- accessToken: string;
5
- liveEdit: any;
6
- componentsDir: string;
7
- components: object;
8
- fallbackComponent?: string;
9
- };
10
- export declare function useConfiguration(): Configuration;
11
- export declare function useConfigApi(): ConfigApi;
12
- export declare function useConfig(): Promise<ConfigResponse>;
13
- export declare function useEntitiesApi(): EntitiesApi;
14
- export declare function usePagesApi(): PagesApi;
15
- export declare function useSearchApi(): SearchApi;
16
- export declare function useSitemapApi(): SitemapApi;
17
- export declare function useVersionApi(): VersionApi;
18
- export declare function editableBlock(block: Block): object;
19
- export default function flyoNitroIntegration(options: IntegrationOptions): AstroIntegration;
package/dist/sitemap.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function GET(config: any): Promise<Response>;