@flyo/nitro-astro 1.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 ADDED
@@ -0,0 +1,6 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ declare module "virtual:*" {
4
+ const component: any;
5
+ export default component;
6
+ }
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "@flyo/nitro-astro",
3
+ "version": "1.0.0",
4
+ "description": "Nitro Astro connecting Flyo Headless to Astro",
5
+ "main": "./dist/nitro-astro.js",
6
+ "module": "./dist/nitro-astro.mjs",
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
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/nitro-astro.mjs",
25
+ "require": "./dist/nitro-astro.js"
26
+ },
27
+ "./FallbackComponent.astro": {
28
+ "types": "./components/FallbackComponent.ts",
29
+ "import": "./components/FallbackComponent.ts",
30
+ "require": "./components/FallbackComponent.ts"
31
+ },
32
+ "./FlyoNitroBlock.astro": {
33
+ "types": "./components/FlyoNitroBlock.ts",
34
+ "import": "./components/FlyoNitroBlock.ts",
35
+ "require": "./components/FlyoNitroBlock.ts"
36
+ },
37
+ "./FlyoNitroPage.astro": {
38
+ "types": "./components/FlyoNitroPage.ts",
39
+ "import": "./components/FlyoNitroPage.ts",
40
+ "require": "./components/FlyoNitroPage.ts"
41
+ },
42
+ "./BlockSlot.astro": {
43
+ "types": "./components/BlockSlot.ts",
44
+ "import": "./components/BlockSlot.ts",
45
+ "require": "./components/BlockSlot.ts"
46
+ },
47
+ "./MetaInfo.astro": {
48
+ "types": "./components/MetaInfo.ts",
49
+ "import": "./components/MetaInfo.ts",
50
+ "require": "./components/MetaInfo.ts"
51
+ },
52
+ "./MetaInfoEntity.astro": {
53
+ "types": "./components/MetaInfoEntity.ts",
54
+ "import": "./components/MetaInfoEntity.ts",
55
+ "require": "./components/MetaInfoEntity.ts"
56
+ },
57
+ "./MetaInfoPage.astro": {
58
+ "types": "./components/MetaInfoPage.ts",
59
+ "import": "./components/MetaInfoPage.ts",
60
+ "require": "./components/MetaInfoPage.ts"
61
+ },
62
+ "./sitemap.ts": "./sitemap.ts",
63
+ "./middleware.ts": "./middleware.ts",
64
+ "./cdn.ts": "./cdn.ts",
65
+ "./toolbar.ts": "./toolbar.ts"
66
+ },
67
+ "type": "module",
68
+ "files": [
69
+ "module.d.ts",
70
+ "dist",
71
+ "components",
72
+ "sitemap.ts",
73
+ "cdn.ts",
74
+ "middleware.ts"
75
+ ],
76
+ "types": "./dist/index.d.ts",
77
+ "author": "Basil Suter <git@nadar.io>",
78
+ "license": "MIT",
79
+ "release": {
80
+ "branches": [
81
+ "main",
82
+ {
83
+ "name": "next",
84
+ "prerelease": true
85
+ },
86
+ {
87
+ "name": "alpha",
88
+ "prerelease": true
89
+ }
90
+ ]
91
+ },
92
+ "publishConfig": {
93
+ "access": "public"
94
+ },
95
+ "repository": {
96
+ "type": "git",
97
+ "url": "https://github.com/flyocloud/nitro-astro"
98
+ }
99
+ }
package/sitemap.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { useSitemapApi } from "./index.ts";
2
+ import type { AstroGlobal } from "astro";
3
+
4
+ function buildUrl(path: string, domain: string) {
5
+ return `${domain.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
6
+ }
7
+
8
+ export async function GET(config: AstroGlobal) {
9
+ const sitemap = await useSitemapApi().sitemap();
10
+
11
+ let xml = '<?xml version="1.0" encoding="UTF-8"?>';
12
+ xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
13
+
14
+ const routes = [];
15
+ for (const item of sitemap) {
16
+ if (item.entity_type === "nitro-page") {
17
+ if (routes.includes(item.entity_slug)) {
18
+ continue;
19
+ }
20
+ routes.push(item.entity_slug);
21
+ xml += `<url><loc>${buildUrl(item.entity_slug, config.site.origin)}</loc></url>`;
22
+ } else if (item.routes?.detail) {
23
+ xml += `<url><loc>${buildUrl(item.routes["detail"], config.site.origin)}</loc></url>`;
24
+ }
25
+ }
26
+
27
+ xml += "</urlset>";
28
+
29
+ return new Response(xml, {
30
+ headers: {
31
+ "Content-Type": "application/xml",
32
+ },
33
+ });
34
+ }