@altafusion/fugue-content 0.0.0-stage → 0.2.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/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +352 -2
- package/app/components/FugueContent404Page.vue +48 -0
- package/app/components/FugueContentAuthSignOut.vue +16 -0
- package/app/components/FugueContentContentPage.vue +33 -0
- package/app/components/FugueContentEditContent.vue +76 -0
- package/app/components/FugueContentEditorMenu.vue +60 -0
- package/app/components/FugueContentFooterActions.vue +32 -0
- package/app/components/FugueContentFragment.vue +53 -0
- package/app/components/FugueContentHeaderActions.vue +37 -0
- package/app/components/FugueContentLandingPage.vue +69 -0
- package/app/components/FugueContentLayoutArticle.vue +22 -0
- package/app/components/FugueContentLayoutArticleAside.vue +88 -0
- package/app/components/FugueContentLayoutLanding.vue +5 -0
- package/app/components/LandingHeroMedia.vue +91 -0
- package/app/components/content/CallToAction.vue +35 -0
- package/app/components/content/Hero.vue +34 -0
- package/app/composables/useFugueContentCatchAllRoute.ts +91 -0
- package/app/composables/useFugueContentFragment.ts +70 -0
- package/app/composables/useFugueContentI18n.ts +77 -0
- package/app/composables/useFugueContentLanding.ts +24 -0
- package/app/composables/useFugueContentPage.ts +37 -0
- package/app/composables/useFugueContentSettings.ts +140 -0
- package/app/composables/useFugueContentStudioEdit.ts +38 -0
- package/app/pages/[...slug].vue +7 -0
- package/app/pages/fragments/[slug].vue +25 -0
- package/app/pages/index.vue +7 -0
- package/app/pages/login.vue +70 -0
- package/app/plugins/auth-session-sync.client.ts +33 -0
- package/app/plugins/landing-component-registry.ts +15 -0
- package/app/plugins/landing-nav.ts +26 -0
- package/app/plugins/qe-tools.client.ts +28 -0
- package/app/plugins/seo-defaults.ts +4 -0
- package/app/plugins/settings-bridge.ts +14 -0
- package/app/plugins/shell-display-name.ts +18 -0
- package/app/plugins/studio-auto-open.client.ts +30 -0
- package/app/plugins/studio-dev-shortcut.client.ts +24 -0
- package/app/plugins/studio-footer-actions.client.ts +27 -0
- package/app/plugins/studio-footer-actions.server.ts +11 -0
- package/app/plugins/studio-hash-cleanup.client.ts +12 -0
- package/app/plugins/studio-header-actions.client.ts +30 -0
- package/app/plugins/studio-header-actions.server.ts +13 -0
- package/app/utils/studio-mount.ts +72 -0
- package/composables/useFugueContentAuthMode.ts +16 -0
- package/composables/useFugueContentAuthSignOut.ts +82 -0
- package/composables/useFugueContentPeekSession.ts +31 -0
- package/composables/useFugueContentStudioEditorEntry.ts +112 -0
- package/composables/useFugueContentStudioSession.ts +81 -0
- package/content.config.ts +199 -0
- package/content.d.ts +25 -0
- package/eslint.config.mjs +4 -0
- package/lib/404-defaults.ts +41 -0
- package/lib/article-i18n.ts +10 -0
- package/lib/auth-resolve.ts +74 -0
- package/lib/auth-utils.ts +44 -0
- package/lib/define-site.ts +156 -0
- package/lib/header-actions-registration.ts +42 -0
- package/lib/i18n-locales.ts +22 -0
- package/lib/i18n-utils.ts +136 -0
- package/lib/i18n.ts +2 -0
- package/lib/landing.ts +129 -0
- package/lib/login-redirect.ts +12 -0
- package/lib/netlify-ssr.ts +113 -0
- package/lib/page-toc.ts +14 -0
- package/lib/qe-tools/index.ts +36 -0
- package/lib/qe-tools/studio-drafts.ts +315 -0
- package/lib/qe-tools/types.ts +14 -0
- package/lib/settings-state.ts +1 -0
- package/lib/site-config-registry.ts +80 -0
- package/lib/studio-activation-gated.d.ts +20 -0
- package/lib/studio-activation-gated.js +127 -0
- package/lib/studio-auto-open.ts +26 -0
- package/lib/studio-cookies.d.ts +10 -0
- package/lib/studio-cookies.js +11 -0
- package/lib/studio-document-edit.ts +61 -0
- package/lib/studio-editor-visibility.ts +54 -0
- package/lib/studio-open.ts +7 -0
- package/lib/studio-session.ts +91 -0
- package/modules/i18n.ts +80 -0
- package/modules/landing-components.ts +95 -0
- package/modules/studio-auth-gate.ts +48 -0
- package/modules/studio-entry.ts +23 -0
- package/nuxt.config.ts +90 -0
- package/package.json +66 -3
- package/schemas/site-settings.schema.json +127 -0
- package/server/middleware/studio-oauth-redirect.ts +36 -0
- package/server/middleware/studio-provider-check.ts +59 -0
- package/server/plugins/studio-hash-cleanup.ts +8 -0
- package/tsconfig.build.json +22 -0
- package/tsconfig.json +20 -0
- package/types/site.ts +79 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* global $fetch -- Nuxt/Nitro runtime global */
|
|
2
|
+
import { getAppManifest, useCookie, useRuntimeConfig, useState } from '#imports'
|
|
3
|
+
import {
|
|
4
|
+
FUGUE_CONTENT_STUDIO_COOKIE_OPTIONS,
|
|
5
|
+
FUGUE_CONTENT_STUDIO_DEV_AUTH_CHECK,
|
|
6
|
+
FUGUE_CONTENT_STUDIO_SESSION_CHECK,
|
|
7
|
+
FUGUE_CONTENT_STUDIO_SESSION_ROUTE
|
|
8
|
+
} from './studio-cookies.js'
|
|
9
|
+
|
|
10
|
+
/** Deferred dev activation when fugue-simple-auth session is missing. */
|
|
11
|
+
let deferredActivate = null
|
|
12
|
+
|
|
13
|
+
/** Called from Edit Content / studio-mount after the access-key session is valid. */
|
|
14
|
+
export async function ensureStudioActivation() {
|
|
15
|
+
if (import.meta.server)
|
|
16
|
+
return false
|
|
17
|
+
|
|
18
|
+
if (typeof window.useStudioHost === 'function')
|
|
19
|
+
return true
|
|
20
|
+
|
|
21
|
+
if (!deferredActivate)
|
|
22
|
+
return false
|
|
23
|
+
|
|
24
|
+
await deferredActivate()
|
|
25
|
+
return typeof window.useStudioHost === 'function'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const devUser = {
|
|
29
|
+
provider: 'github',
|
|
30
|
+
email: 'dev@nuxt.com',
|
|
31
|
+
name: 'Dev',
|
|
32
|
+
accessToken: '',
|
|
33
|
+
providerId: '',
|
|
34
|
+
avatar: ''
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function registerLoginShortcut(loginPath) {
|
|
38
|
+
document.addEventListener('keydown', (event) => {
|
|
39
|
+
if (event.metaKey && event.key === '.') {
|
|
40
|
+
event.preventDefault()
|
|
41
|
+
const redirect = encodeURIComponent(window.location.pathname + window.location.search)
|
|
42
|
+
window.location.href = `${loginPath}?redirect=${redirect}`
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function defineStudioActivationPlugin(onStudioActivation) {
|
|
48
|
+
const user = useState('studio-session', () => null)
|
|
49
|
+
const config = useRuntimeConfig().public.studio
|
|
50
|
+
const sessionCheck = useCookie(FUGUE_CONTENT_STUDIO_SESSION_CHECK, FUGUE_CONTENT_STUDIO_COOKIE_OPTIONS)
|
|
51
|
+
const devAuthCheck = useCookie(FUGUE_CONTENT_STUDIO_DEV_AUTH_CHECK, FUGUE_CONTENT_STUDIO_COOKIE_OPTIONS)
|
|
52
|
+
|
|
53
|
+
async function activateDev() {
|
|
54
|
+
await onStudioActivation(devUser)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (config.dev) {
|
|
58
|
+
deferredActivate = activateDev
|
|
59
|
+
|
|
60
|
+
if (String(devAuthCheck.value) === 'true') {
|
|
61
|
+
await activateDev()
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const fugue = useRuntimeConfig().public.fugueSimpleAuth
|
|
66
|
+
if (fugue?.mode === 'routes') {
|
|
67
|
+
try {
|
|
68
|
+
const session = await $fetch(`${fugue.apiPrefix}/session`)
|
|
69
|
+
if (session?.required && !session?.authenticated) {
|
|
70
|
+
registerLoginShortcut(fugue.loginPath ?? '/login')
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
registerLoginShortcut(fugue.loginPath ?? '/login')
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function resolveProductionUser() {
|
|
83
|
+
if (user.value?.email)
|
|
84
|
+
return user.value
|
|
85
|
+
|
|
86
|
+
if (String(sessionCheck.value) !== 'true')
|
|
87
|
+
return null
|
|
88
|
+
|
|
89
|
+
const sessionUser = await $fetch(FUGUE_CONTENT_STUDIO_SESSION_ROUTE).then(session => session?.user ?? null)
|
|
90
|
+
if (sessionUser?.email)
|
|
91
|
+
user.value = sessionUser
|
|
92
|
+
|
|
93
|
+
return sessionUser
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function activateProduction() {
|
|
97
|
+
const sessionUser = await resolveProductionUser()
|
|
98
|
+
if (!sessionUser?.email)
|
|
99
|
+
return false
|
|
100
|
+
|
|
101
|
+
const manifest = await getAppManifest()
|
|
102
|
+
manifest.prerendered = []
|
|
103
|
+
await onStudioActivation(sessionUser)
|
|
104
|
+
return typeof window.useStudioHost === 'function'
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
deferredActivate = activateProduction
|
|
108
|
+
|
|
109
|
+
user.value = String(sessionCheck.value) === 'true'
|
|
110
|
+
? await $fetch(FUGUE_CONTENT_STUDIO_SESSION_ROUTE).then(session => session?.user ?? null)
|
|
111
|
+
: null
|
|
112
|
+
|
|
113
|
+
let mounted = false
|
|
114
|
+
if (user.value?.email) {
|
|
115
|
+
mounted = await activateProduction()
|
|
116
|
+
} else if (mounted) {
|
|
117
|
+
window.location.reload()
|
|
118
|
+
} else {
|
|
119
|
+
document.addEventListener('keydown', (event) => {
|
|
120
|
+
if (event.metaKey && event.key === '.') {
|
|
121
|
+
setTimeout(() => {
|
|
122
|
+
window.location.href = `${config.route}?redirect=${encodeURIComponent(window.location.pathname)}`
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mountNuxtStudioClient } from '../app/utils/studio-mount'
|
|
2
|
+
|
|
3
|
+
const OPEN_RETRY_MS = 250
|
|
4
|
+
const OPEN_MAX_ATTEMPTS = 12
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Mount the Studio panel when an editor session cookie is present.
|
|
8
|
+
* Retries while the gated activation hook finishes on first paint.
|
|
9
|
+
*/
|
|
10
|
+
export async function openFugueContentStudioEditorPanel(): Promise<boolean> {
|
|
11
|
+
if (!import.meta.client)
|
|
12
|
+
return false
|
|
13
|
+
|
|
14
|
+
if (document.querySelector('nuxt-studio'))
|
|
15
|
+
return true
|
|
16
|
+
|
|
17
|
+
for (let attempt = 0; attempt < OPEN_MAX_ATTEMPTS; attempt++) {
|
|
18
|
+
const mounted = await mountNuxtStudioClient()
|
|
19
|
+
if (mounted)
|
|
20
|
+
return true
|
|
21
|
+
|
|
22
|
+
await new Promise(resolve => setTimeout(resolve, OPEN_RETRY_MS))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return Boolean(document.querySelector('nuxt-studio'))
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Types for `studio-cookies.js` (plain JS so `studio-activation-gated.js` can import it too). */
|
|
2
|
+
export declare const FUGUE_CONTENT_STUDIO_SESSION_ROUTE: '/__nuxt_studio/auth/session'
|
|
3
|
+
export declare const FUGUE_CONTENT_STUDIO_SESSION_CHECK: 'studio-session-check'
|
|
4
|
+
export declare const FUGUE_CONTENT_STUDIO_DEV_AUTH_CHECK: 'fugue-content-studio-dev-auth'
|
|
5
|
+
|
|
6
|
+
export declare const FUGUE_CONTENT_STUDIO_COOKIE_OPTIONS: {
|
|
7
|
+
maxAge: number
|
|
8
|
+
sameSite: string
|
|
9
|
+
path: string
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Shared Studio editor cookie names — imported by TS and `studio-activation-gated.js`. */
|
|
2
|
+
export const FUGUE_CONTENT_STUDIO_SESSION_ROUTE = '/__nuxt_studio/auth/session'
|
|
3
|
+
export const FUGUE_CONTENT_STUDIO_SESSION_CHECK = 'studio-session-check'
|
|
4
|
+
/** Dev-only editor session — never sent to `/__nuxt_studio/auth/session` (that route clears `studio-session-check`). */
|
|
5
|
+
export const FUGUE_CONTENT_STUDIO_DEV_AUTH_CHECK = 'fugue-content-studio-dev-auth'
|
|
6
|
+
|
|
7
|
+
export const FUGUE_CONTENT_STUDIO_COOKIE_OPTIONS = {
|
|
8
|
+
maxAge: 60 * 60 * 24 * 30,
|
|
9
|
+
sameSite: 'lax',
|
|
10
|
+
path: '/'
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isNuxtStudioMounted } from '../app/utils/studio-mount'
|
|
2
|
+
import { openFugueContentStudioEditorPanel } from './studio-auto-open'
|
|
3
|
+
|
|
4
|
+
async function waitForStudioHostMounted(timeoutMs = 15_000): Promise<boolean> {
|
|
5
|
+
const deadline = Date.now() + timeoutMs
|
|
6
|
+
|
|
7
|
+
while (Date.now() < deadline) {
|
|
8
|
+
if (typeof window.useStudioHost !== 'function') {
|
|
9
|
+
await new Promise(resolve => setTimeout(resolve, 50))
|
|
10
|
+
continue
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const host = window.useStudioHost()
|
|
14
|
+
if (host.on?.mounted) {
|
|
15
|
+
try {
|
|
16
|
+
host.on.mounted(() => {})
|
|
17
|
+
return true
|
|
18
|
+
} catch {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (isNuxtStudioMounted())
|
|
24
|
+
return true
|
|
25
|
+
|
|
26
|
+
await new Promise(resolve => setTimeout(resolve, 50))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare module '#app' {
|
|
33
|
+
interface RuntimeNuxtHooks {
|
|
34
|
+
'studio:document:edit': (fsPath: string) => void | Promise<void>
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Mount Studio (if needed) and open a content file by repository fsPath.
|
|
40
|
+
* Returns false when the editor could not be opened — logs a console warning.
|
|
41
|
+
*/
|
|
42
|
+
export async function requestFugueContentStudioDocumentEdit(fsPath: string): Promise<boolean> {
|
|
43
|
+
if (!import.meta.client)
|
|
44
|
+
return false
|
|
45
|
+
|
|
46
|
+
const mounted = await openFugueContentStudioEditorPanel()
|
|
47
|
+
if (!mounted) {
|
|
48
|
+
console.warn(
|
|
49
|
+
'[fugue-content-site] Could not mount Nuxt Studio. Open Edit content from the header menu, then try again.'
|
|
50
|
+
)
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!await waitForStudioHostMounted()) {
|
|
55
|
+
console.warn('[fugue-content-site] Studio editor did not become ready in time.')
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await useNuxtApp().hooks.callHook('studio:document:edit', fsPath)
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ResolvedFugueContentSiteAuthMode } from './auth-resolve'
|
|
2
|
+
|
|
3
|
+
export interface FugueContentPeekSessionState {
|
|
4
|
+
required?: boolean
|
|
5
|
+
authenticated?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface FugueContentEditorChromeContext {
|
|
9
|
+
authMode: ResolvedFugueContentSiteAuthMode
|
|
10
|
+
hasStudioRoute: boolean
|
|
11
|
+
isClientReady: boolean
|
|
12
|
+
isStudioActive: boolean
|
|
13
|
+
hasStudioSession: boolean
|
|
14
|
+
hasPeekGate: boolean
|
|
15
|
+
peekSession: FugueContentPeekSessionState | null | undefined
|
|
16
|
+
peekPending: boolean
|
|
17
|
+
showPeekSignOut: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Signed-in editor — inline `FugueContentEditContent` on fragments and article pages. */
|
|
21
|
+
export function resolveFugueContentShowFragmentEdit(ctx: {
|
|
22
|
+
isAuthenticated: boolean
|
|
23
|
+
}): boolean {
|
|
24
|
+
return ctx.isAuthenticated
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Avatar editor menu — only after Studio Google/dev session is established. */
|
|
28
|
+
export function resolveFugueContentShowEditorMenu(ctx: FugueContentEditorChromeContext): boolean {
|
|
29
|
+
if (!ctx.isClientReady || !ctx.hasStudioRoute)
|
|
30
|
+
return false
|
|
31
|
+
|
|
32
|
+
return ctx.hasStudioSession
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Footer Edit entry — visible when Studio is configured; hidden while the editor is open. */
|
|
36
|
+
export function resolveFugueContentShowFooterEdit(ctx: FugueContentEditorChromeContext): boolean {
|
|
37
|
+
if (!ctx.isClientReady || !ctx.hasStudioRoute || ctx.isStudioActive)
|
|
38
|
+
return false
|
|
39
|
+
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Whether the header actions wrapper should mount (avoids empty chrome + hydration drift). */
|
|
44
|
+
export function resolveFugueContentShowHeaderActions(ctx: FugueContentEditorChromeContext): boolean {
|
|
45
|
+
if (resolveFugueContentShowEditorMenu(ctx))
|
|
46
|
+
return true
|
|
47
|
+
|
|
48
|
+
return Boolean(
|
|
49
|
+
ctx.isClientReady
|
|
50
|
+
&& ctx.hasPeekGate
|
|
51
|
+
&& ctx.showPeekSignOut
|
|
52
|
+
&& !ctx.hasStudioSession
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Dispatched in dev to open Nuxt Studio (header Edit and ⌘. / Ctrl+.). */
|
|
2
|
+
export const FUGUE_CONTENT_STUDIO_OPEN_EVENT = 'fugue-content:open-studio'
|
|
3
|
+
|
|
4
|
+
export function dispatchFugueContentStudioOpen() {
|
|
5
|
+
if (import.meta.client)
|
|
6
|
+
window.dispatchEvent(new CustomEvent(FUGUE_CONTENT_STUDIO_OPEN_EVENT))
|
|
7
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export {
|
|
2
|
+
FUGUE_CONTENT_STUDIO_DEV_AUTH_CHECK,
|
|
3
|
+
FUGUE_CONTENT_STUDIO_SESSION_CHECK,
|
|
4
|
+
FUGUE_CONTENT_STUDIO_SESSION_ROUTE
|
|
5
|
+
} from './studio-cookies.js'
|
|
6
|
+
|
|
7
|
+
export const FUGUE_CONTENT_STUDIO_SESSION_COOKIE_OPTIONS = {
|
|
8
|
+
maxAge: 60 * 60 * 24 * 30,
|
|
9
|
+
sameSite: 'lax' as const,
|
|
10
|
+
path: '/'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface FugueContentStudioUser {
|
|
14
|
+
email?: string
|
|
15
|
+
name?: string
|
|
16
|
+
avatar?: string
|
|
17
|
+
picture?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface FugueContentStudioSessionPayload {
|
|
21
|
+
user?: FugueContentStudioUser
|
|
22
|
+
id?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const FUGUE_CONTENT_STUDIO_DEV_USER: FugueContentStudioUser = {
|
|
26
|
+
email: 'dev@nuxt.com',
|
|
27
|
+
name: 'Dev'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ResolveFugueContentStudioUserOptions {
|
|
31
|
+
devAuthCheck?: string | null
|
|
32
|
+
sessionCheck?: string | null
|
|
33
|
+
isDev?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isFugueContentStudioSessionCheck(value: unknown): boolean {
|
|
37
|
+
return String(value) === 'true'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function resolveFugueContentStudioUser(
|
|
41
|
+
session: FugueContentStudioSessionPayload | null | undefined,
|
|
42
|
+
devUser?: FugueContentStudioUser | null,
|
|
43
|
+
options: ResolveFugueContentStudioUserOptions = {}
|
|
44
|
+
): FugueContentStudioUser | null {
|
|
45
|
+
const fromSession = session?.user
|
|
46
|
+
if (fromSession?.email)
|
|
47
|
+
return normalizeFugueContentStudioUser(fromSession)
|
|
48
|
+
|
|
49
|
+
if (devUser?.email)
|
|
50
|
+
return normalizeFugueContentStudioUser(devUser)
|
|
51
|
+
|
|
52
|
+
if (options.isDev && isFugueContentStudioSessionCheck(options.devAuthCheck))
|
|
53
|
+
return normalizeFugueContentStudioUser(FUGUE_CONTENT_STUDIO_DEV_USER)
|
|
54
|
+
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function normalizeFugueContentStudioUser(user: FugueContentStudioUser): FugueContentStudioUser {
|
|
59
|
+
const avatar = user.avatar ?? user.picture
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
email: user.email,
|
|
63
|
+
name: user.name,
|
|
64
|
+
...(avatar
|
|
65
|
+
? { avatar }
|
|
66
|
+
: {})
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface FugueContentStudioSessionState {
|
|
71
|
+
sessionCheck?: string | null
|
|
72
|
+
devAuthCheck?: string | null
|
|
73
|
+
devUser?: FugueContentStudioUser | null
|
|
74
|
+
isDev?: boolean
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function hasFugueContentStudioSession(
|
|
78
|
+
sessionCheck: string | null | undefined,
|
|
79
|
+
_session: FugueContentStudioSessionPayload | null | undefined,
|
|
80
|
+
devUser?: FugueContentStudioUser | null,
|
|
81
|
+
isDev = false,
|
|
82
|
+
devAuthCheck?: string | null
|
|
83
|
+
): boolean {
|
|
84
|
+
if (isDev && isFugueContentStudioSessionCheck(devAuthCheck))
|
|
85
|
+
return true
|
|
86
|
+
|
|
87
|
+
if (isFugueContentStudioSessionCheck(sessionCheck))
|
|
88
|
+
return true
|
|
89
|
+
|
|
90
|
+
return Boolean(isDev && devUser?.email)
|
|
91
|
+
}
|
package/modules/i18n.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { ModuleOptions } from '@nuxtjs/i18n'
|
|
2
|
+
import type { FugueContentNuxtI18nOptions } from '../lib/i18n-utils'
|
|
3
|
+
import { defineNuxtModule, installModule, logger } from '@nuxt/kit'
|
|
4
|
+
import { defu } from 'defu'
|
|
5
|
+
import { resolveI18nLocaleCodes } from '../lib/i18n-locales'
|
|
6
|
+
import {
|
|
7
|
+
fugueContentNuxtOptions,
|
|
8
|
+
getDefaultI18nOptions,
|
|
9
|
+
localeCodeFromEntry,
|
|
10
|
+
localeNameFromEntry
|
|
11
|
+
} from '../lib/i18n-utils'
|
|
12
|
+
|
|
13
|
+
const log = logger.withTag('fugue-content-site')
|
|
14
|
+
|
|
15
|
+
const disabledFugueContentPublic = {
|
|
16
|
+
i18nEnabled: false,
|
|
17
|
+
defaultLocale: 'en',
|
|
18
|
+
filteredLocales: [] as Array<{ code: string, name?: string }>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default defineNuxtModule({
|
|
22
|
+
meta: {
|
|
23
|
+
name: 'fugue-content-i18n'
|
|
24
|
+
},
|
|
25
|
+
async setup(_options, nuxt) {
|
|
26
|
+
const fugueContentOptions = fugueContentNuxtOptions(nuxt.options)
|
|
27
|
+
const i18nOptions = fugueContentOptions.i18n
|
|
28
|
+
|
|
29
|
+
if (!i18nOptions || typeof i18nOptions !== 'object' || !Array.isArray(i18nOptions.locales) || !i18nOptions.locales.length) {
|
|
30
|
+
nuxt.options.runtimeConfig.public.cms = {
|
|
31
|
+
...(nuxt.options.runtimeConfig.public.cms as Record<string, unknown> | undefined),
|
|
32
|
+
...disabledFugueContentPublic
|
|
33
|
+
}
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const defaultLocale = (i18nOptions.defaultLocale as string | undefined) ?? 'en'
|
|
38
|
+
const filteredCodes = resolveI18nLocaleCodes(
|
|
39
|
+
nuxt.options.rootDir,
|
|
40
|
+
i18nOptions.locales,
|
|
41
|
+
code => log.warn(`Content folder not found: content/${code}/ — skipping locale "${code}"`)
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if (!filteredCodes.length) {
|
|
45
|
+
log.warn('i18n locales configured but no content/{locale}/ folders found — using single pages collection')
|
|
46
|
+
nuxt.options.runtimeConfig.public.cms = {
|
|
47
|
+
...(nuxt.options.runtimeConfig.public.cms as Record<string, unknown> | undefined),
|
|
48
|
+
...disabledFugueContentPublic
|
|
49
|
+
}
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const mergedI18n = defu(i18nOptions, getDefaultI18nOptions(defaultLocale)) as FugueContentNuxtI18nOptions
|
|
54
|
+
fugueContentOptions.i18n = mergedI18n
|
|
55
|
+
|
|
56
|
+
await installModule('@nuxtjs/i18n', mergedI18n as ModuleOptions)
|
|
57
|
+
|
|
58
|
+
const filteredLocales = i18nOptions.locales
|
|
59
|
+
.filter(locale => filteredCodes.includes(localeCodeFromEntry(locale)))
|
|
60
|
+
.map(locale => ({
|
|
61
|
+
code: localeCodeFromEntry(locale),
|
|
62
|
+
name: localeNameFromEntry(locale)
|
|
63
|
+
}))
|
|
64
|
+
|
|
65
|
+
nuxt.options.runtimeConfig.public.cms = {
|
|
66
|
+
i18nEnabled: true,
|
|
67
|
+
defaultLocale,
|
|
68
|
+
filteredLocales
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
nuxt.hook('nitro:config', (nitroConfig) => {
|
|
72
|
+
nitroConfig.prerender = nitroConfig.prerender || {}
|
|
73
|
+
nitroConfig.prerender.routes = nitroConfig.prerender.routes || []
|
|
74
|
+
const routes = filteredCodes.map(code => (code === defaultLocale
|
|
75
|
+
? '/'
|
|
76
|
+
: `/${code}`))
|
|
77
|
+
nitroConfig.prerender.routes.push(...routes)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { defineNuxtModule, logger } from '@nuxt/kit'
|
|
4
|
+
|
|
5
|
+
const log = logger.withTag('fugue-content-site')
|
|
6
|
+
|
|
7
|
+
/** Names referenced by landing.sections[].component in each locale settings/site.yml. */
|
|
8
|
+
function collectLandingComponentNames(rootDir: string): Set<string> {
|
|
9
|
+
const names = new Set<string>()
|
|
10
|
+
const contentDir = join(rootDir, 'content')
|
|
11
|
+
|
|
12
|
+
if (!existsSync(contentDir))
|
|
13
|
+
return names
|
|
14
|
+
|
|
15
|
+
for (const entry of readdirSync(contentDir, { withFileTypes: true })) {
|
|
16
|
+
if (!entry.isDirectory())
|
|
17
|
+
continue
|
|
18
|
+
|
|
19
|
+
const siteYml = join(contentDir, entry.name, 'settings', 'site.yml')
|
|
20
|
+
if (!existsSync(siteYml))
|
|
21
|
+
continue
|
|
22
|
+
|
|
23
|
+
const text = readFileSync(siteYml, 'utf8')
|
|
24
|
+
let inLanding = false
|
|
25
|
+
let inComponentObject = false
|
|
26
|
+
|
|
27
|
+
for (const line of text.split('\n')) {
|
|
28
|
+
if (/^landing:\s*$/.test(line)) {
|
|
29
|
+
inLanding = true
|
|
30
|
+
inComponentObject = false
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
if (inLanding && /^[^\s#]/.test(line)) {
|
|
34
|
+
inLanding = false
|
|
35
|
+
inComponentObject = false
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!inLanding)
|
|
39
|
+
continue
|
|
40
|
+
|
|
41
|
+
const shorthand = line.match(/^\s+component:\s+(\w+)\s*(?:#.*)?$/)
|
|
42
|
+
if (shorthand?.[1] && shorthand[1] !== 'FugueContentFragment') {
|
|
43
|
+
names.add(shorthand[1])
|
|
44
|
+
inComponentObject = false
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (/^\s+component:\s*$/.test(line)) {
|
|
49
|
+
inComponentObject = true
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (inComponentObject) {
|
|
54
|
+
const nameMatch = line.match(/^\s+name:\s+(\w+)\s*(?:#.*)?$/)
|
|
55
|
+
if (nameMatch?.[1])
|
|
56
|
+
names.add(nameMatch[1])
|
|
57
|
+
|
|
58
|
+
const contentComponentMatch = line.match(/^\s+contentComponent:\s+(\w+)\s*(?:#.*)?$/)
|
|
59
|
+
if (contentComponentMatch?.[1])
|
|
60
|
+
names.add(contentComponentMatch[1])
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (/^ {6}\S/.test(line) && !/^ {6}component:/.test(line))
|
|
64
|
+
inComponentObject = false
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return names
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Mark app landing section components as global so SSR includes them for
|
|
73
|
+
* FugueContentLandingPage dynamic component resolution (manifest-only refs are tree-shaken otherwise).
|
|
74
|
+
*/
|
|
75
|
+
export default defineNuxtModule({
|
|
76
|
+
meta: {
|
|
77
|
+
name: 'fugue-content-landing-components'
|
|
78
|
+
},
|
|
79
|
+
setup(_options, nuxt) {
|
|
80
|
+
const landingComponentNames = collectLandingComponentNames(nuxt.options.rootDir)
|
|
81
|
+
|
|
82
|
+
if (!landingComponentNames.size)
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
log.info(`Landing components: ${[...landingComponentNames].join(', ')}`)
|
|
86
|
+
|
|
87
|
+
nuxt.hook('components:extend', (components) => {
|
|
88
|
+
for (const component of components) {
|
|
89
|
+
const name = component.pascalName
|
|
90
|
+
if (name && landingComponentNames.has(name))
|
|
91
|
+
component.global = true
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Plugin, UserConfig } from 'vite'
|
|
2
|
+
import { createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Replace nuxt-studio's dev auto-activation so the editor UI stays closed until
|
|
6
|
+
* **Edit** or **Cmd+.** — optional peek gate only adds a login step before open.
|
|
7
|
+
*/
|
|
8
|
+
export default defineNuxtModule({
|
|
9
|
+
meta: {
|
|
10
|
+
name: '@altafusion/fugue-content/studio-auth-gate'
|
|
11
|
+
},
|
|
12
|
+
setup(_options, nuxt) {
|
|
13
|
+
const resolver = createResolver(import.meta.url)
|
|
14
|
+
const gatedPath = resolver.resolve('../lib/studio-activation-gated.js')
|
|
15
|
+
|
|
16
|
+
nuxt.hook('modules:done', () => {
|
|
17
|
+
if (!nuxt.options.studio)
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
nuxt.hook('vite:extendConfig', (config, { isClient }) => {
|
|
21
|
+
if (!isClient)
|
|
22
|
+
return
|
|
23
|
+
|
|
24
|
+
const gatePlugin: Plugin = {
|
|
25
|
+
name: 'fugue-content:studio-activation-gate',
|
|
26
|
+
enforce: 'pre',
|
|
27
|
+
resolveId(source, importer) {
|
|
28
|
+
if (!importer?.includes('nuxt-studio'))
|
|
29
|
+
return
|
|
30
|
+
|
|
31
|
+
const isStudioClientPlugin = importer.includes('plugins/studio.client')
|
|
32
|
+
const isActivationImport = source === '../utils/activation.js'
|
|
33
|
+
|| source.endsWith('/utils/activation.js')
|
|
34
|
+
|
|
35
|
+
if (isStudioClientPlugin && isActivationImport)
|
|
36
|
+
return gatedPath
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const viteConfig = config as UserConfig
|
|
41
|
+
viteConfig.plugins = [
|
|
42
|
+
...(viteConfig.plugins ?? []),
|
|
43
|
+
gatePlugin
|
|
44
|
+
]
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { addImportsDir, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Register Studio editor composables for Fugue Content consumer apps.
|
|
5
|
+
* `FugueContentEditContent` lives in `app/components/`; footer/header plugins register editor chrome with the shell.
|
|
6
|
+
*/
|
|
7
|
+
export default defineNuxtModule({
|
|
8
|
+
meta: {
|
|
9
|
+
name: '@altafusion/fugue-content/studio-entry'
|
|
10
|
+
},
|
|
11
|
+
setup(_options, nuxt) {
|
|
12
|
+
const resolver = createResolver(import.meta.url)
|
|
13
|
+
|
|
14
|
+
addImportsDir(resolver.resolve('../composables'))
|
|
15
|
+
|
|
16
|
+
nuxt.options.build.transpile = [
|
|
17
|
+
...new Set([
|
|
18
|
+
...(nuxt.options.build.transpile ?? []),
|
|
19
|
+
'nuxt-studio'
|
|
20
|
+
])
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
})
|