@altafusion/fugue-content 0.0.0-stage → 0.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +21 -0
  3. package/README.md +352 -2
  4. package/app/components/FugueContent404Page.vue +48 -0
  5. package/app/components/FugueContentAuthSignOut.vue +16 -0
  6. package/app/components/FugueContentContentPage.vue +33 -0
  7. package/app/components/FugueContentEditContent.vue +76 -0
  8. package/app/components/FugueContentEditorMenu.vue +60 -0
  9. package/app/components/FugueContentFooterActions.vue +32 -0
  10. package/app/components/FugueContentFragment.vue +53 -0
  11. package/app/components/FugueContentHeaderActions.vue +37 -0
  12. package/app/components/FugueContentLandingPage.vue +69 -0
  13. package/app/components/FugueContentLayoutArticle.vue +22 -0
  14. package/app/components/FugueContentLayoutArticleAside.vue +88 -0
  15. package/app/components/FugueContentLayoutLanding.vue +5 -0
  16. package/app/components/LandingHeroMedia.vue +91 -0
  17. package/app/components/content/CallToAction.vue +35 -0
  18. package/app/components/content/Hero.vue +34 -0
  19. package/app/composables/useFugueContentCatchAllRoute.ts +91 -0
  20. package/app/composables/useFugueContentFragment.ts +70 -0
  21. package/app/composables/useFugueContentI18n.ts +77 -0
  22. package/app/composables/useFugueContentLanding.ts +24 -0
  23. package/app/composables/useFugueContentPage.ts +37 -0
  24. package/app/composables/useFugueContentSettings.ts +140 -0
  25. package/app/composables/useFugueContentStudioEdit.ts +38 -0
  26. package/app/pages/[...slug].vue +7 -0
  27. package/app/pages/fragments/[slug].vue +25 -0
  28. package/app/pages/index.vue +7 -0
  29. package/app/pages/login.vue +70 -0
  30. package/app/plugins/auth-session-sync.client.ts +33 -0
  31. package/app/plugins/landing-component-registry.ts +15 -0
  32. package/app/plugins/landing-nav.ts +26 -0
  33. package/app/plugins/qe-tools.client.ts +28 -0
  34. package/app/plugins/seo-defaults.ts +4 -0
  35. package/app/plugins/settings-bridge.ts +14 -0
  36. package/app/plugins/shell-display-name.ts +18 -0
  37. package/app/plugins/studio-auto-open.client.ts +30 -0
  38. package/app/plugins/studio-dev-shortcut.client.ts +24 -0
  39. package/app/plugins/studio-footer-actions.client.ts +27 -0
  40. package/app/plugins/studio-footer-actions.server.ts +11 -0
  41. package/app/plugins/studio-hash-cleanup.client.ts +12 -0
  42. package/app/plugins/studio-header-actions.client.ts +30 -0
  43. package/app/plugins/studio-header-actions.server.ts +13 -0
  44. package/app/utils/studio-mount.ts +72 -0
  45. package/composables/useFugueContentAuthMode.ts +16 -0
  46. package/composables/useFugueContentAuthSignOut.ts +82 -0
  47. package/composables/useFugueContentPeekSession.ts +31 -0
  48. package/composables/useFugueContentStudioEditorEntry.ts +112 -0
  49. package/composables/useFugueContentStudioSession.ts +81 -0
  50. package/content.config.ts +199 -0
  51. package/content.d.ts +25 -0
  52. package/eslint.config.mjs +4 -0
  53. package/lib/404-defaults.ts +41 -0
  54. package/lib/article-i18n.ts +10 -0
  55. package/lib/auth-resolve.ts +74 -0
  56. package/lib/auth-utils.ts +44 -0
  57. package/lib/define-site.ts +156 -0
  58. package/lib/header-actions-registration.ts +42 -0
  59. package/lib/i18n-locales.ts +22 -0
  60. package/lib/i18n-utils.ts +136 -0
  61. package/lib/i18n.ts +2 -0
  62. package/lib/landing.ts +129 -0
  63. package/lib/login-redirect.ts +12 -0
  64. package/lib/netlify-ssr.ts +113 -0
  65. package/lib/page-toc.ts +14 -0
  66. package/lib/qe-tools/index.ts +36 -0
  67. package/lib/qe-tools/studio-drafts.ts +315 -0
  68. package/lib/qe-tools/types.ts +14 -0
  69. package/lib/settings-state.ts +1 -0
  70. package/lib/site-config-registry.ts +80 -0
  71. package/lib/studio-activation-gated.d.ts +20 -0
  72. package/lib/studio-activation-gated.js +127 -0
  73. package/lib/studio-auto-open.ts +26 -0
  74. package/lib/studio-cookies.d.ts +10 -0
  75. package/lib/studio-cookies.js +11 -0
  76. package/lib/studio-document-edit.ts +61 -0
  77. package/lib/studio-editor-visibility.ts +54 -0
  78. package/lib/studio-open.ts +7 -0
  79. package/lib/studio-session.ts +91 -0
  80. package/modules/i18n.ts +80 -0
  81. package/modules/landing-components.ts +95 -0
  82. package/modules/studio-auth-gate.ts +48 -0
  83. package/modules/studio-entry.ts +23 -0
  84. package/nuxt.config.ts +90 -0
  85. package/package.json +75 -3
  86. package/schemas/site-settings.schema.json +127 -0
  87. package/server/middleware/studio-oauth-redirect.ts +36 -0
  88. package/server/middleware/studio-provider-check.ts +59 -0
  89. package/server/plugins/studio-hash-cleanup.ts +8 -0
  90. package/tsconfig.build.json +22 -0
  91. package/tsconfig.json +20 -0
  92. package/types/site.ts +79 -0
@@ -0,0 +1,41 @@
1
+ export const FUGUE_CONTENT_404_DEFAULTS = {
2
+ statusCode: 404,
3
+ title: 'Page Not Found',
4
+ description: 'The page you requested does not exist or may have moved.',
5
+ actionLabel: 'Back to Home',
6
+ actionTo: '/'
7
+ } as const
8
+
9
+ /** i18n keys — translate in the app `i18n/locales/*.yaml` under `fugueContent404.*`. */
10
+ export const FUGUE_CONTENT_404_I18N_KEYS = {
11
+ title: 'fugueContent404.title',
12
+ description: 'fugueContent404.description',
13
+ actionLabel: 'fugueContent404.actionLabel'
14
+ } as const
15
+
16
+ export interface FugueContent404Copy {
17
+ title: string
18
+ description: string
19
+ actionLabel: string
20
+ }
21
+
22
+ export function resolveFugueContent404Copy(
23
+ t: (_key: string, _fallback: string) => string
24
+ ): FugueContent404Copy {
25
+ return {
26
+ title: t(FUGUE_CONTENT_404_I18N_KEYS.title, FUGUE_CONTENT_404_DEFAULTS.title),
27
+ description: t(FUGUE_CONTENT_404_I18N_KEYS.description, FUGUE_CONTENT_404_DEFAULTS.description),
28
+ actionLabel: t(FUGUE_CONTENT_404_I18N_KEYS.actionLabel, FUGUE_CONTENT_404_DEFAULTS.actionLabel)
29
+ }
30
+ }
31
+
32
+ export interface FugueContentPageRouteState {
33
+ loading: boolean
34
+ error: unknown
35
+ contentPage: unknown
36
+ i18nReady: boolean
37
+ }
38
+
39
+ export function isFugueContent404(state: FugueContentPageRouteState): boolean {
40
+ return state.i18nReady && !state.loading && !state.error && !state.contentPage
41
+ }
@@ -0,0 +1,10 @@
1
+ /** i18n keys — translate in the app `i18n/locales/*.yaml` under `cmsArticle.*`. */
2
+ export const FUGUE_CONTENT_ARTICLE_I18N_KEYS = {
3
+ onThisPage: 'cmsArticle.onThisPage',
4
+ editPage: 'cmsArticle.editPage'
5
+ } as const
6
+
7
+ export const FUGUE_CONTENT_ARTICLE_DEFAULTS = {
8
+ onThisPage: 'On This Page',
9
+ editPage: 'Edit'
10
+ } as const
@@ -0,0 +1,74 @@
1
+ import type { FugueContentSiteAuthConfig, FugueContentSiteAuthMode, FugueContentSiteConfig } from '../types/site'
2
+ import process from 'node:process'
3
+ import { isAuthEnabledAtBuild } from '@altafusion/fugue-simple-auth/lib/env'
4
+
5
+ export type ResolvedFugueContentSiteAuthMode = 'peek' | 'studio' | 'off'
6
+
7
+ export interface ResolvedFugueContentSiteAuth {
8
+ mode: ResolvedFugueContentSiteAuthMode
9
+ envPrefix: string
10
+ peekConfig?: FugueContentSiteAuthConfig
11
+ }
12
+
13
+ /** Build-time signal that Google Studio OAuth is configured on this deploy. */
14
+ export function isStudioGoogleConfigured(): boolean {
15
+ return Boolean(
16
+ process.env.STUDIO_GOOGLE_CLIENT_ID
17
+ && process.env.STUDIO_GOOGLE_CLIENT_SECRET
18
+ && process.env.STUDIO_GOOGLE_MODERATORS
19
+ )
20
+ }
21
+
22
+ function resolveEnvPrefix(config: FugueContentSiteConfig): string {
23
+ return config.auth?.envPrefix ?? 'SITE'
24
+ }
25
+
26
+ function resolvePeekConfig(config: FugueContentSiteConfig, envPrefix: string): FugueContentSiteAuthConfig | undefined {
27
+ if (!config.auth)
28
+ return undefined
29
+
30
+ return { ...config.auth, envPrefix: config.auth.envPrefix ?? envPrefix }
31
+ }
32
+
33
+ function isPeekEnvConfigured(config: FugueContentSiteConfig, envPrefix: string): boolean {
34
+ return Boolean(config.auth) && isAuthEnabledAtBuild(envPrefix)
35
+ }
36
+
37
+ /**
38
+ * Resolve the effective fugue-content-site auth mode from manifest + env.
39
+ *
40
+ * Hierarchy (`authMode: 'auto'`, default):
41
+ * 1. **`studio`** when Google Studio OAuth env is set — wins over peek even if **`SITE_ACCESS_KEY`** remains.
42
+ * 2. **`peek`** when an auth block exists and peek env is set (no Studio Google env).
43
+ * 3. **`off`** otherwise.
44
+ */
45
+ export function resolveFugueContentSiteAuth(config: FugueContentSiteConfig): ResolvedFugueContentSiteAuth {
46
+ const manifestMode: FugueContentSiteAuthMode = config.authMode ?? 'auto'
47
+ const envPrefix = resolveEnvPrefix(config)
48
+ const peekEnv = isPeekEnvConfigured(config, envPrefix)
49
+ const studioEnv = isStudioGoogleConfigured()
50
+
51
+ if (manifestMode === 'off')
52
+ return { mode: 'off', envPrefix }
53
+
54
+ if (manifestMode === 'studio')
55
+ return { mode: 'studio', envPrefix }
56
+
57
+ if (manifestMode === 'peek') {
58
+ const peekConfig = resolvePeekConfig(config, envPrefix)
59
+ if (peekConfig && peekEnv)
60
+ return { mode: 'peek', envPrefix, peekConfig }
61
+
62
+ return { mode: 'off', envPrefix }
63
+ }
64
+
65
+ // auto — Studio Google wins when both peek and Studio env are present.
66
+ if (studioEnv)
67
+ return { mode: 'studio', envPrefix }
68
+
69
+ const peekConfig = resolvePeekConfig(config, envPrefix)
70
+ if (peekConfig && peekEnv)
71
+ return { mode: 'peek', envPrefix, peekConfig }
72
+
73
+ return { mode: 'off', envPrefix }
74
+ }
@@ -0,0 +1,44 @@
1
+ import type { FugueContentSiteAuthConfig } from '../types/site'
2
+
3
+ /** Routes that bypass fugue-simple-auth in full-site peek mode (OAuth callbacks must stay reachable). */
4
+ export const studioPublicPrefixes = ['/_studio', '/__nuxt_studio/'] as const
5
+
6
+ /** Studio + OAuth paths gated when auth `mode` is `routes` (public brochure, editors only). */
7
+ export const fugueContentStudioProtectedRoutes = [
8
+ '/_studio',
9
+ '/_studio/**',
10
+ '/__nuxt_studio/**'
11
+ ] as const
12
+
13
+ function envPrefixSlug(envPrefix: string): string {
14
+ return envPrefix.toLowerCase().replace(/_/g, '-')
15
+ }
16
+
17
+ /** Build `runtimeConfig.public.fugueSimpleAuth` for defineFugueContentSite. */
18
+ export function buildFugueSimpleAuth(
19
+ config: FugueContentSiteAuthConfig,
20
+ options?: { includeStudioBypass?: boolean }
21
+ ) {
22
+ const slug = envPrefixSlug(config.envPrefix)
23
+ const includeStudioBypass = options?.includeStudioBypass ?? false
24
+
25
+ const mode = config.mode ?? 'routes'
26
+
27
+ return {
28
+ envPrefix: config.envPrefix,
29
+ mode,
30
+ cookieName: config.cookieName ?? `${slug}-auth`,
31
+ sessionLabel: config.sessionLabel ?? `${slug}-authenticated`,
32
+ loginDescription:
33
+ config.loginDescription ?? 'Enter the access key to open the content editor.',
34
+ publicPrefixes: [
35
+ '/_nuxt/',
36
+ '/__nuxt/',
37
+ ...(includeStudioBypass
38
+ ? studioPublicPrefixes
39
+ : []),
40
+ ...(config.publicPrefixes ?? [])
41
+ ],
42
+ protectedRoutes: config.protectedRoutes ?? []
43
+ }
44
+ }
@@ -0,0 +1,156 @@
1
+ import type { NuxtConfig } from 'nuxt/schema'
2
+ import type { FugueContentSiteConfig, FugueContentSiteStudioConfig } from '../types/site'
3
+ import { createRequire } from 'node:module'
4
+ import { dirname, join } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { createAppConfig } from '@altafusion/nuxt-base'
7
+ import { defu } from 'defu'
8
+ import { resolveFugueContentSiteAuth } from './auth-resolve'
9
+ import { buildFugueSimpleAuth, fugueContentStudioProtectedRoutes } from './auth-utils'
10
+ import { getDefaultI18nOptions } from './i18n-utils'
11
+ import { buildFugueContentSiteNetlifySsrConfig } from './netlify-ssr'
12
+
13
+ /** Install in each Studio-enabled app (devDependencies) — Vite pre-bundles CJS default exports */
14
+ export const studioViteOptimizeDeps = ['debug', 'extend', 'slugify'] as const
15
+
16
+ export { studioPublicPrefixes } from './auth-utils'
17
+
18
+ /** Resolve fugue-simple-auth from `@altafusion/fugue-content` — apps need not duplicate the dependency. */
19
+ export function resolveFugueSimpleAuthLayer(): string {
20
+ const fugueContentRoot = join(dirname(fileURLToPath(import.meta.url)), '..')
21
+ const require = createRequire(join(fugueContentRoot, 'package.json'))
22
+ return dirname(require.resolve('@altafusion/fugue-simple-auth'))
23
+ }
24
+
25
+ function buildStudioConfig(studio: FugueContentSiteStudioConfig) {
26
+ const { repository, route, git } = studio
27
+
28
+ return {
29
+ route: route ?? '/_studio',
30
+ repository: {
31
+ provider: repository.provider ?? 'github',
32
+ branch: repository.branch ?? 'main',
33
+ owner: repository.owner,
34
+ repo: repository.repo,
35
+ ...(repository.rootDir
36
+ ? { rootDir: repository.rootDir }
37
+ : {}),
38
+ ...(repository.private !== undefined
39
+ ? { private: repository.private }
40
+ : {})
41
+ },
42
+ ...(git
43
+ ? { git }
44
+ : {})
45
+ }
46
+ }
47
+
48
+ export type CreateAppConfigOptions = NonNullable<Parameters<typeof createAppConfig>[1]>
49
+
50
+ /**
51
+ * Build a Nuxt config for a Fugue Content site on `@altafusion/fugue-content`.
52
+ *
53
+ * Read access (optional): `@altafusion/fugue-simple-auth` via `auth` block.
54
+ * Edit/publish: Nuxt Studio (Google/GitHub OAuth — env-driven).
55
+ * Public site chrome: `@altafusion/shell` via `createAppConfig` + `@altafusion/fugue-theme`.
56
+ *
57
+ * Apps should keep a **`site.config.ts`** registry (named sections + `siteConfig` /
58
+ * `siteConfigTheme`) and a thin **`nuxt.config.ts`** that calls
59
+ * `defineFugueContentSite(siteConfig, siteConfigTheme)`. See **`@altafusion/fugue-content/site-config-registry`**
60
+ * and **`templates/fugue-content-site/site.config.ts`**.
61
+ *
62
+ * Production deploy with Studio and/or read gate: **`nuxt build` + Netlify SSR** — see
63
+ * developer-docs **[Pilot deploy checklist](/fugue-content/starter-template/pilot-deploy-checklist)**.
64
+ */
65
+ export function defineFugueContentSite(
66
+ config: FugueContentSiteConfig,
67
+ createAppOptions: CreateAppConfigOptions = {}
68
+ ): NuxtConfig {
69
+ const { studio, extraExtends, i18n, ...rest } = config
70
+ const resolvedAuth = resolveFugueContentSiteAuth(config)
71
+ const usePeekGate = resolvedAuth.mode === 'peek' && resolvedAuth.peekConfig
72
+
73
+ const defaultLocale = (i18n?.defaultLocale as string | undefined) ?? 'en'
74
+ const mergedI18n = i18n?.locales?.length
75
+ ? defu(i18n, getDefaultI18nOptions(defaultLocale), { langDir: 'locales' })
76
+ : undefined
77
+
78
+ const base = createAppConfig({
79
+ extends: [
80
+ '@altafusion/fugue-theme',
81
+ '@altafusion/shell',
82
+ ...(usePeekGate
83
+ ? [
84
+ resolveFugueSimpleAuthLayer()
85
+ ] as const
86
+ : []),
87
+ '@altafusion/fugue-content',
88
+ ...(extraExtends ?? [])
89
+ ],
90
+ ...(mergedI18n
91
+ ? { i18n: mergedI18n }
92
+ : {}),
93
+ ...rest
94
+ }, createAppOptions)
95
+
96
+ let result = defu({
97
+ runtimeConfig: {
98
+ public: {
99
+ fugueContent: {
100
+ authMode: resolvedAuth.mode
101
+ }
102
+ }
103
+ }
104
+ }, base) as NuxtConfig
105
+
106
+ if (usePeekGate) {
107
+ const peekConfig = resolvedAuth.peekConfig!
108
+ const peekScope = peekConfig.mode ?? 'routes'
109
+ const authConfig = peekScope === 'routes' && studio
110
+ ? {
111
+ ...peekConfig,
112
+ mode: peekScope,
113
+ protectedRoutes: [
114
+ ...fugueContentStudioProtectedRoutes,
115
+ ...(peekConfig.protectedRoutes ?? [])
116
+ ]
117
+ }
118
+ : { ...peekConfig, mode: peekScope }
119
+
120
+ result = defu({
121
+ runtimeConfig: {
122
+ public: {
123
+ fugueSimpleAuth: buildFugueSimpleAuth(authConfig, {
124
+ includeStudioBypass: Boolean(studio) && peekScope === 'full'
125
+ })
126
+ }
127
+ }
128
+ }, result) as NuxtConfig
129
+ }
130
+
131
+ if (!studio)
132
+ return result
133
+
134
+ const studioConfig = defu({
135
+ studio: buildStudioConfig(studio),
136
+ vite: {
137
+ optimizeDeps: {
138
+ include: [...studioViteOptimizeDeps],
139
+ // Scanner treats Nuxt's `#components` import inside `@nuxtjs/i18n` as a
140
+ // missing package export. `include` still pre-bundles the Studio CJS deps.
141
+ noDiscovery: true
142
+ }
143
+ },
144
+ build: {
145
+ transpile: ['nuxt-studio']
146
+ }
147
+ }, result) as NuxtConfig
148
+
149
+ if (!usePeekGate) {
150
+ const ssrConfig = buildFugueContentSiteNetlifySsrConfig(resolvedAuth.envPrefix)
151
+ if (ssrConfig)
152
+ return defu(ssrConfig, studioConfig) as NuxtConfig
153
+ }
154
+
155
+ return studioConfig
156
+ }
@@ -0,0 +1,42 @@
1
+ import type { ResolvedFugueContentSiteAuthMode } from './auth-resolve'
2
+
3
+ /** Hook used to register shell header actions — must run after SSR hydration. */
4
+ export const FUGUE_CONTENT_HEADER_ACTIONS_REGISTER_AFTER = 'onNuxtReady' as const
5
+
6
+ export interface FugueContentPublicAuthConfig {
7
+ fugueContent?: { authMode?: ResolvedFugueContentSiteAuthMode }
8
+ fugueSimpleAuth?: unknown
9
+ studio?: { route?: string }
10
+ }
11
+
12
+ export function resolveFugueContentAuthModeFromPublicConfig(publicConfig: FugueContentPublicAuthConfig) {
13
+ const authMode = (publicConfig.fugueContent?.authMode ?? 'off') as ResolvedFugueContentSiteAuthMode
14
+ const hasPeekGate = authMode === 'peek' && Boolean(publicConfig.fugueSimpleAuth)
15
+ const hasStudioAuth = authMode === 'studio' && Boolean(publicConfig.studio?.route)
16
+
17
+ return {
18
+ authMode,
19
+ hasPeekGate,
20
+ hasStudioAuth
21
+ }
22
+ }
23
+
24
+ export function shouldRegisterFugueContentHeaderActions(publicConfig: FugueContentPublicAuthConfig): boolean {
25
+ const { hasPeekGate, hasStudioAuth } = resolveFugueContentAuthModeFromPublicConfig(publicConfig)
26
+ return Boolean(publicConfig.studio?.route || hasPeekGate || hasStudioAuth)
27
+ }
28
+
29
+ /**
30
+ * Clear header actions before hydrate, register only after hydration completes.
31
+ * Extracted for unit tests — client plugin passes `onNuxtReady` as `scheduleAfterHydration`.
32
+ */
33
+ export function scheduleFugueContentHeaderActionsRegistration(options: {
34
+ clear: () => void
35
+ register: () => void
36
+ scheduleAfterHydration: (registerFn: () => void) => void
37
+ }) {
38
+ options.clear()
39
+ options.scheduleAfterHydration(() => {
40
+ options.register()
41
+ })
42
+ }
@@ -0,0 +1,22 @@
1
+ import type { FugueContentI18nLocale } from './i18n-utils'
2
+ import { existsSync } from 'node:fs'
3
+ import { join } from 'node:path'
4
+ import { localeCodeFromEntry } from './i18n-utils'
5
+
6
+ /** Locales that have a `content/{code}/` folder (warn and skip others). */
7
+ export function resolveI18nLocaleCodes(
8
+ rootDir: string,
9
+ locales: FugueContentI18nLocale[],
10
+ onMissing?: (_code: string) => void
11
+ ): string[] {
12
+ return locales
13
+ .map(localeCodeFromEntry)
14
+ .filter((code) => {
15
+ const folder = join(rootDir, 'content', code)
16
+ if (!existsSync(folder)) {
17
+ onMissing?.(code)
18
+ return false
19
+ }
20
+ return true
21
+ })
22
+ }
@@ -0,0 +1,136 @@
1
+ export type FugueContentI18nLocale = string | { code: string, name?: string }
2
+
3
+ /** Subset of `nuxt.config` i18n used by fugue-content-site content collections and fugue-content i18n module. */
4
+ export interface FugueContentNuxtI18nOptions {
5
+ defaultLocale?: string
6
+ locales?: FugueContentI18nLocale[]
7
+ strategy?: string
8
+ detectBrowserLanguage?: Record<string, unknown>
9
+ }
10
+
11
+ /** Nuxt options read by `content.config.ts` — explicit typing avoids fragile schema merges in the IDE. */
12
+ export interface FugueContentContentNuxtOptions {
13
+ rootDir: string
14
+ i18n?: FugueContentNuxtI18nOptions
15
+ }
16
+
17
+ export function fugueContentNuxtOptions(options: unknown): FugueContentContentNuxtOptions {
18
+ return options as FugueContentContentNuxtOptions
19
+ }
20
+
21
+ /** Collection suffix: `pt-BR` → `pt_BR` (Docus convention). */
22
+ export function normalizeLocaleCode(code: string): string {
23
+ return code.replace(/-/g, '_')
24
+ }
25
+
26
+ export function pagesCollectionName(localeCode: string): string {
27
+ return `pages_${normalizeLocaleCode(localeCode)}`
28
+ }
29
+
30
+ export function fragmentsCollectionName(localeCode: string): string {
31
+ return `fragments_${normalizeLocaleCode(localeCode)}`
32
+ }
33
+
34
+ export function settingsCollectionName(localeCode: string): string {
35
+ return `settings_${normalizeLocaleCode(localeCode)}`
36
+ }
37
+
38
+ /**
39
+ * Content path for a fragment slug in the active locale.
40
+ * Slug is the file stem — e.g. `app-demo` → `/fragments/app-demo` or `/es/fragments/app-demo`.
41
+ */
42
+ export function fragmentContentPath(slug: string, localeCode: string, defaultLocale: string): string {
43
+ const normalized = slug.replace(/^\//, '').replace(/^fragments\//, '')
44
+ return `${fragmentsRoutePrefix(localeCode, defaultLocale)}/${normalized}`
45
+ }
46
+
47
+ /**
48
+ * Nuxt Content document id for a fragment — matches Studio `data-content-id` / `detectActives`.
49
+ * Derivable from slug + locale without querying the collection (SSR-safe for Studio).
50
+ */
51
+ export function fragmentContentId(
52
+ slug: string,
53
+ localeCode: string,
54
+ defaultLocale: string,
55
+ collectionName = fragmentsCollectionName(localeCode)
56
+ ): string {
57
+ const path = fragmentContentPath(slug, localeCode, defaultLocale).replace(/^\//, '')
58
+ return `${collectionName}/${path}.md`
59
+ }
60
+
61
+ /** Filesystem path Studio uses in the content tree — e.g. `en/fragments/app-demo.md`. */
62
+ export function fragmentFsPath(
63
+ slug: string,
64
+ localeCode: string,
65
+ _defaultLocale: string,
66
+ hasI18n = true
67
+ ): string {
68
+ const normalized = slug.replace(/^\//, '').replace(/^fragments\//, '').replace(/\.md$/, '')
69
+ if (!hasI18n)
70
+ return `fragments/${normalized}.md`
71
+ return `${localeCode}/fragments/${normalized}.md`
72
+ }
73
+
74
+ /**
75
+ * Filesystem path Studio uses for a routed page — e.g. `en/policies.md`.
76
+ * `stem` comes from Nuxt Content (`policies` or `es/policies` for secondary locales).
77
+ */
78
+ export function pageFsPath(
79
+ stem: string,
80
+ localeCode: string,
81
+ _defaultLocale: string,
82
+ hasI18n = true
83
+ ): string {
84
+ const normalized = stem.replace(/^\//, '').replace(/\.md$/, '')
85
+ if (!hasI18n)
86
+ return `${normalized}.md`
87
+ if (normalized.startsWith(`${localeCode}/`))
88
+ return `${normalized}.md`
89
+ return `${localeCode}/${normalized}.md`
90
+ }
91
+
92
+ /** Nuxt Content document id for a page — matches Studio `data-content-id`. */
93
+ export function pageContentId(
94
+ stem: string,
95
+ localeCode: string,
96
+ defaultLocale: string,
97
+ hasI18n = true,
98
+ collectionName = pagesCollectionName(localeCode)
99
+ ): string {
100
+ return `${collectionName}/${pageFsPath(stem, localeCode, defaultLocale, hasI18n)}`
101
+ }
102
+
103
+ export function localeCodeFromEntry(locale: FugueContentI18nLocale): string {
104
+ return typeof locale === 'string'
105
+ ? locale
106
+ : locale.code
107
+ }
108
+
109
+ export function localeNameFromEntry(locale: FugueContentI18nLocale): string {
110
+ return typeof locale === 'string'
111
+ ? locale
112
+ : (locale.name ?? locale.code)
113
+ }
114
+
115
+ export function getDefaultI18nOptions(defaultLocale: string) {
116
+ return {
117
+ strategy: 'prefix_except_default' as const,
118
+ defaultLocale,
119
+ /** Off by default — `/` stays default locale; use header **Español** or `/es`. Opt in via `detectBrowserLanguage` in app `i18n` config. */
120
+ detectBrowserLanguage: false as const
121
+ }
122
+ }
123
+
124
+ export function contentPrefixForLocale(localeCode: string, defaultLocale: string): string {
125
+ return localeCode === defaultLocale
126
+ ? '/'
127
+ : `/${localeCode}`
128
+ }
129
+
130
+ /** Route prefix for fragment collections — avoids `//fragments` when locale prefix is `/`. */
131
+ export function fragmentsRoutePrefix(localeCode: string, defaultLocale: string): string {
132
+ const localePrefix = contentPrefixForLocale(localeCode, defaultLocale)
133
+ if (localePrefix === '/')
134
+ return '/fragments'
135
+ return `${localePrefix}/fragments`
136
+ }
package/lib/i18n.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './i18n-locales'
2
+ export * from './i18n-utils'
package/lib/landing.ts ADDED
@@ -0,0 +1,129 @@
1
+ export interface FugueContentLandingSectionNav {
2
+ labelKey?: string
3
+ label?: string
4
+ icon?: string
5
+ id?: string
6
+ /** Locale-neutral path — defaults to `/` for `home` anchor, else `/#{anchor}` */
7
+ to?: string
8
+ }
9
+
10
+ /** Named landing section component with props nested under the component definition. */
11
+ export interface FugueContentLandingSectionComponent {
12
+ name: string
13
+ props?: Record<string, unknown>
14
+ }
15
+
16
+ export interface FugueContentLandingSection {
17
+ /** Fragment file stem when using `FugueContentFragment` — e.g. `hero` → `fragments/hero.md` */
18
+ slug: string
19
+ /** DOM id for hash navigation — e.g. `activities` → `#activities` */
20
+ anchor: string
21
+ /** Vue component — string shorthand or `{ name, props }` */
22
+ component?: string | FugueContentLandingSectionComponent
23
+ /** Optional wrapper `<section>` base class — overrides `FugueContentLandingPage` `sectionClass` */
24
+ sectionClass?: string
25
+ /** Optional layout variant — appended as `{sectionClass}--{variant}` */
26
+ variant?: string
27
+ nav?: FugueContentLandingSectionNav
28
+ }
29
+
30
+ export interface FugueContentLandingManifest {
31
+ sections: FugueContentLandingSection[]
32
+ }
33
+
34
+ export interface FugueContentLandingNavItem {
35
+ label: string
36
+ labelKey?: string
37
+ icon: string
38
+ id?: string
39
+ to: string
40
+ }
41
+
42
+ /** Default hash/home path for a landing section nav entry. */
43
+ export function landingSectionNavPath(section: FugueContentLandingSection): string {
44
+ if (section.nav?.to)
45
+ return section.nav.to
46
+ if (section.anchor === 'home')
47
+ return '/'
48
+ return `/#${section.anchor}`
49
+ }
50
+
51
+ /** Build shell nav items from a landing manifest (sections with `nav` only). */
52
+ export function landingNavItems(
53
+ sections: FugueContentLandingSection[] | undefined,
54
+ localePath: (path: string) => string = path => path
55
+ ): FugueContentLandingNavItem[] {
56
+ if (!sections?.length)
57
+ return []
58
+
59
+ return sections
60
+ .filter(section => section.nav)
61
+ .map((section) => {
62
+ const nav = section.nav!
63
+ return {
64
+ label: nav.label ?? section.anchor,
65
+ labelKey: nav.labelKey,
66
+ icon: nav.icon ?? 'i-lucide-circle',
67
+ id: nav.id ?? section.anchor,
68
+ to: localePath(landingSectionNavPath(section))
69
+ }
70
+ })
71
+ }
72
+
73
+ /** Resolved Vue component name for a landing section row. */
74
+ export function landingSectionComponentName(section: FugueContentLandingSection): string {
75
+ const component = section.component
76
+ if (typeof component === 'string')
77
+ return component || 'FugueContentFragment'
78
+ if (component && typeof component === 'object')
79
+ return component.name
80
+ return 'FugueContentFragment'
81
+ }
82
+
83
+ function landingSectionComponentRawProps(section: FugueContentLandingSection): Record<string, unknown> {
84
+ const component = section.component
85
+ if (component && typeof component === 'object' && component.props)
86
+ return { ...component.props }
87
+ return {}
88
+ }
89
+
90
+ /** Props for a dynamic section component — `FugueContentFragment` always receives `slug`. */
91
+ export function landingSectionProps(section: FugueContentLandingSection): Record<string, unknown> {
92
+ const component = landingSectionComponentName(section)
93
+ const props = landingSectionComponentRawProps(section)
94
+
95
+ if (component === 'FugueContentFragment')
96
+ props.slug = section.slug
97
+ else if (
98
+ !props.slug
99
+ && !props.contentComponent
100
+ && (
101
+ 'images' in props
102
+ || ('src' in props && 'alt' in props)
103
+ || component.endsWith('Fragment')
104
+ )
105
+ )
106
+ props.slug = section.slug
107
+
108
+ return props
109
+ }
110
+
111
+ /** Base BEM block class for a landing `<section>` — manifest row overrides page default. */
112
+ export function landingSectionClass(
113
+ section: FugueContentLandingSection,
114
+ defaultSectionClass: string
115
+ ): string {
116
+ return section.sectionClass ?? defaultSectionClass
117
+ }
118
+
119
+ /** Wrapper `<section>` class list — base class plus optional `{base}--{variant}`. */
120
+ export function landingSectionClasses(
121
+ section: FugueContentLandingSection,
122
+ defaultSectionClass: string
123
+ ): string[] {
124
+ const base = landingSectionClass(section, defaultSectionClass)
125
+ const classes = [base]
126
+ if (section.variant)
127
+ classes.push(`${base}--${section.variant}`)
128
+ return classes
129
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Normalize `/login?redirect=` for post-auth navigation.
3
+ */
4
+ export function resolveFugueContentLoginRedirect(
5
+ redirect: unknown,
6
+ fallback = '/'
7
+ ): string {
8
+ if (typeof redirect === 'string' && redirect.startsWith('/') && !redirect.startsWith('//'))
9
+ return redirect
10
+
11
+ return fallback
12
+ }