Skip to content

Commit e9b8a89

Browse files
committed
Adds runme badge plugin
1 parent 3749956 commit e9b8a89

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

docusaurus.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ const config = {
9696
// Please change this to your repo.
9797
// Remove this to remove the "edit this page" links.
9898
editUrl: "https://github.com/stateful/docs.runme.dev/edit/main",
99+
remarkPlugins: [
100+
[
101+
require("./runme-badge-plugin.js"),
102+
{ repository: "https://github.com/stateful/docs.runme.dev.git" },
103+
],
104+
],
99105
},
100106
blog: {
101107
showReadingTime: true,

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
"@docusaurus/preset-classic": "3.1.1",
2020
"@mdx-js/react": "^3.0.0",
2121
"clsx": "^2.1.0",
22+
"js-yaml": "^4.1.0",
2223
"prism-react-renderer": "^2.3.0",
2324
"react": "^18.0.0",
2425
"react-dom": "^18.0.0",
25-
"react-timeout": "^2.0.1"
26+
"react-timeout": "^2.0.1",
27+
"unist-util-visit": "^5.0.0"
2628
},
2729
"devDependencies": {
2830
"@docusaurus/module-type-aliases": "3.1.1",

runme-badge-plugin.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { visit } = require("unist-util-visit");
2+
const path = require("node:path");
3+
const yaml = require("js-yaml");
4+
5+
const runmePlugin = ({ repository }) => {
6+
if (!repository) {
7+
throw new Error("repository is required");
8+
}
9+
10+
const transformer = async (ast, vfile) => {
11+
const markdownPath = vfile.path.replace(`${vfile.cwd}${path.sep}`, "");
12+
let isRunmeFile = false;
13+
14+
visit(ast, "yaml", (node, index, parent) => {
15+
const yml = yaml.load(node.value);
16+
if (yml?.runme) {
17+
isRunmeFile = true;
18+
}
19+
});
20+
21+
if (!isRunmeFile) {
22+
return;
23+
}
24+
25+
visit(ast, "root", (node, index, parent) => {
26+
node.children.unshift({
27+
type: "link",
28+
url: `https://runme.dev/api/runme?repository=${encodeURIComponent(
29+
repository
30+
)}&fileToOpen=${markdownPath}`,
31+
title: "Open with runme",
32+
children: [
33+
{
34+
type: "image",
35+
title: "Open with runme",
36+
url: "https://badgen.net/badge/Open%20with/Runme/5B3ADF?icon=https://runme.dev/img/logo.svg",
37+
alt: "Runme badget",
38+
},
39+
],
40+
});
41+
});
42+
};
43+
44+
return transformer;
45+
};
46+
47+
module.exports = runmePlugin;

0 commit comments

Comments
 (0)