Skip to content

Commit c5e84d0

Browse files
committed
updated cli and cms pages
1 parent f052e26 commit c5e84d0

File tree

3 files changed

+170
-5
lines changed

3 files changed

+170
-5
lines changed

src/content/docs/intro/cli.mdx

+39-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { Aside, Tabs, TabItem, Badge } from '@astrojs/starlight/components'
77
import { PubBadge } from '@/components/PubBadge'
88

99
The Vyuh CLI is a new tool that allows you to quickly scaffold projects,
10-
features, and schemas for the Vyuh framework. It is built on top of the `Mason`
11-
package and includes a few other utilities to make it easier to generate
12-
projects and features.
10+
features, schemas and content-items for the Vyuh framework. It is built on top
11+
of the `Mason` package and includes a few other utilities to make it easier to
12+
generate projects and features.
1313

1414
<Aside type={'note'} title={'PNPM and Melos'}>
1515

@@ -66,7 +66,7 @@ A similar setup is required for those running on **Windows**.
6666

6767
</Aside>
6868

69-
### Create your new project
69+
## Create your new project
7070

7171
<Aside type={'note'} title={'Prerequisites'}>
7272

@@ -178,6 +178,41 @@ Run "vyuh help" to see global options.
178178
179179
```
180180

181+
## Add a new content item
182+
183+
The `vyuh create item <item-name>` command is used to create a new content item
184+
within your Vyuh project. Content items represent individual pieces of content,
185+
such as articles, blog posts, or product descriptions.
186+
187+
```text title="Create Item" {3}
188+
Create a new Vyuh ContentItem.
189+
190+
Usage: vyuh create item <item-name> [arguments]
191+
-h, --help Print this usage information.
192+
-o, --output-directory The desired output directory when creating a new item.
193+
-f, --feature The feature to add the content item to. If not specified, the item will be created without a feature context.
194+
195+
Run "vyuh help" to see global options.
196+
```
197+
198+
The `<item-name>` argument specifies the name of the content item to be created.
199+
The name should be a valid Dart identifier.
200+
201+
The `-o` or `--output-directory` option allows you to specify the directory
202+
where the content item will be created. If not specified, the content item will
203+
be created in the current directory.
204+
205+
The `-f` or `--feature` option allows you to specify the feature to which the
206+
content item belongs. If specified, the content item will be created within the
207+
`lib/content` directory of the specified feature. If not specified, the content
208+
item will be created in the `lib/content` directory of the current project.
209+
210+
After creating the content item, you will need to:
211+
212+
1. Run `dart run build_runner build` to generate the JSON serialization code.
213+
2. Register the `ContentBuilder` in your `FeatureDescriptor` with the
214+
`ContentExtensionDescriptor()`.
215+
181216
## Environment checks with Doctor <Badge text="New" />
182217

183218
The `vyuh doctor` command helps you verify that your development environment is
Loading

src/content/docs/intro/integrating-cms.mdx

+131-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ description: Simple integration of Vyuh with Sanity.io, the default CMS
44
---
55

66
import { PubBadge } from '@/components/PubBadge'
7-
import { Aside } from '@astrojs/starlight/components'
7+
import { Image } from 'astro:assets'
8+
import { Aside, Badge } from '@astrojs/starlight/components'
9+
import refreshButtonImage from './images/refresh-button.png'
810

911
Now that we know how to setup a feature in Vyuh, let's see how we can integrate
1012
it with a CMS. We will be using [Sanity.io](https://sanity.io) for this example,
@@ -282,6 +284,134 @@ launches on the correct port.
282284

283285
</Aside>
284286

287+
## 6. Enable Live Content Editing <sup><Badge text="New" /></sup>
288+
289+
One of the most powerful features of Vyuh is the ability to see content changes
290+
in real-time without having to restart your app or manually refresh. This
291+
feature, called Live Content Editing, significantly improves your development
292+
workflow.
293+
294+
### How to Enable Live Routes
295+
296+
Enabling Live Content Editing is as simple as setting the `useLiveRoute` flag to
297+
`true` on the `DefaultContentPlugin`. Here's how you can modify your main.dart
298+
file:
299+
300+
```dart {13} title="lib/main.dart"
301+
void main() async {
302+
WidgetsFlutterBinding.ensureInitialized();
303+
304+
vc.runApp(
305+
initialLocation: '/blog',
306+
features: () => [
307+
system.feature,
308+
developer.feature,
309+
blog.feature,
310+
],
311+
plugins: PluginDescriptor(
312+
content: DefaultContentPlugin(
313+
useLiveRoute: true, // Enable live routes
314+
provider: SanityContentProvider(
315+
SanityClient(
316+
SanityConfig(
317+
dataset: 'your_dataset',
318+
projectId: 'your_project_id',
319+
token:'your_token',
320+
perspective: Perspective.previewDrafts, // To see draft content
321+
useCdn: false, // Required for live updates
322+
),
323+
),
324+
),
325+
)
326+
),
327+
);
328+
}
329+
```
330+
331+
### Important Configuration Notes
332+
333+
For Live Content Editing to work properly, make sure to:
334+
335+
1. Set `useLiveRoute: true` on the `DefaultContentPlugin`
336+
2. Set `perspective: Perspective.previewDrafts` to see draft content before
337+
publishing
338+
3. Set `useCdn: false` as we want to work with draft content
339+
4. Provide a valid Sanity token with appropriate permissions. Without a valid
340+
token this will fail.
341+
342+
### How It Works
343+
344+
Behind the scenes, Vyuh leverages Sanity's Live Content API to establish a
345+
real-time connection between your app and the CMS. When content changes are made
346+
in the Sanity Studio, the API sends those changes to your app, which then
347+
updates the UI accordingly.
348+
349+
This works in both development and production environments. In production, you
350+
would typically need to publish your content before it appears on customer
351+
devices, unless you specifically configure your app to show draft content.
352+
353+
<Aside type="tip" title="Development vs. Production">
354+
355+
In development, it's useful to see draft content immediately using
356+
`Perspective.previewDrafts`.
357+
358+
For production apps, you might want to switch to `Perspective.published` to
359+
ensure only published content is visible to users.
360+
361+
</Aside>
362+
363+
### Manual Route Refreshing
364+
365+
In addition to live updates, Vyuh also provides a way to manually refresh routes
366+
through the `allowRouteRefresh` parameter. This is useful when you want to give
367+
users the ability to pull-to-refresh content or when you need a refresh button
368+
in your UI.
369+
370+
```dart {14} title="lib/main.dart"
371+
void main() async {
372+
WidgetsFlutterBinding.ensureInitialized();
373+
374+
vc.runApp(
375+
initialLocation: '/blog',
376+
features: () => [
377+
system.feature,
378+
developer.feature,
379+
blog.feature,
380+
],
381+
plugins: PluginDescriptor(
382+
content: DefaultContentPlugin(
383+
useLiveRoute: true,
384+
allowRouteRefresh: true, // Enable manual refreshing
385+
provider: SanityContentProvider(
386+
SanityClient(
387+
SanityConfig(
388+
dataset: 'your_dataset',
389+
projectId: 'your_project_id',
390+
token:'your_token',
391+
perspective: Perspective.previewDrafts,
392+
useCdn: false,
393+
),
394+
),
395+
),
396+
)
397+
),
398+
);
399+
}
400+
```
401+
402+
<Image src={refreshButtonImage} alt={'Manual Refresh Button'} />
403+
404+
This parameter works with both live routes and static routes, giving you
405+
flexibility in how content updates are handled in your application.
406+
407+
<Aside type="note">
408+
409+
Even when `useLiveRoute` is enabled, manual refreshing can still be useful in
410+
certain scenarios, such as when you want to force an immediate refresh rather
411+
than waiting for the next live update.
412+
413+
</Aside>
414+
285415
## Summary
286416

287417
This guide gave you a quick way of creating content on Sanity and seeing it live

0 commit comments

Comments
 (0)