@callstack/rspress-preset 0.4.0 → 0.4.1

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/README.md CHANGED
@@ -50,7 +50,7 @@ export default withCallstackPreset(
50
50
  theme: {
51
51
  // theme settings
52
52
  },
53
- // Optional: boolean or config for rspress-plugin-vercel-analytics.
53
+ // Optional: boolean or config for Vercel Analytics.
54
54
  vercelAnalytics: true,
55
55
  },
56
56
  defineConfig({
@@ -61,12 +61,12 @@ export default withCallstackPreset(
61
61
 
62
62
  ### Required/expected public assets
63
63
 
64
- All graphical assets are optional but recommended. Place files in `<docs.rootDir>/public/` (default `docs/public/`), and set their filenames via theme options (`docs.icon`, `docs.logoLight`, `docs.logoDark`, `docs.ogImage`). Defaults are used if omitted.
64
+ All graphical assets are optional but recommended. Place files in `<docs.rootDir>/public/` (default `docs/public/`), and set their filenames via theme options (`docs.icon`, `docs.logoLight`, `docs.logoDark`, `docs.ogImage`).
65
65
 
66
- - **Favicon**: default `icon.png` (supports `png|svg|jpg|jpeg|webp|avif|ico`)
67
- - **Logo (light)**: default `logo-light.png` (supports `png|svg|jpg|jpeg|webp|avif`)
68
- - **Logo (dark)**: default `logo-dark.png` (supports `png|svg|jpg|jpeg|webp|avif`)
69
- - **Open Graph image**: default `og.png` (supports `png|svg|jpg|jpeg|webp|avif`)
66
+ - **Favicon**: e.g. `/icon.png` (supports `png|svg|ico`)
67
+ - **Logo (light)**: e.g. `/logo-light.png` (supports `png|svg|jpg|jpeg|webp|avif`)
68
+ - **Logo (dark)**: e.g. `/logo-dark.png` (supports `png|svg|jpg|jpeg|webp|avif`)
69
+ - **Open Graph image**: e.g. `/og-image.png` (supports `png|svg|jpg|jpeg|webp|avif`)
70
70
 
71
71
  If only one of `logoLight` or `logoDark` is provided, it will be used for both modes.
72
72
 
package/dist/index.cjs CHANGED
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
+ return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
+ }();
2
5
  var __webpack_require__ = {};
3
6
  (()=>{
4
7
  __webpack_require__.n = (module)=>{
@@ -39,13 +42,13 @@ const external_node_fs_namespaceObject = require("node:fs");
39
42
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
40
43
  const external_node_path_namespaceObject = require("node:path");
41
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);
42
47
  const plugin_namespaceObject = require("@callstack/rspress-theme/plugin");
43
48
  const core_namespaceObject = require("@rspress/core");
44
49
  const plugin_llms_namespaceObject = require("@rspress/plugin-llms");
45
50
  const plugin_sitemap_namespaceObject = require("@rspress/plugin-sitemap");
46
51
  const external_rsbuild_plugin_open_graph_namespaceObject = require("rsbuild-plugin-open-graph");
47
- const external_rspress_plugin_vercel_analytics_namespaceObject = require("rspress-plugin-vercel-analytics");
48
- var external_rspress_plugin_vercel_analytics_default = /*#__PURE__*/ __webpack_require__.n(external_rspress_plugin_vercel_analytics_namespaceObject);
49
52
  const external_node_util_namespaceObject = require("node:util");
50
53
  const external_zod_namespaceObject = require("zod");
51
54
  const nonEmptyString = external_zod_namespaceObject.z.string().trim().min(1, {
@@ -106,6 +109,8 @@ function validatePresetOptions(options) {
106
109
  }
107
110
  return result.data;
108
111
  }
112
+ const preset_filename = external_node_url_default().fileURLToPath(__rslib_import_meta_url__);
113
+ const preset_dirname = external_node_path_default().dirname(preset_filename);
109
114
  function createSocialLinks(socials) {
110
115
  return Object.entries(socials ?? {}).map(([key, value])=>({
111
116
  icon: key,
@@ -113,6 +118,15 @@ function createSocialLinks(socials) {
113
118
  content: value
114
119
  }));
115
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
+ }
116
130
  const createPreset = (config)=>{
117
131
  var _docs_socials, _docs_socials1;
118
132
  const { context, docs, theme, vercelAnalytics } = config;
@@ -125,6 +139,15 @@ const createPreset = (config)=>{
125
139
  description: docs.description,
126
140
  icon: docs.icon,
127
141
  globalStyles: external_node_path_default().join(context, 'theme/styles.css'),
142
+ globalUIComponents: enableVercel ? [
143
+ [
144
+ external_node_path_default().join(external_node_path_default().dirname(preset_dirname), 'vendor/VercelAnalytics.ts'),
145
+ {
146
+ mode: process.env.NODE_ENV ?? 'development',
147
+ ...vercelOptions
148
+ }
149
+ ]
150
+ ] : [],
128
151
  logo: docs.logoLight || docs.logoDark ? {
129
152
  light: docs.logoLight ?? docs.logoDark,
130
153
  dark: docs.logoDark ?? docs.logoLight
@@ -159,10 +182,10 @@ const createPreset = (config)=>{
159
182
  title: docs.title,
160
183
  type: 'website',
161
184
  url: docs.rootUrl,
162
- image: `${docs.rootUrl}/${docs.ogImage}`,
185
+ image: docs.rootUrl + docs.ogImage,
163
186
  description: docs.description,
164
- twitter: (null == (_docs_socials = docs.socials) ? void 0 : _docs_socials.x) ? {
165
- site: null == (_docs_socials1 = docs.socials) ? void 0 : _docs_socials1.x,
187
+ twitter: (null == (_docs_socials = docs.socials) ? void 0 : _docs_socials.X) ? {
188
+ site: extractXHandle(null == (_docs_socials1 = docs.socials) ? void 0 : _docs_socials1.X),
166
189
  card: 'summary_large_image'
167
190
  } : void 0
168
191
  })
@@ -175,9 +198,8 @@ const createPreset = (config)=>{
175
198
  }),
176
199
  (0, plugin_llms_namespaceObject.pluginLlms)({
177
200
  exclude: ({ page })=>page.routePath.includes('404')
178
- }),
179
- enableVercel && external_rspress_plugin_vercel_analytics_default()(vercelOptions)
180
- ].filter(Boolean)
201
+ })
202
+ ]
181
203
  });
182
204
  };
183
205
  function withCallstackPreset(options, userConfig) {
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import node_fs from "node:fs";
2
2
  import node_path from "node:path";
3
+ import node_url from "node:url";
3
4
  import { pluginCallstackTheme } from "@callstack/rspress-theme/plugin";
4
5
  import { defineConfig, mergeDocConfig } from "@rspress/core";
5
6
  import { pluginLlms } from "@rspress/plugin-llms";
6
7
  import { pluginSitemap } from "@rspress/plugin-sitemap";
7
8
  import { pluginOpenGraph } from "rsbuild-plugin-open-graph";
8
- import rspress_plugin_vercel_analytics from "rspress-plugin-vercel-analytics";
9
9
  import { styleText } from "node:util";
10
10
  import { z } from "zod";
11
11
  const nonEmptyString = z.string().trim().min(1, {
@@ -66,6 +66,8 @@ function validatePresetOptions(options) {
66
66
  }
67
67
  return result.data;
68
68
  }
69
+ const preset_filename = node_url.fileURLToPath(import.meta.url);
70
+ const preset_dirname = node_path.dirname(preset_filename);
69
71
  function createSocialLinks(socials) {
70
72
  return Object.entries(socials ?? {}).map(([key, value])=>({
71
73
  icon: key,
@@ -73,6 +75,15 @@ function createSocialLinks(socials) {
73
75
  content: value
74
76
  }));
75
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
+ }
76
87
  const createPreset = (config)=>{
77
88
  var _docs_socials, _docs_socials1;
78
89
  const { context, docs, theme, vercelAnalytics } = config;
@@ -85,6 +96,15 @@ const createPreset = (config)=>{
85
96
  description: docs.description,
86
97
  icon: docs.icon,
87
98
  globalStyles: node_path.join(context, 'theme/styles.css'),
99
+ globalUIComponents: enableVercel ? [
100
+ [
101
+ node_path.join(node_path.dirname(preset_dirname), 'vendor/VercelAnalytics.ts'),
102
+ {
103
+ mode: process.env.NODE_ENV ?? 'development',
104
+ ...vercelOptions
105
+ }
106
+ ]
107
+ ] : [],
88
108
  logo: docs.logoLight || docs.logoDark ? {
89
109
  light: docs.logoLight ?? docs.logoDark,
90
110
  dark: docs.logoDark ?? docs.logoLight
@@ -119,10 +139,10 @@ const createPreset = (config)=>{
119
139
  title: docs.title,
120
140
  type: 'website',
121
141
  url: docs.rootUrl,
122
- image: `${docs.rootUrl}/${docs.ogImage}`,
142
+ image: docs.rootUrl + docs.ogImage,
123
143
  description: docs.description,
124
- twitter: (null == (_docs_socials = docs.socials) ? void 0 : _docs_socials.x) ? {
125
- site: null == (_docs_socials1 = docs.socials) ? void 0 : _docs_socials1.x,
144
+ twitter: (null == (_docs_socials = docs.socials) ? void 0 : _docs_socials.X) ? {
145
+ site: extractXHandle(null == (_docs_socials1 = docs.socials) ? void 0 : _docs_socials1.X),
126
146
  card: 'summary_large_image'
127
147
  } : void 0
128
148
  })
@@ -135,9 +155,8 @@ const createPreset = (config)=>{
135
155
  }),
136
156
  pluginLlms({
137
157
  exclude: ({ page })=>page.routePath.includes('404')
138
- }),
139
- enableVercel && rspress_plugin_vercel_analytics(vercelOptions)
140
- ].filter(Boolean)
158
+ })
159
+ ]
141
160
  });
142
161
  };
143
162
  function withCallstackPreset(options, userConfig) {
package/dist/options.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { pluginCallstackTheme } from '@callstack/rspress-theme/plugin';
2
- import type pluginVercelAnalytics from 'rspress-plugin-vercel-analytics';
2
+ import type { AnalyticsProps } from '@vercel/analytics';
3
3
  import { z } from 'zod';
4
4
  export declare const presetOptionsSchema: z.ZodObject<{
5
5
  context: z.ZodEffects<z.ZodString, string, string>;
@@ -73,11 +73,10 @@ export declare const presetOptionsSchema: z.ZodObject<{
73
73
  vercelAnalytics?: boolean | Record<string, unknown> | undefined;
74
74
  }>;
75
75
  type ThemeConfig = Parameters<typeof pluginCallstackTheme>[0];
76
- type VercelAnalyticsConfig = Parameters<typeof pluginVercelAnalytics>[0];
77
76
  type PresetSchema = z.infer<typeof presetOptionsSchema>;
78
77
  export type PresetConfig = Omit<PresetSchema, 'theme' | 'vercelAnalytics'> & {
79
78
  theme?: ThemeConfig;
80
- vercelAnalytics?: boolean | VercelAnalyticsConfig;
79
+ vercelAnalytics?: boolean | AnalyticsProps;
81
80
  };
82
81
  export declare function validatePresetOptions(options: unknown): PresetConfig;
83
82
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@callstack/rspress-preset",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Callstack preset for Rspress docs",
5
5
  "author": "Jakub Romańczyk <jakub.romanczyk@callstack.com>",
6
6
  "license": "MIT",
@@ -16,7 +16,8 @@
16
16
  },
17
17
  "files": [
18
18
  "dist",
19
- "README.md"
19
+ "README.md",
20
+ "vendor"
20
21
  ],
21
22
  "publishConfig": {
22
23
  "access": "public",
@@ -40,10 +41,10 @@
40
41
  "dependencies": {
41
42
  "@rspress/plugin-llms": "2.0.0-beta.32",
42
43
  "@rspress/plugin-sitemap": "2.0.0-beta.32",
44
+ "@vercel/analytics": "^1.5.0",
43
45
  "rsbuild-plugin-open-graph": "^1.0.2",
44
- "rspress-plugin-vercel-analytics": "^0.3.0",
45
46
  "zod": "^3.23.8",
46
- "@callstack/rspress-theme": "0.4.0"
47
+ "@callstack/rspress-theme": "0.4.1"
47
48
  },
48
49
  "peerDependencies": {
49
50
  "@rspress/core": "2.0.0-beta.32"
@@ -0,0 +1,12 @@
1
+ import va from '@vercel/analytics';
2
+ import { useLayoutEffect } from 'react';
3
+
4
+ const VercelAnalytics = (props: Record<string, unknown> = {}) => {
5
+ useLayoutEffect(() => {
6
+ va.inject(props);
7
+ }, []);
8
+
9
+ return null;
10
+ };
11
+
12
+ export default VercelAnalytics;