@nuasite/nua 0.14.1 → 0.15.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.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/src/integration.ts +28 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuasite/nua",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "module": "src/index.ts",
@@ -39,11 +39,11 @@
39
39
  "@astrojs/mdx": "5.0.0",
40
40
  "@astrojs/rss": "4.0.17",
41
41
  "@astrojs/sitemap": "3.7.1",
42
- "@nuasite/llm-enhancements": "0.14.1",
43
- "@nuasite/cli": "0.14.1",
44
- "@nuasite/cms": "0.14.1",
45
- "@nuasite/components": "0.14.1",
46
- "@nuasite/core": "0.14.1",
42
+ "@nuasite/llm-enhancements": "0.15.0",
43
+ "@nuasite/cli": "0.15.0",
44
+ "@nuasite/cms": "0.15.0",
45
+ "@nuasite/components": "0.15.0",
46
+ "@nuasite/core": "0.15.0",
47
47
  "@tailwindcss/vite": "^4.2.1",
48
48
  "@tailwindcss/typography": "^0.5.19",
49
49
  "astro": "^6.0.2",
@@ -3,16 +3,24 @@ import sitemap from '@astrojs/sitemap'
3
3
  import cms from '@nuasite/cms'
4
4
  import tailwindcss from '@tailwindcss/vite'
5
5
  import type { AstroIntegration } from 'astro'
6
+ import { writeFile } from 'node:fs/promises'
6
7
  import pageMarkdown from '../../llm-enhancements/src'
7
8
  import { type NuaIntegrationOptions, resolveOptions } from './types'
8
9
 
10
+ interface NormalizedRedirect {
11
+ from: string
12
+ to: string
13
+ code: number
14
+ }
15
+
9
16
  export default function nua(options: NuaIntegrationOptions = {}): AstroIntegration {
10
17
  const resolved = resolveOptions(options)
18
+ let capturedRedirects: NormalizedRedirect[] = []
11
19
 
12
20
  return {
13
21
  name: '@nuasite/nua',
14
22
  hooks: {
15
- 'astro:config:setup': ({ updateConfig, command, injectScript, logger }) => {
23
+ 'astro:config:setup': ({ config, updateConfig, command, injectScript, logger }) => {
16
24
  const integrations: AstroIntegration[] = []
17
25
  const vitePlugins = []
18
26
 
@@ -65,14 +73,33 @@ export default function nua(options: NuaIntegrationOptions = {}): AstroIntegrati
65
73
  )
66
74
  }
67
75
 
76
+ // Capture and strip Astro redirects to generate _redirects file instead of meta-refresh HTML
77
+ const astroRedirects = config.redirects ?? {}
78
+ capturedRedirects = Object.entries(astroRedirects).map(([from, value]) => {
79
+ const destination = typeof value === 'string' ? value : value.destination
80
+ const code = typeof value === 'string' ? 301 : (value.status ?? 301)
81
+ const normalizedFrom = from.replace(/\[\.\.\.[\w]+\]/g, '*')
82
+ const normalizedTo = destination.replace(/\[\.\.\.[\w]+\]/g, ':splat')
83
+ return { from: normalizedFrom, to: normalizedTo, code }
84
+ })
85
+
68
86
  // Inject Vite plugins and integrations
69
87
  updateConfig({
88
+ redirects: {},
70
89
  vite: {
71
90
  plugins: vitePlugins,
72
91
  },
73
92
  integrations,
74
93
  })
75
94
  },
95
+ 'astro:build:done': async ({ dir, logger }) => {
96
+ if (capturedRedirects.length === 0) return
97
+ const lines = capturedRedirects.map(r => `${r.from} ${r.to} ${r.code}`)
98
+ const content = lines.join('\n') + '\n'
99
+ const filePath = new URL('_redirects', dir)
100
+ await writeFile(filePath, content, 'utf-8')
101
+ logger.info(`Generated _redirects with ${capturedRedirects.length} rules`)
102
+ },
76
103
  },
77
104
  }
78
105
  }