Skip to content

Commit

Permalink
feat: CodeTree - source code url
Browse files Browse the repository at this point in the history
  • Loading branch information
luizchaves committed Sep 1, 2024
1 parent 560906b commit fb67b13
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 19 deletions.
10 changes: 8 additions & 2 deletions src/components/CodeTree.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import { resolve } from 'node:path';
import tree from 'tree-node-cli';
import { getHTML } from './CodePreview.astro';
import { prettyCodeOptions } from '../../plugins/rehype-pretty-code-config';
import { GITHUB_EDIT_URL } from '../consts';
export interface Props {
src?: string;
content?: string;
githubUrl?: boolean;
}
const { src, content } = Astro.props;
const { src, content, githubUrl } = Astro.props;
const githubLink = githubUrl
? `[Código Fonte](${GITHUB_EDIT_URL + '/public' + src})`
: '';
const codeTree = existsSync(resolve('./public' + src))
? tree(resolve('./public' + src), { exclude: [/node_modules/] })
: 'Code not found';
const markdown = `\`\`\`plaintext title="Arquivos"\n${
const markdown = `${githubLink}\n\`\`\`plaintext title="Arquivos"\n${
codeTree ?? content
}\n\`\`\``;
Expand Down
4 changes: 2 additions & 2 deletions src/content/classnotes/expressjs/api/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import CodeTree from '../../../../components/CodeTree.astro';

### API de Investimentos

<CodeTree src="/codes/expressjs/invest-app-api/back" />
<CodeTree src="/codes/expressjs/invest-app-api/back" githubUrl={true} />

<CodePreview src="/codes/expressjs/invest-app-api/back/src/data/investments.js" />

Expand Down Expand Up @@ -197,7 +197,7 @@ DELETE {{host}}/investments/{{createdInvestmentId}}

![](/lp2/imgs/expressjs/api/preview.png)

<CodeTree src="/codes/expressjs/invest-app-api/front" />
<CodeTree src="/codes/expressjs/invest-app-api/front" githubUrl={true} />

<CodePreview src="/codes/expressjs/invest-app-api/front/index.html" />

Expand Down
2 changes: 1 addition & 1 deletion src/content/classnotes/expressjs/auth/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CodeTree from '../../../../components/CodeTree.astro';

[Código Fonte](https://github.com/ifpb/lp2/tree/main/public/codes/expressjs/invest-app-auth)

<CodeTree src="/codes/expressjs/invest-app-auth" />
<CodeTree src="/codes/expressjs/invest-app-auth" githubUrl={true} />

## Migration

Expand Down
2 changes: 1 addition & 1 deletion src/content/classnotes/expressjs/db-simple/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CodeTree from '../../../../components/CodeTree.astro';

![](/lp2/imgs/expressjs/db-simple/mvc.png)

<CodeTree src="/codes/expressjs/invest-app-db-simple" />
<CodeTree src="/codes/expressjs/invest-app-db-simple" githubUrl={true} />

## Migration

Expand Down
2 changes: 1 addition & 1 deletion src/content/classnotes/expressjs/email/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import CodeTree from '../../../../components/CodeTree.astro';
$ npm install nodemailer
```

<CodeTree src="/codes/expressjs/invest-app-email" />
<CodeTree src="/codes/expressjs/invest-app-email" githubUrl={true} />

## Back-end

Expand Down
10 changes: 5 additions & 5 deletions src/content/classnotes/expressjs/introduction/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import CodeTree from '../../../../components/CodeTree.astro';

## Exemplo de Express.js

<CodeTree src="/codes/expressjs/hello-simple" />
<CodeTree src="/codes/expressjs/hello-simple" githubUrl={true} />

Fluxo da aplicação hello-simple:

Expand Down Expand Up @@ -101,7 +101,7 @@ Rotas:

Estrutura do código:

<CodeTree src="/codes/expressjs/hello-lang" />
<CodeTree src="/codes/expressjs/hello-lang" githubUrl={true} />

<CodePreview src="/codes/expressjs/hello-lang/src/index.js" />

Expand All @@ -125,7 +125,7 @@ Parâmetros:

Estrutura do código:

<CodeTree src="/codes/expressjs/bmi-query-param" />
<CodeTree src="/codes/expressjs/bmi-query-param" githubUrl={true} />

<CodePreview src="/codes/expressjs/bmi-query-param/src/bmi.js" />

Expand All @@ -139,7 +139,7 @@ Estrutura do código:

Estrutura do código:

<CodeTree src="/codes/expressjs/bmi-route-param" />
<CodeTree src="/codes/expressjs/bmi-route-param" githubUrl={true} />

<CodePreview src="/codes/expressjs/bmi-route-param/src/index.js" highlightLines="7,8" />

Expand All @@ -151,7 +151,7 @@ Estrutura do código:

Estrutura do código:

<CodeTree src="/codes/expressjs/bmi-body-param" />
<CodeTree src="/codes/expressjs/bmi-body-param" githubUrl={true} />

<CodePreview src="/codes/expressjs/bmi-body-param/src/index.js" highlightLines="6,9" />

Expand Down
2 changes: 1 addition & 1 deletion src/content/classnotes/expressjs/mvc/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CodeTree from '../../../../components/CodeTree.astro';

![](/lp2/imgs/expressjs/mvc/mvc-csr.png)

<CodeTree src="/codes/expressjs/invest-app-mvc" />
<CodeTree src="/codes/expressjs/invest-app-mvc" githubUrl={true} />

## Loader

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CodeTree from '../../../../components/CodeTree.astro';

# {frontmatter.title}

<CodeTree src="/codes/expressjs/invest-app-prismajs-relation" />
<CodeTree src="/codes/expressjs/invest-app-prismajs-relation" githubUrl={true} />

## Migration

Expand Down
2 changes: 1 addition & 1 deletion src/content/classnotes/expressjs/prismajs-simple/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $ npm install prisma
$ npx prisma init --datasource-provider sqlite
```

<CodeTree src="/codes/expressjs/invest-app-prismajs-simple" />
<CodeTree src="/codes/expressjs/invest-app-prismajs-simple" githubUrl={true} />

## Migration

Expand Down
2 changes: 1 addition & 1 deletion src/content/classnotes/expressjs/prismajs-user/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CodeTree from '../../../../components/CodeTree.astro';

# {frontmatter.title}

<CodeTree src="/codes/expressjs/invest-app-prismajs-user" />
<CodeTree src="/codes/expressjs/invest-app-prismajs-user" githubUrl={true} />

## Migration

Expand Down
2 changes: 1 addition & 1 deletion src/content/classnotes/expressjs/upload-file/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CodeTree from '../../../../components/CodeTree.astro';

# {frontmatter.title}

<CodeTree src="/codes/expressjs/invest-app-upload" />
<CodeTree src="/codes/expressjs/invest-app-upload" githubUrl={true} />

## Back-end

Expand Down
4 changes: 2 additions & 2 deletions src/content/classnotes/javascript/frontend/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import CodeTree from '../../../../components/CodeTree.astro';

![](/lp2/imgs/w3c/invest-app-read/preview.png)

<CodeTree src="/codes/w3c/invest-app-read" />
<CodeTree src="/codes/w3c/invest-app-read" githubUrl={true} />

<CodePreview src="/codes/w3c/invest-app-read/index.html" />

Expand Down Expand Up @@ -154,7 +154,7 @@ DELETE {{host}}/investments/{{createdInvestmentId}}

### Front-end

<CodeTree src="/codes/w3c/invest-app/front" />
<CodeTree src="/codes/w3c/invest-app/front" githubUrl={true} />

<CodePreview src="/codes/w3c/invest-app/front/index.html" />

Expand Down

0 comments on commit fb67b13

Please sign in to comment.