specra 0.2.12 → 0.2.13
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/config/svelte-config.js +35 -4
- package/dist/utils.d.ts +6 -8
- package/dist/utils.js +8 -15
- package/package.json +1 -1
package/config/svelte-config.js
CHANGED
|
@@ -44,11 +44,35 @@ export function specraMdsvexConfig(options = {}) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Read the deployment basePath from specra.config.json if present.
|
|
49
|
+
* Falls back to the BASE_PATH environment variable, then empty string.
|
|
50
|
+
*/
|
|
51
|
+
function resolveBasePath(configPath = path.join(process.cwd(), 'specra.config.json')) {
|
|
52
|
+
// Environment variable takes priority
|
|
53
|
+
if (process.env.BASE_PATH) return process.env.BASE_PATH
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
if (fs.existsSync(configPath)) {
|
|
57
|
+
const raw = JSON.parse(fs.readFileSync(configPath, 'utf8'))
|
|
58
|
+
if (raw.deployment?.basePath) {
|
|
59
|
+
const bp = raw.deployment.basePath
|
|
60
|
+
// If custom domain is set, ignore basePath
|
|
61
|
+
if (raw.deployment?.customDomain) return ''
|
|
62
|
+
return bp.startsWith('/') ? bp : `/${bp}`
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
// Ignore parse errors
|
|
67
|
+
}
|
|
68
|
+
return ''
|
|
69
|
+
}
|
|
70
|
+
|
|
47
71
|
/**
|
|
48
72
|
* Scan the docs/ directory and return prerender entries for all version root pages.
|
|
49
73
|
* This ensures adapter-static discovers and prerenders every version, not just the active one.
|
|
50
74
|
*/
|
|
51
|
-
function discoverVersionEntries(docsDir = path.join(process.cwd(), 'docs')) {
|
|
75
|
+
function discoverVersionEntries(basePath = '', docsDir = path.join(process.cwd(), 'docs')) {
|
|
52
76
|
const entries = ['/']
|
|
53
77
|
try {
|
|
54
78
|
if (!fs.existsSync(docsDir)) return entries
|
|
@@ -56,7 +80,7 @@ function discoverVersionEntries(docsDir = path.join(process.cwd(), 'docs')) {
|
|
|
56
80
|
const items = fs.readdirSync(docsDir, { withFileTypes: true })
|
|
57
81
|
for (const item of items) {
|
|
58
82
|
if (item.isDirectory() && /^v\d/.test(item.name)) {
|
|
59
|
-
entries.push(
|
|
83
|
+
entries.push(`${basePath}/docs/${item.name}`)
|
|
60
84
|
}
|
|
61
85
|
}
|
|
62
86
|
} catch {
|
|
@@ -66,11 +90,14 @@ function discoverVersionEntries(docsDir = path.join(process.cwd(), 'docs')) {
|
|
|
66
90
|
}
|
|
67
91
|
|
|
68
92
|
/**
|
|
69
|
-
* Create a full SvelteKit config with Specra defaults
|
|
93
|
+
* Create a full SvelteKit config with Specra defaults.
|
|
94
|
+
* Automatically reads deployment.basePath from specra.config.json
|
|
95
|
+
* for GitHub Pages deployments.
|
|
70
96
|
*/
|
|
71
97
|
export function specraConfig(options = {}) {
|
|
72
98
|
const { vitePreprocess } = options.vitePreprocess || {}
|
|
73
99
|
const userPrerender = options.kit?.prerender || {}
|
|
100
|
+
const basePath = options.kit?.paths?.base ?? resolveBasePath()
|
|
74
101
|
|
|
75
102
|
return {
|
|
76
103
|
extensions: ['.svelte', '.md', '.svx', '.mdx'],
|
|
@@ -80,11 +107,15 @@ export function specraConfig(options = {}) {
|
|
|
80
107
|
],
|
|
81
108
|
kit: {
|
|
82
109
|
...options.kit,
|
|
110
|
+
paths: {
|
|
111
|
+
...options.kit?.paths,
|
|
112
|
+
base: basePath,
|
|
113
|
+
},
|
|
83
114
|
prerender: {
|
|
84
115
|
handleHttpError: 'warn',
|
|
85
116
|
handleMissingId: 'warn',
|
|
86
117
|
handleUnseenRoutes: 'warn',
|
|
87
|
-
entries: discoverVersionEntries(),
|
|
118
|
+
entries: discoverVersionEntries(basePath),
|
|
88
119
|
...userPrerender,
|
|
89
120
|
}
|
|
90
121
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { type ClassValue } from 'clsx';
|
|
2
2
|
export declare function cn(...inputs: ClassValue[]): string;
|
|
3
3
|
/**
|
|
4
|
-
* Get the correct asset path based on deployment configuration
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - GitHub Pages without custom domain: Uses basePath from config
|
|
8
|
-
* - Static hosting with custom domain: No basePath needed
|
|
4
|
+
* Get the correct asset path based on deployment configuration.
|
|
5
|
+
* Uses SvelteKit's base path (from kit.paths.base) which is resolved
|
|
6
|
+
* from deployment.basePath in specra.config.json or the BASE_PATH env var.
|
|
9
7
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @returns The properly formatted asset path
|
|
8
|
+
* @param assetPath - The asset path (can start with or without '/')
|
|
9
|
+
* @returns The properly formatted asset path with base prefix
|
|
12
10
|
*/
|
|
13
|
-
export declare function getAssetPath(
|
|
11
|
+
export declare function getAssetPath(assetPath: string): string;
|
package/dist/utils.js
CHANGED
|
@@ -4,27 +4,20 @@ export function cn(...inputs) {
|
|
|
4
4
|
return twMerge(clsx(inputs));
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* Get the correct asset path based on deployment configuration
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - GitHub Pages without custom domain: Uses basePath from config
|
|
11
|
-
* - Static hosting with custom domain: No basePath needed
|
|
7
|
+
* Get the correct asset path based on deployment configuration.
|
|
8
|
+
* Uses SvelteKit's base path (from kit.paths.base) which is resolved
|
|
9
|
+
* from deployment.basePath in specra.config.json or the BASE_PATH env var.
|
|
12
10
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @returns The properly formatted asset path
|
|
11
|
+
* @param assetPath - The asset path (can start with or without '/')
|
|
12
|
+
* @returns The properly formatted asset path with base prefix
|
|
15
13
|
*/
|
|
16
|
-
export function getAssetPath(
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
// Normalize the input path: ensure it starts with '/'
|
|
20
|
-
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
21
|
-
// If we have a basePath (GitHub Pages without custom domain), prepend it
|
|
14
|
+
export function getAssetPath(assetPath) {
|
|
15
|
+
const basePath = process.env.BASE_PATH || '';
|
|
16
|
+
const normalizedPath = assetPath.startsWith('/') ? assetPath : `/${assetPath}`;
|
|
22
17
|
if (basePath) {
|
|
23
|
-
// Normalize basePath: remove trailing slash, ensure leading slash
|
|
24
18
|
const normalizedBase = basePath.startsWith('/') ? basePath : `/${basePath}`;
|
|
25
19
|
const cleanBase = normalizedBase.replace(/\/$/, '');
|
|
26
20
|
return `${cleanBase}${normalizedPath}`;
|
|
27
21
|
}
|
|
28
|
-
// Default: return the normalized path (works for Vercel, custom domains, and dev)
|
|
29
22
|
return normalizedPath;
|
|
30
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "specra",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "A modern documentation library for SvelteKit with built-in versioning, API reference generation, full-text search, and MDX support",
|
|
5
5
|
"svelte": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|