Skip to content

Commit ecaf86c

Browse files
authored
feat: add support for section directories (#162)
* add generation support for section folders * rename folder * run yarn generate * comment * remove redundant line * update readme * modify output * fix section name * generate * improve loggin * remove space * update readme * update link
1 parent 1d05741 commit ecaf86c

File tree

38 files changed

+238
-209
lines changed

38 files changed

+238
-209
lines changed

README.md

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,49 @@
44

55
## Overview
66

7-
`Gno By Example` is a community-dedicated web app that showcases the fundamentals of Gnolang, the Smart Contract
8-
language
9-
used on [Gno.land](https://gno.land).
7+
`Gno By Example` is a community-dedicated web app that showcases the fundamentals
8+
of Gnolang, the Smart Contract
9+
language used on [Gno.land](https://gno.land).
1010

1111
## Contributing
1212

13-
The base application is built with `React` and utilizes the `Chakra UI` framework. You will need `Node v20+` to run it
14-
locally.
13+
The base application is built with `React` and utilizes the `Chakra UI` framework.
14+
You will need `Node v20+` to run it locally.
1515

16-
Since the project is community-run, users can contribute new tutorials or modify existing ones.
16+
As a community-driven project, users are welcome to contribute by creating new
17+
tutorials or modifying existing ones.
1718

18-
As a community-driven project, users are welcome to contribute by creating new tutorials or modifying existing ones.
19-
20-
All tutorials are located within the `./src/tutorials/gno.land/gbe` subdirectory. Tutorials are automatically generated
19+
All tutorials are located within the
20+
[`./src/tutorials/gno.land/gbe`](./src/tutorials/gno.land/gbe) subdirectory
21+
in their respective section folders. Tutorials are automatically generated
2122
from corresponding `.md` files, with each tutorial having its own subdirectory.
2223

2324
![Banner](.github/assets/contribution-flow.png)
2425

2526
### Generating tutorials
2627

27-
After making modifications to tutorial files (`.md` or other resources), it is necessary to regenerate the global list
28-
of tutorials by running the following command:
28+
After making modifications to tutorial files (`.md` or other resources), it is
29+
necessary to regenerate the global list of tutorials by running the following
30+
command:
2931

3032
```bash
3133
yarn generate
3234
```
3335

34-
This command executes the tutorial route generation script, ensuring that all tutorials are up to date and ready for
35-
dynamic display. Make sure to run this command from the repository root.
36+
This command executes the tutorial route generation script, ensuring that all
37+
tutorials are up-to-date and ready for dynamic display. Make sure to run this
38+
command from the repository root.
3639

3740
### Markdown format
3841

3942
Tutorials can be written using Markdown syntax.
4043

4144
#### Metadata header
4245

43-
A markdown header with some specific metadata is mandatory. This makes it possible for the tutorial generator script to
44-
correctly parse and organize examples.
45-
`title` and `section` values have to be set as part of the metadata at the top of the markdown file:
46+
A markdown header with some specific metadata is mandatory. This makes it
47+
possible for the tutorial generator script to correctly parse and organize examples.
48+
`title` and `section` values have to be set as part of the metadata at the
49+
top of the markdown file:
4650

4751
```md
4852
---
@@ -51,29 +55,40 @@ section: Example Section
5155
---
5256
```
5357

58+
Note: The `section` field in the metadata header will ultimately decide under
59+
which section the tutorial is generated in.
60+
5461
#### Code snippets
5562

56-
In Gno By Example, there is a special feature that allows referencing entire external files or specific line numbers
57-
from those files, outside of the Markdown files themselves.
63+
In Gno By Example, there is a special feature that allows referencing entire
64+
external files or specific line numbers from those files, outside of the Markdown
65+
files themselves.
5866

59-
To embed the entire content of a specific file inside a code segment, use the following syntax:
67+
To embed the entire content of a specific file inside a code segment, use the
68+
following syntax:
6069

6170
````md
6271
```go file=./myFile.gno
6372
```
6473
````
6574

66-
To embed specific line numbers from an external file inside a code segment, use the following syntax:
75+
To embed specific line numbers from an external file inside a code segment, use
76+
the following syntax:
6777

6878
````md
6979
```go file=./myFile.gno#L1-L2
7080
```
7181
````
7282

73-
The above syntax will embed the content of the first two lines (inclusive) from the `./myFile.gno` file.
83+
The above syntax will embed the content of the first two lines (inclusive) from
84+
the `./myFile.gno` file.
85+
86+
If your sample code relies on another code, you can define the dependencies.
87+
Each dependency code will be shown in a separate tab.
88+
A typical scenario occurs when your sample code is a test file. In order for
89+
your test file to be executable, you need to include the actual implementation
90+
as a dependency.
7491

75-
If your sample code relies on another code, you can define the dependencies. Each dependency code will be shown in a separate tab.
76-
A typical scenario occurs when your sample code is a test file. In order for your test file to be executable, you need to include the actual implementation as a dependency.
7792
To define dependencies, use the following syntax:
7893

7994
````md

scripts/generate.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,22 +230,37 @@ const generateTutorialRoutes = async (items: TutorialItem[], outputFile: string)
230230
// Generate the corresponding tutorials in the subdirectories
231231
// and write out the tutorial routes
232232
const generateTutorials = async () => {
233-
const baseDir: string = './src/tutorials/gno.land/gbe';
234-
// const baseDir: string = './scripts/dummy';
235-
const subDirs: string[] = fs.readdirSync(baseDir);
233+
const baseDirPath: string = './src/tutorials/gno.land/gbe';
234+
235+
const sectionDirs: string[] = fs.readdirSync(baseDirPath);
236236
const tutorialItems: TutorialItem[] = [];
237237

238-
for (const subDir of subDirs) {
239-
const subDirPath: string = path.join(baseDir, subDir);
240-
const isDirectory: boolean = fs.statSync(subDirPath).isDirectory();
238+
// Find section subdirs
239+
for (const sectionName of sectionDirs) {
240+
const sectionDirPath: string = path.join(baseDirPath, sectionName);
241+
const isDirectory: boolean = fs.statSync(sectionDirPath).isDirectory();
241242

242-
if (isDirectory) {
243-
// Generate the tutorial for this subdirectory
244-
const item: TutorialItem = await parseTutorial(subDirPath);
243+
// Ignore non-dirs
244+
if (!isDirectory) {
245+
continue
246+
}
245247

246-
tutorialItems.push(item);
248+
console.log(`➡️ Scanning section directory "${sectionName}":`);
249+
const tutorialDirs: string[] = fs.readdirSync(sectionDirPath);
250+
// Find tutorial subdirs in each section
251+
for (const tutorialName of tutorialDirs) {
252+
const tutorialDirPath: string = path.join(sectionDirPath, tutorialName);
253+
const isDirectory: boolean = fs.statSync(tutorialDirPath).isDirectory();
247254

248-
console.log(`✅ Generated tutorial for: ${subDirPath}`);
255+
// Ignore non-dirs
256+
if (!isDirectory) {
257+
continue
258+
}
259+
260+
// Generate the tutorial for this subdirectory
261+
const item: TutorialItem = await parseTutorial(tutorialDirPath);
262+
tutorialItems.push(item);
263+
console.log(`\t ✨ Generated tutorial: ${item.section} - ${tutorialName}`);
249264
}
250265
}
251266

src/tutorials.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import helloWorld from "./tutorials/gno.land/gbe/01-hello/index";
2-
import firstApp from "./tutorials/gno.land/gbe/02-count/index";
3-
import primitives from "./tutorials/gno.land/gbe/03-primitives/index";
4-
import variables from "./tutorials/gno.land/gbe/04-variables/index";
5-
import constants from "./tutorials/gno.land/gbe/05-constants/index";
6-
import conditions from "./tutorials/gno.land/gbe/06-conditions/index";
7-
import loops from "./tutorials/gno.land/gbe/07-loops/index";
1+
import helloWorld from "./tutorials/gno.land/gbe/getting-started/01-hello/index";
2+
import firstApp from "./tutorials/gno.land/gbe/getting-started/02-count/index";
3+
import primitives from "./tutorials/gno.land/gbe/getting-started/03-primitives/index";
4+
import variables from "./tutorials/gno.land/gbe/getting-started/04-variables/index";
5+
import constants from "./tutorials/gno.land/gbe/getting-started/05-constants/index";
6+
import conditions from "./tutorials/gno.land/gbe/getting-started/06-conditions/index";
7+
import loops from "./tutorials/gno.land/gbe/getting-started/07-loops/index";
88

99
const tutorials = [
1010
{

src/tutorials/gno.land/gbe/01-hello/index.ts

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

src/tutorials/gno.land/gbe/02-count/index.ts

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

src/tutorials/gno.land/gbe/03-primitives/index.ts

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

src/tutorials/gno.land/gbe/04-variables/index.ts

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

0 commit comments

Comments
 (0)