@callstack/rspress-preset 0.6.6 → 0.6.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@callstack/rspress-preset",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "Callstack preset for Rspress docs",
5
5
  "author": "Jakub Romańczyk <jakub.romanczyk@callstack.com>",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "@vercel/analytics": "^2.0.1",
44
44
  "rsbuild-plugin-open-graph": "^1.1.2",
45
45
  "zod": "^4.3.6",
46
- "@callstack/rspress-theme": "0.6.6"
46
+ "@callstack/rspress-theme": "0.6.7"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@rspress/core": "^2.0.8"
package/dist/index.cjs DELETED
@@ -1,236 +0,0 @@
1
- "use strict";
2
- const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
- return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
- }();
5
- var __webpack_require__ = {};
6
- (()=>{
7
- __webpack_require__.n = (module)=>{
8
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
9
- __webpack_require__.d(getter, {
10
- a: getter
11
- });
12
- return getter;
13
- };
14
- })();
15
- (()=>{
16
- __webpack_require__.d = (exports1, definition)=>{
17
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
18
- enumerable: true,
19
- get: definition[key]
20
- });
21
- };
22
- })();
23
- (()=>{
24
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
25
- })();
26
- (()=>{
27
- __webpack_require__.r = (exports1)=>{
28
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
29
- value: 'Module'
30
- });
31
- Object.defineProperty(exports1, '__esModule', {
32
- value: true
33
- });
34
- };
35
- })();
36
- var __webpack_exports__ = {};
37
- __webpack_require__.r(__webpack_exports__);
38
- __webpack_require__.d(__webpack_exports__, {
39
- withCallstackPreset: ()=>withCallstackPreset
40
- });
41
- const external_node_fs_namespaceObject = require("node:fs");
42
- var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
43
- const external_node_path_namespaceObject = require("node:path");
44
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
45
- const external_node_url_namespaceObject = require("node:url");
46
- var external_node_url_default = /*#__PURE__*/ __webpack_require__.n(external_node_url_namespaceObject);
47
- const plugin_namespaceObject = require("@callstack/rspress-theme/plugin");
48
- const core_namespaceObject = require("@rspress/core");
49
- const plugin_sitemap_namespaceObject = require("@rspress/plugin-sitemap");
50
- const external_rsbuild_plugin_open_graph_namespaceObject = require("rsbuild-plugin-open-graph");
51
- const external_node_util_namespaceObject = require("node:util");
52
- const external_zod_namespaceObject = require("zod");
53
- const nonEmptyString = external_zod_namespaceObject.z.string().trim().min(1, {
54
- message: 'must be a non-empty string'
55
- });
56
- const presetOptionsSchema = external_zod_namespaceObject.z.object({
57
- context: nonEmptyString.refine((value)=>external_node_path_default().isAbsolute(value), {
58
- message: 'must be an absolute path'
59
- }).describe('Absolute path to the project root'),
60
- docs: external_zod_namespaceObject.z.object({
61
- title: nonEmptyString.describe('Title of the docs'),
62
- description: nonEmptyString.describe("Description of the docs"),
63
- editUrl: external_zod_namespaceObject.z.string().trim().url({
64
- message: 'must be a valid URL'
65
- }).describe('Base URL to repository for edit links'),
66
- logoLight: nonEmptyString.optional().describe('Filename from docs public directory for light mode logo (default: logo-light.png)'),
67
- logoDark: nonEmptyString.optional().describe('Filename from docs public directory for dark mode logo (default: logo-dark.png)'),
68
- icon: nonEmptyString.optional().describe('Filename from docs public directory for site icon (default: icon.png)'),
69
- ogImage: nonEmptyString.optional().describe('Filename from docs public directory for Open Graph image (default: og.png)'),
70
- rootDir: nonEmptyString.optional().describe('Root directory containing markdown docs'),
71
- rootUrl: external_zod_namespaceObject.z.string().trim().url({
72
- message: 'must be a valid URL'
73
- }).describe('Absolute public site origin (e.g. https://example.com)'),
74
- socials: external_zod_namespaceObject.z.record(external_zod_namespaceObject.z.string(), external_zod_namespaceObject.z.url()).optional().describe('Map of social icon name to profile URL')
75
- }),
76
- theme: external_zod_namespaceObject.z.unknown().optional(),
77
- vercelAnalytics: external_zod_namespaceObject.z.union([
78
- external_zod_namespaceObject.z.boolean(),
79
- external_zod_namespaceObject.z.record(external_zod_namespaceObject.z.string(), external_zod_namespaceObject.z.unknown())
80
- ]).optional().describe('Enable/disable Vercel Analytics or pass its config (overrides auto-detect)')
81
- });
82
- function error(...message) {
83
- for (const msg of message)console.error((0, external_node_util_namespaceObject.styleText)('red', msg));
84
- }
85
- function validatePresetOptions(options) {
86
- const result = presetOptionsSchema.safeParse(options);
87
- if (!result.success) {
88
- const bullets = result.error.issues.map((issue)=>{
89
- const pathSegments = issue.path;
90
- const pathLabel = pathSegments.length > 0 ? pathSegments.join('.') : 'root';
91
- let current = presetOptionsSchema;
92
- for (const segment of pathSegments)if (current instanceof external_zod_namespaceObject.z.ZodObject) {
93
- const objectSchema = current;
94
- const shape = objectSchema.shape;
95
- current = shape[String(segment)];
96
- } else if (current instanceof external_zod_namespaceObject.z.ZodRecord) current = current.def.valueType;
97
- else break;
98
- const description = current?._def?.description;
99
- const received = issue.received;
100
- const details = received ? `${issue.message} — received ${received}` : issue.message;
101
- const withDesc = description ? `${details} (${description})` : details;
102
- return `- ${pathLabel}: ${withDesc}`;
103
- }).join('\n');
104
- error('Invalid @callstack/rspress-preset configuration:');
105
- error(bullets);
106
- process.exit(1);
107
- }
108
- return result.data;
109
- }
110
- const CALLSTACK_BASE_URL = 'https://www.callstack.com';
111
- const CALLSTACK_CONTACT_URL = 'https://www.callstack.com/contact';
112
- const preset_filename = external_node_url_default().fileURLToPath(__rslib_import_meta_url__);
113
- const preset_dirname = external_node_path_default().dirname(preset_filename);
114
- function createSocialLinks(socials) {
115
- return Object.entries(socials ?? {}).map(([key, value])=>({
116
- icon: key,
117
- mode: 'link',
118
- content: value
119
- }));
120
- }
121
- function extractXHandle(profileUrl) {
122
- try {
123
- const url = new URL(profileUrl);
124
- const handle = url.pathname.split('/')[1];
125
- return `@${handle}`;
126
- } catch {
127
- throw new Error('Failed to extract X handle from X profile URL');
128
- }
129
- }
130
- function addUTMParameters(url, location, siteTitle) {
131
- const urlObj = new URL(url);
132
- urlObj.searchParams.set('utm_campaign', 'open_source');
133
- urlObj.searchParams.set('utm_source', siteTitle);
134
- urlObj.searchParams.set('utm_medium', 'referral');
135
- urlObj.searchParams.set('utm_content', location);
136
- return urlObj.toString();
137
- }
138
- function getGlobalStyles(context) {
139
- const stylesPath = external_node_path_default().join(context, 'theme/styles.css');
140
- return external_node_fs_default().existsSync(stylesPath) ? stylesPath : void 0;
141
- }
142
- const createPreset = (config)=>{
143
- const { context, docs, vercelAnalytics } = config;
144
- const rootDir = external_node_path_default().join(context, docs.rootDir ?? 'docs');
145
- const enableVercel = void 0 === vercelAnalytics ? external_node_fs_default().existsSync(external_node_path_default().join(context, 'vercel.json')) : Boolean(vercelAnalytics);
146
- const vercelOptions = 'object' == typeof vercelAnalytics ? vercelAnalytics : {};
147
- const defaultLinks = {
148
- docFooterCTA: addUTMParameters(CALLSTACK_CONTACT_URL, 'FOOTER_CTA', docs.title),
149
- homeBanner: addUTMParameters(CALLSTACK_CONTACT_URL, 'HOME_BANNER', docs.title),
150
- homeFooter: CALLSTACK_BASE_URL,
151
- outlineCTA: addUTMParameters(CALLSTACK_CONTACT_URL, 'OUTLINE_CTA', docs.title)
152
- };
153
- const theme = {
154
- ...config.theme,
155
- links: {
156
- ...defaultLinks,
157
- ...config.theme?.links
158
- }
159
- };
160
- return (0, core_namespaceObject.defineConfig)({
161
- root: rootDir,
162
- title: docs.title,
163
- description: docs.description,
164
- icon: docs.icon,
165
- llms: true,
166
- globalStyles: getGlobalStyles(context),
167
- globalUIComponents: enableVercel ? [
168
- [
169
- external_node_path_default().join(external_node_path_default().dirname(preset_dirname), 'vendor/VercelAnalytics.ts'),
170
- {
171
- mode: process.env.NODE_ENV ?? 'development',
172
- ...vercelOptions
173
- }
174
- ]
175
- ] : [],
176
- logo: docs.logoLight || docs.logoDark ? {
177
- light: docs.logoLight ?? docs.logoDark,
178
- dark: docs.logoDark ?? docs.logoLight
179
- } : void 0,
180
- markdown: {
181
- link: {
182
- checkDeadLinks: true
183
- }
184
- },
185
- route: {
186
- cleanUrls: true
187
- },
188
- search: {
189
- versioned: true,
190
- codeBlocks: true
191
- },
192
- themeConfig: {
193
- enableContentAnimation: true,
194
- enableScrollToTop: false,
195
- footer: {
196
- message: `Copyright © ${new Date().getFullYear()} Callstack`
197
- },
198
- editLink: {
199
- docRepoBaseUrl: docs.editUrl
200
- },
201
- socialLinks: createSocialLinks(docs.socials)
202
- },
203
- builderConfig: {
204
- plugins: [
205
- (0, external_rsbuild_plugin_open_graph_namespaceObject.pluginOpenGraph)({
206
- title: docs.title,
207
- type: 'website',
208
- url: docs.rootUrl,
209
- image: docs.rootUrl + docs.ogImage,
210
- description: docs.description,
211
- twitter: docs.socials?.X ? {
212
- site: extractXHandle(docs.socials?.X),
213
- card: 'summary_large_image'
214
- } : void 0
215
- })
216
- ]
217
- },
218
- plugins: [
219
- (0, plugin_namespaceObject.pluginCallstackTheme)(theme),
220
- (0, plugin_sitemap_namespaceObject.pluginSitemap)({
221
- siteUrl: docs.rootUrl
222
- })
223
- ]
224
- });
225
- };
226
- function withCallstackPreset(options, userConfig) {
227
- const parsed = validatePresetOptions(options);
228
- return (0, core_namespaceObject.mergeDocConfig)(createPreset(parsed), userConfig);
229
- }
230
- exports.withCallstackPreset = __webpack_exports__.withCallstackPreset;
231
- for(var __rspack_i in __webpack_exports__)if (-1 === [
232
- "withCallstackPreset"
233
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
234
- Object.defineProperty(exports, '__esModule', {
235
- value: true
236
- });
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { withCallstackPreset } from './preset';
package/dist/index.js DELETED
@@ -1,187 +0,0 @@
1
- import node_fs from "node:fs";
2
- import node_path from "node:path";
3
- import node_url from "node:url";
4
- import { pluginCallstackTheme } from "@callstack/rspress-theme/plugin";
5
- import { defineConfig, mergeDocConfig } from "@rspress/core";
6
- import { pluginSitemap } from "@rspress/plugin-sitemap";
7
- import { pluginOpenGraph } from "rsbuild-plugin-open-graph";
8
- import { styleText } from "node:util";
9
- import { z } from "zod";
10
- const nonEmptyString = z.string().trim().min(1, {
11
- message: 'must be a non-empty string'
12
- });
13
- const presetOptionsSchema = z.object({
14
- context: nonEmptyString.refine((value)=>node_path.isAbsolute(value), {
15
- message: 'must be an absolute path'
16
- }).describe('Absolute path to the project root'),
17
- docs: z.object({
18
- title: nonEmptyString.describe('Title of the docs'),
19
- description: nonEmptyString.describe("Description of the docs"),
20
- editUrl: z.string().trim().url({
21
- message: 'must be a valid URL'
22
- }).describe('Base URL to repository for edit links'),
23
- logoLight: nonEmptyString.optional().describe('Filename from docs public directory for light mode logo (default: logo-light.png)'),
24
- logoDark: nonEmptyString.optional().describe('Filename from docs public directory for dark mode logo (default: logo-dark.png)'),
25
- icon: nonEmptyString.optional().describe('Filename from docs public directory for site icon (default: icon.png)'),
26
- ogImage: nonEmptyString.optional().describe('Filename from docs public directory for Open Graph image (default: og.png)'),
27
- rootDir: nonEmptyString.optional().describe('Root directory containing markdown docs'),
28
- rootUrl: z.string().trim().url({
29
- message: 'must be a valid URL'
30
- }).describe('Absolute public site origin (e.g. https://example.com)'),
31
- socials: z.record(z.string(), z.url()).optional().describe('Map of social icon name to profile URL')
32
- }),
33
- theme: z.unknown().optional(),
34
- vercelAnalytics: z.union([
35
- z.boolean(),
36
- z.record(z.string(), z.unknown())
37
- ]).optional().describe('Enable/disable Vercel Analytics or pass its config (overrides auto-detect)')
38
- });
39
- function error(...message) {
40
- for (const msg of message)console.error(styleText('red', msg));
41
- }
42
- function validatePresetOptions(options) {
43
- const result = presetOptionsSchema.safeParse(options);
44
- if (!result.success) {
45
- const bullets = result.error.issues.map((issue)=>{
46
- const pathSegments = issue.path;
47
- const pathLabel = pathSegments.length > 0 ? pathSegments.join('.') : 'root';
48
- let current = presetOptionsSchema;
49
- for (const segment of pathSegments)if (current instanceof z.ZodObject) {
50
- const objectSchema = current;
51
- const shape = objectSchema.shape;
52
- current = shape[String(segment)];
53
- } else if (current instanceof z.ZodRecord) current = current.def.valueType;
54
- else break;
55
- const description = current?._def?.description;
56
- const received = issue.received;
57
- const details = received ? `${issue.message} — received ${received}` : issue.message;
58
- const withDesc = description ? `${details} (${description})` : details;
59
- return `- ${pathLabel}: ${withDesc}`;
60
- }).join('\n');
61
- error('Invalid @callstack/rspress-preset configuration:');
62
- error(bullets);
63
- process.exit(1);
64
- }
65
- return result.data;
66
- }
67
- const CALLSTACK_BASE_URL = 'https://www.callstack.com';
68
- const CALLSTACK_CONTACT_URL = 'https://www.callstack.com/contact';
69
- const preset_filename = node_url.fileURLToPath(import.meta.url);
70
- const preset_dirname = node_path.dirname(preset_filename);
71
- function createSocialLinks(socials) {
72
- return Object.entries(socials ?? {}).map(([key, value])=>({
73
- icon: key,
74
- mode: 'link',
75
- content: value
76
- }));
77
- }
78
- function extractXHandle(profileUrl) {
79
- try {
80
- const url = new URL(profileUrl);
81
- const handle = url.pathname.split('/')[1];
82
- return `@${handle}`;
83
- } catch {
84
- throw new Error('Failed to extract X handle from X profile URL');
85
- }
86
- }
87
- function addUTMParameters(url, location, siteTitle) {
88
- const urlObj = new URL(url);
89
- urlObj.searchParams.set('utm_campaign', 'open_source');
90
- urlObj.searchParams.set('utm_source', siteTitle);
91
- urlObj.searchParams.set('utm_medium', 'referral');
92
- urlObj.searchParams.set('utm_content', location);
93
- return urlObj.toString();
94
- }
95
- function getGlobalStyles(context) {
96
- const stylesPath = node_path.join(context, 'theme/styles.css');
97
- return node_fs.existsSync(stylesPath) ? stylesPath : void 0;
98
- }
99
- const createPreset = (config)=>{
100
- const { context, docs, vercelAnalytics } = config;
101
- const rootDir = node_path.join(context, docs.rootDir ?? 'docs');
102
- const enableVercel = void 0 === vercelAnalytics ? node_fs.existsSync(node_path.join(context, 'vercel.json')) : Boolean(vercelAnalytics);
103
- const vercelOptions = 'object' == typeof vercelAnalytics ? vercelAnalytics : {};
104
- const defaultLinks = {
105
- docFooterCTA: addUTMParameters(CALLSTACK_CONTACT_URL, 'FOOTER_CTA', docs.title),
106
- homeBanner: addUTMParameters(CALLSTACK_CONTACT_URL, 'HOME_BANNER', docs.title),
107
- homeFooter: CALLSTACK_BASE_URL,
108
- outlineCTA: addUTMParameters(CALLSTACK_CONTACT_URL, 'OUTLINE_CTA', docs.title)
109
- };
110
- const theme = {
111
- ...config.theme,
112
- links: {
113
- ...defaultLinks,
114
- ...config.theme?.links
115
- }
116
- };
117
- return defineConfig({
118
- root: rootDir,
119
- title: docs.title,
120
- description: docs.description,
121
- icon: docs.icon,
122
- llms: true,
123
- globalStyles: getGlobalStyles(context),
124
- globalUIComponents: enableVercel ? [
125
- [
126
- node_path.join(node_path.dirname(preset_dirname), 'vendor/VercelAnalytics.ts'),
127
- {
128
- mode: process.env.NODE_ENV ?? 'development',
129
- ...vercelOptions
130
- }
131
- ]
132
- ] : [],
133
- logo: docs.logoLight || docs.logoDark ? {
134
- light: docs.logoLight ?? docs.logoDark,
135
- dark: docs.logoDark ?? docs.logoLight
136
- } : void 0,
137
- markdown: {
138
- link: {
139
- checkDeadLinks: true
140
- }
141
- },
142
- route: {
143
- cleanUrls: true
144
- },
145
- search: {
146
- versioned: true,
147
- codeBlocks: true
148
- },
149
- themeConfig: {
150
- enableContentAnimation: true,
151
- enableScrollToTop: false,
152
- footer: {
153
- message: `Copyright © ${new Date().getFullYear()} Callstack`
154
- },
155
- editLink: {
156
- docRepoBaseUrl: docs.editUrl
157
- },
158
- socialLinks: createSocialLinks(docs.socials)
159
- },
160
- builderConfig: {
161
- plugins: [
162
- pluginOpenGraph({
163
- title: docs.title,
164
- type: 'website',
165
- url: docs.rootUrl,
166
- image: docs.rootUrl + docs.ogImage,
167
- description: docs.description,
168
- twitter: docs.socials?.X ? {
169
- site: extractXHandle(docs.socials?.X),
170
- card: 'summary_large_image'
171
- } : void 0
172
- })
173
- ]
174
- },
175
- plugins: [
176
- pluginCallstackTheme(theme),
177
- pluginSitemap({
178
- siteUrl: docs.rootUrl
179
- })
180
- ]
181
- });
182
- };
183
- function withCallstackPreset(options, userConfig) {
184
- const parsed = validatePresetOptions(options);
185
- return mergeDocConfig(createPreset(parsed), userConfig);
186
- }
187
- export { withCallstackPreset };
package/dist/options.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import type { pluginCallstackTheme } from '@callstack/rspress-theme/plugin';
2
- import type { AnalyticsProps } from '@vercel/analytics';
3
- import { z } from 'zod';
4
- export declare const presetOptionsSchema: z.ZodObject<{
5
- context: z.ZodString;
6
- docs: z.ZodObject<{
7
- title: z.ZodString;
8
- description: z.ZodString;
9
- editUrl: z.ZodString;
10
- logoLight: z.ZodOptional<z.ZodString>;
11
- logoDark: z.ZodOptional<z.ZodString>;
12
- icon: z.ZodOptional<z.ZodString>;
13
- ogImage: z.ZodOptional<z.ZodString>;
14
- rootDir: z.ZodOptional<z.ZodString>;
15
- rootUrl: z.ZodString;
16
- socials: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodURL>>;
17
- }, z.core.$strip>;
18
- theme: z.ZodOptional<z.ZodUnknown>;
19
- vercelAnalytics: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
20
- }, z.core.$strip>;
21
- type ThemeConfig = Parameters<typeof pluginCallstackTheme>[0];
22
- type PresetSchema = z.infer<typeof presetOptionsSchema>;
23
- export type PresetConfig = Omit<PresetSchema, 'theme' | 'vercelAnalytics'> & {
24
- theme?: ThemeConfig;
25
- vercelAnalytics?: boolean | AnalyticsProps;
26
- };
27
- export declare function validatePresetOptions(options: unknown): PresetConfig;
28
- export {};
package/dist/preset.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { UserConfig } from '@rspress/core';
2
- import { type PresetConfig } from './options';
3
- export declare function withCallstackPreset(options: PresetConfig, userConfig: UserConfig): Promise<UserConfig>;