Skip to content

Commit 5aa649d

Browse files
committed
docs: update README.md
1 parent 6d00f05 commit 5aa649d

File tree

1 file changed

+81
-13
lines changed

1 file changed

+81
-13
lines changed

README.md

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,23 @@ Whether you’re building a static site generator, documentation renderer, or a
2424
.
2525
├── README.md
2626
├── CHANGELOG.md
27-
├── CODE_OF_CONDUCT.md
28-
├── CONTRIBUTING.md
29-
├── LICENSE
27+
├── package.json
28+
├── docs/
29+
│ ├── definitions.md
30+
│ ├── integrations-guide.md
31+
│ └── overview.md
3032
├── schema/
3133
│ ├── v1.0.0/
3234
│ │ ├── sidebar.schema.json
3335
│ │ └── samples/
34-
│ │ ├── meta-valid-sample.yaml
35-
│ │ └── valid-sample.yaml
36+
│ │ └── example.yaml
3637
│ └── latest/
3738
│ ├── sidebar.schema.json
3839
│ └── samples/
39-
│ ├── meta-valid-sample.yaml
40-
│ └── valid-sample.yaml
41-
├── docs/
42-
│ ├── definitions.md
43-
│ ├── integration-guide.md
44-
│ └── overview.md
40+
│ └── example.yaml
41+
├── scripts/
42+
│ ├── yamlToMarkdown.js
43+
│ └── markdownToYaml.js
4544
```
4645

4746
- `latest/` is a pointer to the most recent version of the schema for easy integration. Update it manually on each release, or use a script/symlink strategy.
@@ -58,6 +57,75 @@ Whether you’re building a static site generator, documentation renderer, or a
5857

5958
---
6059

60+
## 🛠️ Conversion Scripts
61+
62+
### `yamlToMarkdown.js`
63+
64+
**Description:**
65+
Converts sidebar YAML files (matching the schema) into readable, structured Markdown navigation lists.
66+
Supports preservation of YAML comments (before each sidebar entry) as Markdown paragraphs, and includes metadata such as the YAML filename and timestamp as Markdown comments.
67+
68+
**Features:**
69+
- Converts all sidebar structure, including nested items, headings, and tags, into Markdown.
70+
- Scalar properties (string, number, boolean) are rendered as `_property_: value`.
71+
- Tags arrays are rendered as Markdown sub-lists.
72+
- YAML comments before each sidebar entry are rendered as Markdown paragraphs after the heading.
73+
- Prepends Markdown comments for the YAML filename and timestamp.
74+
75+
**Usage Example:**
76+
```js
77+
const fs = require('fs');
78+
const { parseYamlWithSidebarComments, convertDataToMarkdown } = require('./scripts/yamlToMarkdown');
79+
80+
const yamlContent = fs.readFileSync('sidebars.yaml', 'utf8');
81+
const data = parseYamlWithSidebarComments(yamlContent);
82+
83+
convertDataToMarkdown(data, { yamlFilePath: 'sidebars.yaml' }).then(markdown => {
84+
fs.writeFileSync('sidebars.md', markdown);
85+
});
86+
```
87+
88+
---
89+
90+
### `markdownToYaml.js`
91+
92+
**Description:**
93+
Converts Markdown navigation lists (as generated by `yamlToMarkdown.js`) back into YAML, reconstructing the sidebar structure and restoring comments as YAML comments.
94+
95+
**Features:**
96+
- Parses Markdown headings, paragraphs, and lists to reconstruct the sidebar data structure.
97+
- Converts Markdown paragraphs between headings and the first list item into YAML comments.
98+
- Scalar properties and tags are faithfully restored.
99+
- Prepends YAML comments for the Markdown filename and timestamp.
100+
101+
**Usage Example:**
102+
```js
103+
const fs = require('fs');
104+
const { convertMarkdownToYaml } = require('./scripts/markdownToYaml');
105+
106+
const markdownContent = fs.readFileSync('sidebars.md', 'utf8');
107+
const yaml = convertMarkdownToYaml(markdownContent, { markdownFilePath: 'sidebars.md' });
108+
fs.writeFileSync('sidebars.generated.yaml', yaml);
109+
```
110+
111+
---
112+
113+
### 🧩 Dependencies
114+
115+
Both scripts require the following libraries (see `package.json`):
116+
117+
- [`js-yaml`](https://www.npmjs.com/package/js-yaml)
118+
- [`yaml`](https://www.npmjs.com/package/yaml)
119+
- [`prettier`](https://www.npmjs.com/package/prettier) (with plugins: `prettier/plugins/estree`, `prettier/plugins/yaml`, `prettier/plugins/markdown`)
120+
121+
Install all dependencies with:
122+
123+
```bash
124+
npm install
125+
```
126+
127+
---
128+
61129
## 🚀 Usage
62130

63131
Clone the repo:
@@ -74,7 +142,7 @@ Explore:
74142

75143
- [`overview.md`](./docs/overview.md): High-level schema purpose and structure
76144
- [`definitions.md`](./docs/definitions.md): Breakdown of reusable components
77-
- [`integration-guide.md`](./docs/integration-guide.md): How to integrate with static site generators or client apps
145+
- [`integrations-guide.md`](./docs/integrations-guide.md): How to integrate with static site generators or client apps
78146

79147
---
80148

@@ -103,4 +171,4 @@ Have a question or feedback? Please use one of the following channels:
103171

104172
Released under the [MIT License](LICENSE). Use it freely in commercial and open-source projects.
105173

106-
---
174+
---

0 commit comments

Comments
 (0)