Skip to content

Commit 685504c

Browse files
authored
Merge pull request #3 from ioncakephper:chore/convert-to-markdown
Chore/convert-to-markdown
2 parents 0a7739a + 0b26820 commit 685504c

File tree

4 files changed

+613
-12
lines changed

4 files changed

+613
-12
lines changed

README.md

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

63135
Clone the repo:
@@ -74,7 +146,7 @@ Explore:
74146

75147
- [`overview.md`](./docs/overview.md): High-level schema purpose and structure
76148
- [`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
149+
- [`integrations-guide.md`](./docs/integrations-guide.md): How to integrate with static site generators or client apps
78150

79151
---
80152

0 commit comments

Comments
 (0)