Skip to content

Commit f647892

Browse files
authored
Merge pull request #1 from jordalgo/docs_link_staging
Incorporate docs content into main website
2 parents c161500 + 60fe2c6 commit f647892

File tree

7 files changed

+17509
-2
lines changed

7 files changed

+17509
-2
lines changed

docusaurus.config.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,23 @@ const config = {
9090
position: 'left',
9191
},
9292
{
93-
to: 'https://docs.bpftrace.org/latest',
93+
type: 'dropdown',
9494
label: 'Docs',
95-
target: '_self', // open external link in current window
9695
position: 'left',
96+
items: [
97+
{
98+
label: 'pre-release',
99+
to: '/docs/pre-release'
100+
},
101+
{
102+
label: '0.22 (latest)ds',
103+
to: '/docs/0.22'
104+
},
105+
{
106+
label: '0.21',
107+
to: '/docs/0.21'
108+
},
109+
],
97110
},
98111
{to: '/blog', label: 'Blog', position: 'left'},
99112
{

make-doc.js

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
* This script takes an html file, specifically generated by asciidoctor
5+
* via this command:
6+
* `asciidoctor man/adoc/bpftrace.adoc -b html5 -o adoc.html`
7+
* and transforms it into a js file for the bpftrace website's docs section.
8+
*
9+
* Usage:
10+
* `./make-doc.js adoc.html 0.22` - to make docs from version 0.22
11+
* `./make-doc.js adoc.html` - to make the unreleased/master docs
12+
*/
13+
14+
var fs = require('fs')
15+
var path = require('path')
16+
const { createReadStream } = require('node:fs')
17+
const { createInterface } = require('node:readline')
18+
const templatePath = path.join(__dirname, '/src/pages/docs/__template.js')
19+
20+
const arguments = process.argv
21+
22+
if (arguments.length < 3) {
23+
console.error("Need a adoc html file path e.g. adoc.html");
24+
process.exit(1);
25+
}
26+
27+
const filePath = arguments[2]
28+
const hasVersion = arguments.length == 4
29+
const versionArg = hasVersion ? arguments[3] : "pre-release"
30+
31+
var body = []
32+
var toc = []
33+
const destinationPath = path.join(
34+
__dirname,
35+
'/src/pages/docs/',
36+
versionArg + '.js')
37+
38+
async function processAdoc() {
39+
const fileStream = createReadStream(filePath);
40+
41+
const rl = createInterface({
42+
input: fileStream,
43+
crlfDelay: Infinity,
44+
});
45+
46+
var startToc = false;
47+
var startBody = false;
48+
49+
for await (const line of rl) {
50+
if (line.includes("<ul class=\"sectlevel1\">")) {
51+
startToc = true;
52+
toc.push("<ul className=\"sectlevel1\">");
53+
continue;
54+
}
55+
if (line.includes("<div id=\"content\">")) {
56+
startBody = true;
57+
}
58+
if (startToc) {
59+
toc.push(line);
60+
if (line.includes("</ul>")) {
61+
startToc = false;
62+
}
63+
continue;
64+
}
65+
if (startBody) {
66+
if (line.includes("<div id=\"footer\">")) {
67+
break;
68+
}
69+
if (line.startsWith("<col ") || line === "<col>") {
70+
body.push("<col />")
71+
} else {
72+
body.push(
73+
line.replace(/<br>/ig, "<br />")
74+
.replace(/{/ig, "&#123;")
75+
.replace(/}/ig, "&#125;")
76+
.replace(/class="/ig, "className=\"")
77+
);
78+
}
79+
80+
}
81+
}
82+
83+
fs.readFile(templatePath, {encoding: 'utf-8'}, function(err, data){
84+
if (err) {
85+
console.error("Error reading js template at path: ", templatePath);
86+
console.error(err);
87+
return;
88+
}
89+
90+
const versionHeader = "<h1> Version: " + versionArg + "</h1>"
91+
var versionPage = data.replace("<div id=\"version-content\" />", versionHeader)
92+
.replace("<div id=\"body-content\" />", body.join("\n"))
93+
.replace("<div id=\"toc-content\" />", toc.join("\n"))
94+
95+
fs.writeFile(destinationPath, versionPage, err => {
96+
if (err) {
97+
console.error("Error writing new version doc to path: ", destinationPath);
98+
console.error(err);
99+
return;
100+
}
101+
102+
console.log("Success.");
103+
console.log("Wrote: ", destinationPath);
104+
});
105+
});
106+
}
107+
108+
processAdoc();

src/css/custom.css

+28
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,31 @@
9797
.footer--dark {
9898
--ifm-footer-background-color: #18252D;
9999
}
100+
101+
.docs-container h2 {
102+
scroll-margin-top: calc(var(--ifm-navbar-height) + .5rem);
103+
}
104+
105+
.docs-container h3 {
106+
--ifm-h3-font-size: 1.5rem;
107+
margin-top: calc(var(--ifm-h3-vertical-rhythm-top)* var(--ifm-leading));
108+
scroll-margin-top: calc(var(--ifm-navbar-height) + .5rem);
109+
}
110+
111+
.docs-toc {
112+
max-height: calc(100vh - var(--ifm-navbar-height) - 2rem);
113+
overflow-y: auto;
114+
position: sticky;
115+
top: calc(var(--ifm-navbar-height) + 1rem);
116+
}
117+
118+
.docs-toc ul {
119+
list-style: none;
120+
padding-left: var(--ifm-toc-padding-horizontal);
121+
}
122+
123+
/* Fix for mobile or see if you can use docs classes */
124+
.docs-left-col {
125+
max-width: 75% !important;
126+
}
127+

0 commit comments

Comments
 (0)