Skip to content

Commit 240e21f

Browse files
create a hidden samples.md
which is the concatenation of all of the sample readmes. it shouldn't be visible in the sidebar, but it should be accessible with the url so that the docs chatbot can link to it as a reference
1 parent 17b33b0 commit 240e21f

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ yarn-error.log*
2121

2222
defang
2323
samples
24-
/static/samples-v2.json
24+
/docs/samples.md
25+
/static/samples-v2.json

scripts/prep-samples.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const path = require('path');
33
const YAML = require('yaml');
44

55
const samplesDir = process.argv[2];
6+
let samplesMdContent = ''
67

78
// Inspired by https://github.com/compose-spec/compose-go/blob/main/template/template.go
89
const interpolationRegex =
@@ -23,6 +24,12 @@ directories.forEach((sample) => {
2324
let readme;
2425
try {
2526
readme = fs.readFileSync(path.join(samplesDir, sample, 'README.md'), 'utf8');
27+
// replace the text after the first `#` with a link to the sample
28+
// readme = readme.replace(/^# (.*)/, `# [$1](https://github.com/DefangLabs/samples/tree/main/samples/${sample})`);
29+
readme = readme.replace(/^# (.*)/, (match, p1) => {
30+
return `# [${p1}](https://github.com/DefangLabs/samples/tree/main/samples/${sample})`;
31+
});
32+
samplesMdContent += readme + "\n\n";
2633
} catch (error) {
2734
readme = `# ${sample}`;
2835
}
@@ -102,14 +109,30 @@ directories.forEach((sample) => {
102109

103110
const stringified = JSON.stringify(jsonArray, null, 2);
104111

105-
// fs.writeFileSync(path.join(__dirname, '..', 'samples.json'), stringified);
112+
// exclude any lines which start with '---'
113+
samplesMdContent = samplesMdContent.replace(/---.*\n/g, '');
114+
// exclude any lines which include markdown images `![`
115+
samplesMdContent = samplesMdContent.replace(/^.*!\[.*\]\(.*\).*\n?/gm, '');
106116

107-
// we're going to open up the ../docs/samples.md file and replce [] with the stringified JSON
117+
// increase the header level of all headers in the markdown content
118+
samplesMdContent = samplesMdContent.replace(/^(#{1,6})\s/gm, (match) => {
119+
const headerLevel = match.length - 1; // number of '#' characters
120+
const newHeaderLevel = Math.min(headerLevel + 1, 6);
121+
return '#'.repeat(newHeaderLevel) + ' ';
122+
});
108123

109-
// const samplesMd = path.join(__dirname, '..', 'docs', 'samples.md');
110-
// let samplesMdContents = fs.readFileSync(samplesMd, 'utf8');
111-
// samplesMdContents += `<Samples samples={${stringified}} />`;
112-
// fs.writeFileSync(samplesMd, samplesMdContents);
124+
const frontMatter = `---
125+
sidebar_class_name: hidden
126+
title: Samples
127+
description: A collection of sample applications and configurations for Defang Labs.
128+
---
129+
`;
130+
// prefix samplesMdContent with the front matter
131+
samplesMdContent = frontMatter + "\n\n" + samplesMdContent;
132+
133+
const samplesMd = path.join(__dirname, '..', 'docs', 'samples.md');
134+
console.log(`@@ Writing samples markdown to ${samplesMd}`);
135+
fs.writeFileSync(samplesMd, samplesMdContent);
113136

114137
// save the json to the samples.json file in static
115138
fs.writeFileSync(path.join(__dirname, '..', 'static', 'samples-v2.json'), stringified);

src/css/custom.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,8 @@ img.unstyled {
137137
to {
138138
background-position: 200% 0;
139139
}
140-
}
140+
}
141+
142+
.menu__list-item.hidden {
143+
display: none;
144+
}

0 commit comments

Comments
 (0)