Skip to content

Commit

Permalink
fix: scroll-y
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Lauber <jan.lauber@protonmail.ch>
  • Loading branch information
janlauber committed Jun 18, 2023
1 parent 137f250 commit c693638
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
4 changes: 4 additions & 0 deletions kubelab-fill/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export LABS_UPLOAD_URL=https://kubelab.swisscom.k8s.natron.cloud/api/collections/labs/records
export EXERCISES_UPLOAD_URL=https://kubelab.swisscom.k8s.natron.cloud/api/collections/exercises/records
export URL_PREFIX=https://raw.githubusercontent.com/natrontech/kubelab-workshops/main/kubernetes-basics/
export WORSHOP_DIR_PATH=/Users/janlauber/code/github.com/natrontech/kubelab-workshops/kubernetes-basics
104 changes: 104 additions & 0 deletions kubelab-fill/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import json
import os
import requests


class Lab:
def __init__(self, title, description, docs):
self.title = title
self.description = description
self.docs = docs


class Exercise:
def __init__(self, title, description, docs, hint, solution, check, bootstrap, lab):
self.title = title
self.description = description
self.docs = docs
self.hint = hint
self.solution = solution
self.check = check
self.bootstrap = bootstrap
self.lab = lab


def post_request(url, data):
try:
headers = {'Content-type': 'application/json'}
response = requests.post(url, data=json.dumps(data), headers=headers)
print(response.text)
except requests.exceptions.RequestException as e:
print(e)


def main():
# from .env import labs_upload_url, exercises_upload_url
labs_upload_url = os.environ['LABS_UPLOAD_URL']
exercises_upload_url = os.environ['EXERCISES_UPLOAD_URL']
prefix = os.environ['URL_PREFIX']
path = os.environ['WORSHOP_DIR_PATH']

labs = get_labs_from_dir(path)
exercises = get_exercises_from_dir(path)

# sort labs and exercises
labs.sort(key=lambda x: x.title)
exercises.sort(key=lambda x: x.title)

for lab in labs:
data = {
'title': lab.title,
'description': lab.description,
'docs': prefix + lab.docs
}
post_request(labs_upload_url, data)


def get_labs_from_dir(path):
labs = []
for name in os.listdir(path):
if os.path.isdir(os.path.join(path, name)):
prename = name
number = name.split("_")[0]
name = name.split("_")[1:]
name = " ".join(name)
name = number+" "+name.title()
labs.append(
Lab(
title=name,
description=name,
docs=prename+"/docs.md"
)
)
return labs


def get_exercises_from_dir(path, level=1, parent=None):
exercises = []
for name in os.listdir(path):
full_path = os.path.join(path, name)
if os.path.isdir(full_path):
if level == 2:
prename = name
number = name.split("_")[0]
name = name.split("_")[1:]
name = " ".join(name)
name = number+" "+name.title()
exercises.append(
Exercise(
title=name,
description=name,
docs=prename+"/docs.md",
hint=prename+"/hint.md",
solution=prename+"/solution.md",
check=prename+"/check.sh",
bootstrap=prename+"/bootstrap.sh",
lab=parent
)
)
exercises.extend(get_exercises_from_dir(full_path, level + 1, parent=name))
return exercises


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion kubelab-ui/src/routes/labs/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="absolute top-16 bottom-0 right-0 left-0 overflow-hidden p-2">
<div class="absolute top-20 bottom-0 right-0 left-0 overflow-y-scroll p-2">
<slot />
</div>

0 comments on commit c693638

Please sign in to comment.