Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wget option Added along with a new dropdown menu #265

Merged
merged 30 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
22717ed
Some changes for the new wget code panel
guptaaryan16 Jun 26, 2023
e6ed93a
Made some more changes and refactoring
guptaaryan16 Jun 26, 2023
671cc09
Added text copy button
guptaaryan16 Jun 26, 2023
e53aac9
Merge branch 'main' of github.com:guptaaryan16/code-generator into wg…
guptaaryan16 Jun 26, 2023
a19bb7f
Merge branch 'pytorch-ignite:main' into wget_option
guptaaryan16 Jun 26, 2023
b414c57
Update PaneLeft.vue
guptaaryan16 Jun 26, 2023
dbf657c
Made some changes
guptaaryan16 Jun 26, 2023
886c501
changed the configuration of code option and download button
guptaaryan16 Jun 30, 2023
5da0df4
Made few changes in CSS styles of NavCode.vue
guptaaryan16 Jun 30, 2023
e88bcd6
Fix bug for NavDownload success message
guptaaryan16 Jun 30, 2023
bcb492b
Made final changes for the Code dropdown button
guptaaryan16 Jul 4, 2023
9394123
A minor change
guptaaryan16 Jul 4, 2023
e92d7da
Minor fixes
guptaaryan16 Jul 4, 2023
efe1642
Minor change
guptaaryan16 Jul 4, 2023
d1f3293
Minor fix
guptaaryan16 Jul 4, 2023
95b9888
Last fix
guptaaryan16 Jul 4, 2023
0f37ac9
minor change in the NavCode
guptaaryan16 Jul 4, 2023
3e03699
Merge branch 'pytorch-ignite:main' into wget_option
guptaaryan16 Jul 4, 2023
6682e82
Last fix
guptaaryan16 Jul 4, 2023
273e7a6
UI fixes
guptaaryan16 Jul 4, 2023
75e4094
Made all the required UI fixes for now
guptaaryan16 Jul 5, 2023
fc47f36
reconfigured tests
guptaaryan16 Jul 6, 2023
4dc775b
Made some changes
guptaaryan16 Jul 7, 2023
f73ed43
Added changes to CSS of NavCode and NavDownload for center alignmnet
guptaaryan16 Jul 10, 2023
aa9d21e
Added copy notification in NavCode
guptaaryan16 Jul 10, 2023
cff1ff9
Fixed issues and reformatted the NavCode tab
guptaaryan16 Jul 10, 2023
96fbb30
Fixed button styles, formatting and tests
guptaaryan16 Jul 11, 2023
8cbaecd
Merge branch 'main' of https://github.com/guptaaryan16/code-generator…
guptaaryan16 Jul 11, 2023
24d79d6
Fix tests for failing on await
guptaaryan16 Jul 13, 2023
76cfe0a
Fixed and reduced CSS for NavCode.vue
guptaaryan16 Jul 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions functions/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Below imports are defined in
// `external_node_modules` of [functions] in netlify.toml
// They are required for this function to run

import { v4 as uuidv4 } from 'uuid'
import JSZip from 'jszip'
import { pushToGitHub } from './utils'

const nbUid = uuidv4()
const repoOwner = process.env.VUE_APP_GH_USER
const repo = process.env.VUE_APP_GH_REPO

// This function is the one Netlify function runs on
// https://docs.netlify.com/functions/build-with-javascript/#synchronous-function-format
exports.handler = async function (event, _) {
// event is a JSON object
const data = JSON.parse(event.body)
const zip = new JSZip()
const code = data.code
const template = `ignite-${data.template}`

// As usual from Download component,
// we will zip the files and
// generate a base64 format for pushing to GitHub
// with Octokit.
for (const filename in code) {
zip.file(filename, code[filename])
}
const content = await zip.generateAsync({ type: 'base64' })
const zipRes = await pushToGitHub(content, `${template}.zip`, nbUid)
vfdev-5 marked this conversation as resolved.
Show resolved Hide resolved
return {
statusCode: 200,
body: zipRes
}
}
38 changes: 7 additions & 31 deletions functions/colab.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,13 @@
// They are required for this function to run

import { v4 as uuidv4 } from 'uuid'
import { Octokit } from '@octokit/core'
import JSZip from 'jszip'
import { pushToGitHub } from './utils'
vfdev-5 marked this conversation as resolved.
Show resolved Hide resolved

const nbUid = uuidv4()
const repoOwner = process.env.VUE_APP_GH_USER
const repo = process.env.VUE_APP_GH_REPO

/**
* Create a file on GitHub with Octokit.
* @param {string} content
* @param {string} filename
* @returns download_url
*/
async function pushToGitHub(content, filename) {
const octokit = new Octokit({
auth: process.env.VUE_APP_GH_TOKEN
})
try {
const res = await octokit.request(
'PUT /repos/{owner}/{repo}/contents/{path}',
{
owner: repoOwner,
repo: repo,
path: `nbs/${nbUid}/${filename}`,
message: `nb: add ${nbUid}`,
content: content
}
)
// the download url is raw url - https://raw.githubusercontent.com/...
return res.data.content.download_url
} catch (e) {
console.error(e)
}
}

// This function is the one Netlify function runs on
// https://docs.netlify.com/functions/build-with-javascript/#synchronous-function-format
exports.handler = async function (event, _) {
Expand All @@ -56,7 +28,7 @@ exports.handler = async function (event, _) {
zip.file(filename, code[filename])
}
const content = await zip.generateAsync({ type: 'base64' })
const zipRes = await pushToGitHub(content, `${template}.zip`)
const zipRes = await pushToGitHub(content, `${template}.zip`, nbUid)

const title = template
.replace('ignite-', '')
Expand Down Expand Up @@ -100,7 +72,11 @@ exports.handler = async function (event, _) {
]
}
// Create the notebook on GitHub
await pushToGitHub(Buffer.from(JSON.stringify(nb)).toString('base64'), nbName)
await pushToGitHub(
Buffer.from(JSON.stringify(nb)).toString('base64'),
nbName,
nbUid
)

const colabLink = `https://colab.research.google.com/github/${repoOwner}/${repo}/blob/main/nbs/${nbUid}/${nbName}`
return {
Expand Down
35 changes: 35 additions & 0 deletions functions/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Below imports are defined in
// `external_node_modules` of [functions] in netlify.toml
// They are required for this function to run

import { Octokit } from '@octokit/core'

const repoOwner = process.env.VUE_APP_GH_USER
const repo = process.env.VUE_APP_GH_REPO

/**
* Create a file on GitHub with Octokit.
* @param {string} content
* @param {string} filename
* @returns download_url
*/
export async function pushToGitHub(content, filename, nbUid) {
const octokit = new Octokit({
auth: process.env.VUE_APP_GH_TOKEN
})
try {
const res = await octokit.request(
'PUT /repos/{owner}/{repo}/contents/{path}',
{
owner: repoOwner,
repo: repo,
path: `nbs/${nbUid}/${filename}`,
message: `nb: add ${nbUid}`,
content: content
}
)
return res.data.content.download_url
} catch (e) {
console.error(e)
}
}
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
/>
<title>Code Generator</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[dev]
publish = "dist/"
targetPort = 3000
targetPort = 5000

[functions]
directory = "functions"
Expand Down
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/components/CodeBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ div[class*='language-']::before,
position: absolute;
top: 0;
bottom: 0;
z-index: 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why these z-index removals ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the rendering of this code block the terminal margin line appears in front of the Download Zip Success message and without removing z index, this problem could not be fixed

border-right: 1px solid rgba(0, 0, 0, 0.5);
padding: 1.25rem 0;
width: 3.5rem;
Expand All @@ -140,7 +139,6 @@ div[class*='language-']::before,
.line-numbers {
position: relative;
font-size: var(--code-font-size);
z-index: 4;
user-select: none;
}

Expand Down
Loading