@levino/shipyard-docs 0.6.1 → 0.6.2
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/package.json +1 -1
- package/src/index.ts +51 -4
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -253,8 +253,11 @@ export interface DocsConfig {
|
|
|
253
253
|
llmsTxt?: LlmsTxtDocsConfig
|
|
254
254
|
/**
|
|
255
255
|
* Whether to prerender docs pages at build time.
|
|
256
|
-
*
|
|
257
|
-
*
|
|
256
|
+
* When not specified, this is automatically determined from Astro's output mode:
|
|
257
|
+
* - `output: 'server'` → defaults to `false` (SSR)
|
|
258
|
+
* - `output: 'static'` or `output: 'hybrid'` → defaults to `true` (prerender)
|
|
259
|
+
*
|
|
260
|
+
* Set explicitly to `false` for SSR sites with auth middleware that need access to request headers/cookies.
|
|
258
261
|
*/
|
|
259
262
|
prerender?: boolean
|
|
260
263
|
}
|
|
@@ -333,7 +336,7 @@ export default (config: DocsConfig = {}): AstroIntegration => {
|
|
|
333
336
|
showLastUpdateTime = false,
|
|
334
337
|
showLastUpdateAuthor = false,
|
|
335
338
|
llmsTxt,
|
|
336
|
-
prerender
|
|
339
|
+
prerender: prerenderConfig,
|
|
337
340
|
} = config
|
|
338
341
|
|
|
339
342
|
// Normalize the route base path (remove leading/trailing slashes safely)
|
|
@@ -370,6 +373,14 @@ export default (config: DocsConfig = {}): AstroIntegration => {
|
|
|
370
373
|
config: astroConfig,
|
|
371
374
|
updateConfig,
|
|
372
375
|
}) => {
|
|
376
|
+
// Determine prerender value: if not explicitly set, derive from Astro's output mode
|
|
377
|
+
// - 'server' output defaults to false (SSR)
|
|
378
|
+
// - 'static' or 'hybrid' output defaults to true (prerender)
|
|
379
|
+
const prerender =
|
|
380
|
+
prerenderConfig !== undefined
|
|
381
|
+
? prerenderConfig
|
|
382
|
+
: astroConfig.output !== 'server'
|
|
383
|
+
|
|
373
384
|
// Create a generated entry file for this specific docs instance
|
|
374
385
|
// This ensures each route has its own getStaticPaths that only returns its own paths
|
|
375
386
|
const generatedDir = join(
|
|
@@ -395,7 +406,12 @@ import { docsConfigs } from 'virtual:shipyard-docs-configs'
|
|
|
395
406
|
import { getEditUrl, getGitMetadata } from '@levino/shipyard-docs'
|
|
396
407
|
import Layout from '@levino/shipyard-docs/astro/Layout.astro'
|
|
397
408
|
|
|
409
|
+
const collectionName = ${JSON.stringify(resolvedCollectionName)}
|
|
410
|
+
const routeBasePath = ${JSON.stringify(normalizedBasePath)}
|
|
411
|
+
|
|
398
412
|
export async function getStaticPaths() {
|
|
413
|
+
// Note: collectionName and routeBasePath must be inlined here because Astro compiles
|
|
414
|
+
// getStaticPaths separately and module-level constants are not available
|
|
399
415
|
const collectionName = ${JSON.stringify(resolvedCollectionName)}
|
|
400
416
|
const routeBasePath = ${JSON.stringify(normalizedBasePath)}
|
|
401
417
|
const allDocs = await getCollection(collectionName)
|
|
@@ -423,7 +439,38 @@ export async function getStaticPaths() {
|
|
|
423
439
|
}))
|
|
424
440
|
}
|
|
425
441
|
|
|
426
|
-
|
|
442
|
+
// In SSR mode (prerender: false), getStaticPaths is not called so Astro.props.entry will be undefined.
|
|
443
|
+
// We need to fetch the entry from the collection based on URL params.
|
|
444
|
+
let entry = Astro.props.entry
|
|
445
|
+
if (!entry) {
|
|
446
|
+
const allDocs = await getCollection(collectionName)
|
|
447
|
+
const docs = allDocs.filter((doc) => doc.data.render !== false)
|
|
448
|
+
|
|
449
|
+
// Reconstruct the entry ID from URL params
|
|
450
|
+
const { locale, slug } = Astro.params
|
|
451
|
+
let entryId
|
|
452
|
+
if (i18n && locale) {
|
|
453
|
+
entryId = slug ? locale + '/' + slug : locale
|
|
454
|
+
} else {
|
|
455
|
+
entryId = slug ?? ''
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Find the matching entry
|
|
459
|
+
entry = docs.find((doc) => doc.id === entryId)
|
|
460
|
+
|
|
461
|
+
// If no exact match, try matching with /index suffix (for index pages)
|
|
462
|
+
// For empty entryId (root path like /docs), look for 'index'
|
|
463
|
+
// For category paths (like /docs/details), look for 'details/index'
|
|
464
|
+
if (!entry) {
|
|
465
|
+
const indexEntryId = entryId ? entryId + '/index' : 'index'
|
|
466
|
+
entry = docs.find((doc) => doc.id === indexEntryId)
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// If still no match, return 404
|
|
470
|
+
if (!entry) {
|
|
471
|
+
return Astro.redirect('/404')
|
|
472
|
+
}
|
|
473
|
+
}
|
|
427
474
|
|
|
428
475
|
const docsConfig = docsConfigs[routeBasePath] ?? {
|
|
429
476
|
showLastUpdateTime: false,
|