Skip to content

Commit

Permalink
Merge pull request #1 from jordalgo/docs_link_staging
Browse files Browse the repository at this point in the history
Incorporate docs content into main website
  • Loading branch information
jordalgo authored Jan 27, 2025
2 parents c161500 + 60fe2c6 commit f647892
Show file tree
Hide file tree
Showing 7 changed files with 17,509 additions and 2 deletions.
17 changes: 15 additions & 2 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,23 @@ const config = {
position: 'left',
},
{
to: 'https://docs.bpftrace.org/latest',
type: 'dropdown',
label: 'Docs',
target: '_self', // open external link in current window
position: 'left',
items: [
{
label: 'pre-release',
to: '/docs/pre-release'
},
{
label: '0.22 (latest)ds',
to: '/docs/0.22'
},
{
label: '0.21',
to: '/docs/0.21'
},
],
},
{to: '/blog', label: 'Blog', position: 'left'},
{
Expand Down
108 changes: 108 additions & 0 deletions make-doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env node

/*
* This script takes an html file, specifically generated by asciidoctor
* via this command:
* `asciidoctor man/adoc/bpftrace.adoc -b html5 -o adoc.html`
* and transforms it into a js file for the bpftrace website's docs section.
*
* Usage:
* `./make-doc.js adoc.html 0.22` - to make docs from version 0.22
* `./make-doc.js adoc.html` - to make the unreleased/master docs
*/

var fs = require('fs')
var path = require('path')
const { createReadStream } = require('node:fs')
const { createInterface } = require('node:readline')
const templatePath = path.join(__dirname, '/src/pages/docs/__template.js')

const arguments = process.argv

if (arguments.length < 3) {
console.error("Need a adoc html file path e.g. adoc.html");
process.exit(1);
}

const filePath = arguments[2]
const hasVersion = arguments.length == 4
const versionArg = hasVersion ? arguments[3] : "pre-release"

var body = []
var toc = []
const destinationPath = path.join(
__dirname,
'/src/pages/docs/',
versionArg + '.js')

async function processAdoc() {
const fileStream = createReadStream(filePath);

const rl = createInterface({
input: fileStream,
crlfDelay: Infinity,
});

var startToc = false;
var startBody = false;

for await (const line of rl) {
if (line.includes("<ul class=\"sectlevel1\">")) {
startToc = true;
toc.push("<ul className=\"sectlevel1\">");
continue;
}
if (line.includes("<div id=\"content\">")) {
startBody = true;
}
if (startToc) {
toc.push(line);
if (line.includes("</ul>")) {
startToc = false;
}
continue;
}
if (startBody) {
if (line.includes("<div id=\"footer\">")) {
break;
}
if (line.startsWith("<col ") || line === "<col>") {
body.push("<col />")
} else {
body.push(
line.replace(/<br>/ig, "<br />")
.replace(/{/ig, "&#123;")
.replace(/}/ig, "&#125;")
.replace(/class="/ig, "className=\"")
);
}

}
}

fs.readFile(templatePath, {encoding: 'utf-8'}, function(err, data){
if (err) {
console.error("Error reading js template at path: ", templatePath);
console.error(err);
return;
}

const versionHeader = "<h1> Version: " + versionArg + "</h1>"
var versionPage = data.replace("<div id=\"version-content\" />", versionHeader)
.replace("<div id=\"body-content\" />", body.join("\n"))
.replace("<div id=\"toc-content\" />", toc.join("\n"))

fs.writeFile(destinationPath, versionPage, err => {
if (err) {
console.error("Error writing new version doc to path: ", destinationPath);
console.error(err);
return;
}

console.log("Success.");
console.log("Wrote: ", destinationPath);
});
});
}

processAdoc();
28 changes: 28 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,31 @@
.footer--dark {
--ifm-footer-background-color: #18252D;
}

.docs-container h2 {
scroll-margin-top: calc(var(--ifm-navbar-height) + .5rem);
}

.docs-container h3 {
--ifm-h3-font-size: 1.5rem;
margin-top: calc(var(--ifm-h3-vertical-rhythm-top)* var(--ifm-leading));
scroll-margin-top: calc(var(--ifm-navbar-height) + .5rem);
}

.docs-toc {
max-height: calc(100vh - var(--ifm-navbar-height) - 2rem);
overflow-y: auto;
position: sticky;
top: calc(var(--ifm-navbar-height) + 1rem);
}

.docs-toc ul {
list-style: none;
padding-left: var(--ifm-toc-padding-horizontal);
}

/* Fix for mobile or see if you can use docs classes */
.docs-left-col {
max-width: 75% !important;
}

Loading

0 comments on commit f647892

Please sign in to comment.