Skip to content

Commit c042ad5

Browse files
committed
feat: codeTree with links
1 parent 862dd6a commit c042ad5

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/components/CodeTree.astro

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,37 @@ import { resolve } from 'node:path';
44
import tree from 'tree-node-cli';
55
import { getHTML } from './CodePreview.astro';
66
import { prettyCodeOptions } from '../../plugins/rehype-pretty-code-config';
7+
import { GITHUB_EDIT_URL, GITHUB_PAGES_URL } from '../consts';
78
89
export interface Props {
910
src?: string;
1011
content?: string;
12+
githubUrl?: boolean;
13+
githubPages?: boolean;
14+
devContainerUrl?: boolean;
1115
}
1216
13-
const { src, content } = Astro.props;
17+
const { src, content, githubUrl, githubPages, devContainerUrl } = Astro.props;
18+
19+
const folder = src.split('/').at(-1);
20+
21+
const githubLink = githubUrl
22+
? `<a href="${GITHUB_EDIT_URL + '/public' + src}" target="blank"><img class="inline m-0" src="https://img.shields.io/badge/Open%20In%20GitHub-181717?style=for-the-badge&logo=github&logoColor=white" alt="Open in GitHub"></a>`
23+
: '';
24+
25+
const page = githubPages
26+
? `<a href="${GITHUB_PAGES_URL + src}" target="blank"><img class="inline m-0" src="https://img.shields.io/badge/GitHub%20Pages-181717?style=for-the-badge&logo=github&logoColor=white" alt="Open in GitHub"></a>`
27+
: '';
28+
29+
const devContainerLink = devContainerUrl
30+
? `<a href="https://codespaces.new/ifpb/lp2?devcontainer_path=.devcontainer/${folder}/devcontainer.json" target="blank"><img class="inline m-0" src="https://img.shields.io/badge/Open%20In%20Codespaces-181717?style=for-the-badge&logo=github&logoColor=white" alt="Open in Codespaces"></a>`
31+
: '';
1432
1533
const codeTree = existsSync(resolve('./public' + src))
1634
? tree(resolve('./public' + src), { exclude: [/node_modules/] })
1735
: 'Code not found';
1836
19-
const markdown = `\`\`\`plaintext title="Arquivos"\n${
37+
const markdown = `${githubLink} ${page} ${devContainerLink}\n\`\`\`plaintext title="Arquivos"\n${
2038
codeTree ?? content
2139
}\n\`\`\``;
2240

src/consts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export const SUBJECT = {
4848
// project data
4949
export const GITHUB_EDIT_URL = 'https://github.com/ifpb/ls/tree/main';
5050

51+
export const GITHUB_PAGES_URL = 'https://ifpb.github.io/ls';
52+
5153
export const CONTENT_SLUGS = [
5254
'ecma/introduction',
5355
'ecma/variable',

src/content/classnotes/w3c/dynamic-elements/index.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ body.appendChild(h1);
6363
![](/ls/imgs/w3c/dynamic-elements/invest-app.png)
6464
</div>
6565

66-
{/* [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/ifpb/ls) */}
67-
68-
<CodeTree src="/codes/w3c/dynamic-elements/invest-app" />
66+
<CodeTree src="/codes/w3c/dynamic-elements/invest-app" githubUrl={true} githubPages={true} />
6967

7068
<CodePreview src="/codes/w3c/dynamic-elements/invest-app/index.html" />
7169

0 commit comments

Comments
 (0)