Skip to content

Commit 7e7032d

Browse files
committed
add metabar
1 parent 314d524 commit 7e7032d

File tree

7 files changed

+104
-86
lines changed

7 files changed

+104
-86
lines changed
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
export default () => <div>MetaBar</div>;
1+
import MetaBar from '@node-core/ui-components/Containers/MetaBar';
2+
import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub.tsx';
3+
4+
export default ({ headings, addedIn, readingTime, viewAs, editThisPage }) => {
5+
return (
6+
<MetaBar
7+
heading="Table of Contents"
8+
headings={{ items: headings }}
9+
items={{
10+
'Added In': addedIn,
11+
'Reading Time': readingTime,
12+
'View As': viewAs.map(([title, path]) => <a href={path}>{title}</a>),
13+
Contribute: (
14+
<>
15+
<GitHubIcon className="fill-neutral-700 dark:fill-neutral-100" />
16+
<a href={editThisPage}>Edit this page</a>
17+
</>
18+
),
19+
}}
20+
/>
21+
);
22+
};

src/generators/web/constants.mjs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
import { fileURLToPath } from 'node:url';
22

3-
import tailwindcss from '@tailwindcss/postcss';
4-
import stylePlugin from 'esbuild-style-plugin';
5-
import postcssCalc from 'postcss-calc';
6-
7-
import uiResolver from './utils/esbuild-plugin.mjs';
8-
/**
9-
* @type {import('esbuild').BuildOptions}
10-
*/
11-
export const ESBUILD_CONFIG = {
12-
bundle: true,
13-
minify: false,
14-
format: 'iife',
15-
target: 'es2020',
16-
platform: 'browser',
17-
jsx: 'automatic',
18-
write: false,
19-
// This file is never created due to `write: false`, but we need
20-
// to specify it for ESBuild.
21-
outfile: 'output.js',
22-
plugins: [
23-
stylePlugin({
24-
postcss: {
25-
plugins: [tailwindcss(), postcssCalc()],
26-
},
27-
}),
28-
uiResolver,
29-
],
30-
};
31-
323
export const ESBUILD_RESOLVE_DIR = fileURLToPath(
334
new URL('./components', import.meta.url)
345
);

src/generators/web/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { generate } from '@babel/generator';
55
import Mustache from 'mustache';
66

77
import buildProgram from './utils/buildProgram.mjs';
8-
import { bundle } from './utils/bundle.mjs';
8+
import bundleCode from './utils/bundleCode.mjs';
99

1010
/**
1111
* This generator generates a JavaScript / HTML / CSS bundle from the input JSX AST
@@ -39,7 +39,7 @@ export default {
3939
entries.map(async entry => {
4040
const program = buildProgram(entry);
4141
const { code } = generate(program);
42-
const bundled = await bundle(code);
42+
const bundled = await bundleCode(code);
4343

4444
// All bundles share the same CSS
4545
if (!css) {

src/generators/web/utils/buildProgram.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const buildProgram = entry =>
3030
...Object.values(JSX_IMPORTS).map(({ name, source }) =>
3131
getImport(name, source)
3232
),
33+
// ReactDOM.createRoot(document.getElementById("root")).render([ our AST ])
3334
t.expressionStatement(
3435
t.callExpression(
3536
t.memberExpression(

src/generators/web/utils/bundle.mjs

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { existsSync } from 'node:fs';
2+
import { fileURLToPath } from 'node:url';
3+
4+
import tailwindcss from '@tailwindcss/postcss';
5+
import esbuild from 'esbuild';
6+
import stylePlugin from 'esbuild-style-plugin';
7+
import postcssCalc from 'postcss-calc';
8+
9+
import { ESBUILD_RESOLVE_DIR } from '../constants.mjs';
10+
11+
const uiComponentsResolver = {
12+
name: 'ui-components-resolver',
13+
/**
14+
* This plugin intercepts imports starting with '@node-core/ui-components' or '#ui/' and resolves them
15+
* to the corresponding index.tsx file in the node_modules directory. If the index.tsx file
16+
* doesn't exist, the resolution falls back to the default behavior.
17+
* @param {import('esbuild').PluginBuild} build
18+
*/
19+
setup(build) {
20+
build.onResolve({ filter: /^(@node-core\/ui-components|#ui\/)/ }, args => {
21+
// Skip if path already has file extension
22+
if (/\.[a-zA-Z0-9]+$/.test(args.path)) {
23+
return undefined;
24+
}
25+
26+
// Normalize #ui/ prefix to @node-core/ui-components/
27+
const normalizedPath = args.path.replace(
28+
/^#ui\//,
29+
'@node-core/ui-components/'
30+
);
31+
32+
// Resolve to index.tsx file
33+
const indexPath = fileURLToPath(
34+
import.meta.resolve(`${normalizedPath}/index.tsx`)
35+
);
36+
37+
return existsSync(indexPath) ? { path: indexPath } : undefined;
38+
});
39+
},
40+
};
41+
42+
/**
43+
* Bundles JavaScript code and returns JS/CSS content
44+
* @param {string} code - Source code to bundle
45+
* @returns {Promise<{js: string, css: string}>}
46+
*/
47+
export default async code => {
48+
const result = await esbuild.build({
49+
stdin: {
50+
contents: code,
51+
resolveDir: ESBUILD_RESOLVE_DIR,
52+
},
53+
bundle: true,
54+
minify: true,
55+
format: 'iife',
56+
target: 'es2020',
57+
platform: 'browser',
58+
jsx: 'automatic',
59+
write: false,
60+
// This output file is a pseudo-file. It's never written to (`write: false`),
61+
// but it gives ESLint a basename for the output.
62+
outfile: 'output.js',
63+
plugins: [
64+
stylePlugin({
65+
postcss: {
66+
plugins: [tailwindcss(), postcssCalc()],
67+
},
68+
}),
69+
uiComponentsResolver,
70+
],
71+
});
72+
73+
const [jsFile, cssFile] = result.outputFiles;
74+
75+
return {
76+
js: jsFile.text,
77+
css: cssFile.text,
78+
};
79+
};

src/generators/web/utils/esbuild-plugin.mjs

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)