Skip to content

Commit c4350a8

Browse files
authored
feat: template inheritance (#99)
1 parent 0644706 commit c4350a8

File tree

18 files changed

+1069
-292
lines changed

18 files changed

+1069
-292
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ dist-ssr
2222
tsconfig.tsbuildinfo
2323
tsconfig.build.tsbuildinfo
2424
.tmp
25+
.tmp-*

docs/tutorialkit.dev/astro.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default defineConfig({
3838
link: '/guides/installation/',
3939
},
4040
{
41-
label: 'Creating a Lesson',
41+
label: 'Content creation',
4242
link: '/guides/creating-content/',
4343
},
4444
{

docs/tutorialkit.dev/src/content/docs/guides/creating-content.mdx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Creating a Lesson
3-
description: 'Creating lessons in TutorialKit.'
2+
title: Content creation
3+
description: 'Creating content in TutorialKit.'
44
---
55
import { FileTree } from '@astrojs/starlight/components';
66

@@ -109,3 +109,38 @@ template: my-advanced-template
109109
```
110110

111111
This declaration will make TutorialKit use the `src/templates/my-advanced-template` directory as the base for the lesson.
112+
113+
If you start having a lot of templates and they all share some files, you can create a shared template that they all extend. This way, you can keep the shared files in one place and avoid duplication. To do that, you need to specify the `extends` property in the template's `.tk-config.json` file:
114+
115+
```json
116+
{
117+
"extends": "../shared-template"
118+
}
119+
```
120+
121+
This will make the template inherit all files from the `shared-template` directory. You can then override any file in the template by placing a file with the same name in the template's directory.
122+
Here's an example of how you can structure your templates:
123+
124+
```
125+
src/templates
126+
├── shared-template
127+
│ ├── index.js
128+
│ ├── index.html
129+
│ └── package.json
130+
131+
└── first-template
132+
│ │ # Contains { "extends": "../shared-template" }
133+
│ │ # Inherits all files from "shared-template"
134+
│ ├── .tk-config.json
135+
│ │
136+
│ │ # Only available in first-template
137+
│ └── main.js
138+
139+
└── second-template
140+
│ # Contains { "extends": "../shared-template" }
141+
│ # Inherits all files from "shared-template"
142+
├── .tk-config.json
143+
144+
│ # Overrides "index.js" from "shared-template"
145+
└── index.js
146+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const RESIZABLE_PANELS = {
22
Main: 'main',
33
} as const;
4+
export const IGNORED_FILES = ['**/.DS_Store', '**/*.swp'];

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { folderPathToFilesRef } from '@tutorialkit/types';
1111
import { getCollection } from 'astro:content';
1212
import glob from 'fast-glob';
1313
import path from 'node:path';
14+
import { IGNORED_FILES } from './constants';
1415
import { logger } from './logger';
1516
import { joinPaths } from './url';
1617

@@ -332,6 +333,8 @@ async function getFilesRefList(pathToFolder: string): Promise<FilesRefList> {
332333
const filePaths = (
333334
await glob(`${glob.convertPathToPattern(root)}/**/*`, {
334335
onlyFiles: true,
336+
ignore: IGNORED_FILES,
337+
dot: true,
335338
})
336339
).map((filePath) => `/${path.relative(root, filePath)}`);
337340

packages/astro/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AstroConfig, AstroIntegration } from 'astro';
22
import { fileURLToPath } from 'node:url';
33
import { extraIntegrations } from './integrations.js';
44
import { updateMarkdownConfig } from './remark/index.js';
5-
import { WebContainerFiles } from './webcontainer-files.js';
5+
import { WebContainerFiles } from './webcontainer-files/index.js';
66
import { userlandCSS, watchUserlandCSS } from './vite-plugins/css.js';
77
import { tutorialkitStore } from './vite-plugins/store.js';
88
import { tutorialkitCore } from './vite-plugins/core.js';
@@ -116,15 +116,15 @@ export default function createPlugin({ defaultRoutes = true, isolation, enterpri
116116
'astro:config:done'({ config }) {
117117
_config = config;
118118
},
119-
'astro:server:setup'(options) {
119+
async 'astro:server:setup'(options) {
120120
if (!_config) {
121121
return;
122122
}
123123

124124
const { server, logger } = options;
125125
const projectRoot = fileURLToPath(_config.root);
126126

127-
webcontainerFiles.serverSetup(projectRoot, options);
127+
await webcontainerFiles.serverSetup(projectRoot, options);
128128

129129
watchUserlandCSS(server, logger);
130130
},

packages/astro/src/webcontainer-files.ts

Lines changed: 0 additions & 285 deletions
This file was deleted.

0 commit comments

Comments
 (0)