Skip to content

Commit dccc2ad

Browse files
committed
fix: code review
1 parent 71c10f4 commit dccc2ad

File tree

12 files changed

+31
-25
lines changed

12 files changed

+31
-25
lines changed

docs/tutorialkit.dev/src/content/docs/reference/configuration.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type I18nText = {
5353
*
5454
* @default 'Edit this page'
5555
*/
56-
editPage?: string
56+
editPageText?: string
5757

5858
/**
5959
* Text shown when there are no previews or steps to show in the prepare environment section.
@@ -179,12 +179,12 @@ Specified which folder from the `src/templates/` directory should be used as the
179179

180180
#### `editPageLink`
181181
Display a link in lesson for editing the page content.
182-
The value is a URL pattern where `:path` is replaced with the lesson's location relative to the `src/content/tutorial`.
182+
The value is a URL pattern where `${path}` is replaced with the lesson's location relative to the `src/content/tutorial`.
183183

184184
<PropertyTable inherited type="string|false" />
185185

186186
```yaml
187-
editPageLink: https://github.com/stackblitz/tutorialkit/blob/main/packages/template/src/content/tutorial/:path
187+
editPageLink: https://github.com/stackblitz/tutorialkit/blob/main/packages/template/src/content/tutorial/${path}
188188
```
189189
190190
The inherited value can be disabled in specific parts using `false`.
@@ -198,8 +198,8 @@ Note that Github will try to automatically render the `.md` files when linked to
198198
You can instruct Github to show the source code instead by adding `plain=1` query parameter.
199199

200200
```diff
201-
-editPageLink: https://github.com/stackblitz/tutorialkit/blob/main/packages/template/src/content/tutorial/:path
202-
+editPageLink: https://github.com/stackblitz/tutorialkit/blob/main/packages/template/src/content/tutorial/:path?plain=1
201+
-editPageLink: https://github.com/stackblitz/tutorialkit/blob/main/packages/template/src/content/tutorial/${path}
202+
+editPageLink: https://github.com/stackblitz/tutorialkit/blob/main/packages/template/src/content/tutorial/${path}?plain=1
203203
```
204204

205205
:::

docs/tutorialkit.dev/src/content/docs/reference/theming.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ The navigation cards are the cards at the bottom of a lesson to navigate to the
318318

319319
### Edit Page Link
320320

321-
The edit page link is shown above the navigation cards when configured by [`editPageLink` option](../configuration/#editpagelink).
321+
The edit page link is shown above the navigation cards when configured by [`editPageLink` option](/reference/configuration/#editpagelink).
322322

323323
![Edit Page Link](./images/theming-editpagelink.png)
324324

packages/astro/src/default/components/TutorialContent.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const { Markdown, editPageLink, prev, next } = lesson;
2424
class="inline-flex flex-items-center text-tk-elements-editPageLink-textColor hover:text-tk-elements-editPageLink-textColorHover hover:underline"
2525
>
2626
<span class="icon i-ph-note-pencil pointer-events-none h-5 w-5 mr-2 text-tk-elements-editPageLink-iconColor group-hover:text-tk-elements-editPageLink-iconColorHover" />
27-
<span>{lesson.data.i18n!.editPage}</span>
27+
<span>{lesson.data.i18n!.editPageText}</span>
2828
</a>
2929
</div>
3030
)

packages/astro/src/default/utils/content.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
Tutorial,
88
TutorialSchema,
99
} from '@tutorialkit/types';
10-
import { folderPathToFilesRef } from '@tutorialkit/types';
10+
import { folderPathToFilesRef, interpolateString } from '@tutorialkit/types';
1111
import { getCollection } from 'astro:content';
1212
import glob from 'fast-glob';
1313
import path from 'node:path';
@@ -44,7 +44,7 @@ export async function getTutorial(): Promise<Tutorial> {
4444
partTemplate: 'Part ${index}: ${title}',
4545
noPreviewNorStepsText: 'No preview to run nor steps to show',
4646
startWebContainerText: 'Run this tutorial',
47-
editPage: 'Edit this page',
47+
editPageText: 'Edit this page',
4848
} satisfies Lesson['data']['i18n'],
4949
tutorialMetaData.i18n,
5050
);
@@ -289,7 +289,7 @@ export async function getTutorial(): Promise<Tutorial> {
289289
}
290290

291291
if (lesson.data.editPageLink && typeof lesson.data.editPageLink === 'string') {
292-
lesson.editPageLink = lesson.data.editPageLink.replace(':path', lesson.filepath);
292+
lesson.editPageLink = interpolateString(lesson.data.editPageLink, { path: lesson.filepath });
293293
}
294294
}
295295

packages/components/react/src/Nav.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { Lesson, NavItem, NavList } from '@tutorialkit/types';
1+
import { interpolateString, type Lesson, type NavItem, type NavList } from '@tutorialkit/types';
22
import * as Accordion from '@radix-ui/react-accordion';
33
import navStyles from './styles/nav.module.css';
44
import { classNames } from './utils/classnames.js';
55
import { AnimatePresence, cubicBezier, motion } from 'framer-motion';
66
import { useCallback, useRef, useState } from 'react';
77
import { useOutsideClick } from './hooks/useOutsideClick.js';
8-
import { interpolateString } from './utils/interpolation.js';
98

109
const dropdownEasing = cubicBezier(0.4, 0, 0.2, 1);
1110

packages/components/react/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ export * from './Panels/TerminalPanel.js';
66
export * from './Panels/WorkspacePanel.js';
77
export type * from './core/types.js';
88
export * from './utils/classnames.js';
9-
export * from './utils/interpolation.js';

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export type * from './entities/index.js';
22
export * from './schemas/index.js';
33
export * from './files-ref.js';
4+
export { interpolateString } from './utils/interpolation.js';

packages/types/src/schemas/common.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,18 @@ export const webcontainerSchema = commandsSchema.extend({
151151
}),
152152
]),
153153
i18n: i18nSchema.optional(),
154-
});
155-
156-
export const editPageLinkSchema = z.union([
157-
// pattern for creating the URL
158-
z.string(),
154+
editPageLink: z.union([
155+
// pattern for creating the URL
156+
z.string(),
159157

160-
// `false` for disabling the edit link
161-
z.boolean(),
162-
]);
158+
// `false` for disabling the edit link
159+
z.boolean(),
160+
]),
161+
});
163162

164163
export const baseSchema = webcontainerSchema.extend({
165164
title: z.string(),
166165
slug: z.string().optional(),
167-
editPageLink: editPageLinkSchema.optional(),
168166
});
169167

170168
export type BaseSchema = z.infer<typeof baseSchema>;

packages/types/src/schemas/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const i18nSchema = z.object({
1313
*
1414
* @default 'Edit this page'
1515
*/
16-
editPage: z.string().optional(),
16+
editPageText: z.string().optional(),
1717

1818
/**
1919
* Text shown when there are no previews or steps to show in the prepare environment section.

packages/types/src/schemas/tutorial.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { z } from 'zod';
2-
import { webcontainerSchema, editPageLinkSchema } from './common.js';
2+
import { webcontainerSchema } from './common.js';
33

44
export const tutorialSchema = webcontainerSchema.extend({
55
type: z.literal('tutorial'),
66
logoLink: z.string().optional(),
7-
editPageLink: editPageLinkSchema.optional(),
87
parts: z.array(z.string()).optional(),
98
});
109

packages/components/react/src/utils/interpolation.spec.ts renamed to packages/types/src/utils/interpolation.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ describe('interpolateString', () => {
99
expect(interpolateString(template, variables)).toBe('Hello, world!');
1010
});
1111

12+
it('should interpolate variables inside URL', () => {
13+
const template =
14+
'https://github.com/stackblitz/tutorialkit/blob/main/packages/template/src/content/tutorial/${path}?plain=1';
15+
const variables = { path: '1-basics/2-foo/1-welcome/content.md' };
16+
17+
expect(interpolateString(template, variables)).toBe(
18+
'https://github.com/stackblitz/tutorialkit/blob/main/packages/template/src/content/tutorial/1-basics/2-foo/1-welcome/content.md?plain=1',
19+
);
20+
});
21+
1222
it('should interpolate multiple variables', () => {
1323
const template = 'Part ${index}: ${title}';
1424
const variables = { index: 5, title: 'Welcome to foo bar' };

0 commit comments

Comments
 (0)