diff --git a/.eslintignore b/.eslintignore index a76ae64..55c1e3b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ vite.config.js -.gitignore \ No newline at end of file +.gitignore +data \ No newline at end of file diff --git a/server/package.json b/server/package.json index 215c7c0..2c70405 100644 --- a/server/package.json +++ b/server/package.json @@ -12,6 +12,7 @@ "dependencies": { "dockerode": "^3.3.5", "express": "^4.18.2", + "marked": "^5.1.1", "mongoose": "^7.4.0", "socket.io": "^4.7.1", "socket.io-client": "^4.7.1", diff --git a/server/quests/helloworld/README.md b/server/quests/helloworld/README.md index 49d5fed..47e651b 100644 --- a/server/quests/helloworld/README.md +++ b/server/quests/helloworld/README.md @@ -4,3 +4,23 @@ order: 1 --- # Hello World + +Welcome to your first quest! This quest will help you familiarize yourself with the terminal. + +The terminal is a text-based interface that allows you to interact directly with your computer's operating system. You can perform various tasks by typing commands into the terminal and pressing `Enter` to execute them. + +For your first task, you are going to use the `echo` command. + +## Task 1: Using the `echo` Command + +The `echo` command in Unix is used to display line of text/string that are passed as an argument. This is a built in command that is mostly used in shell scripts and batch files to output status text to the screen or a file. + +Here is what you need to do: + +1. Open your terminal. +2. Type `echo Hello World` and hit `Enter`. +3. You should see `Hello World` output to the terminal. This is because `echo` prints its arguments to the standard output, which is your terminal by default. + +Congratulation! You've just run your first terminal command! + +Stay tuned for the next quests where you'll delve deeper into more complex and powerful terminal commands. diff --git a/server/src/index.js b/server/src/index.js index 03d68e9..f1f7f34 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -18,6 +18,7 @@ async function main() { const file = await fs.readFile('./swagger.yaml', 'utf8') const swaggerDocument = YAML.parse(file) app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument)) + app.use(express.json()) app.get('/', (req, res) => { res.send('Hello World!') diff --git a/server/src/utils/quest.js b/server/src/utils/quest.js new file mode 100644 index 0000000..eb4e5f9 --- /dev/null +++ b/server/src/utils/quest.js @@ -0,0 +1,40 @@ +import fs from 'fs/promises' +import path from 'path' +import { marked } from 'marked' +import yaml from 'yaml' + +const questDirectory = path.join(process.cwd(), 'quests') + +async function parseQuests() { + const questNames = await fs.readdir(questDirectory) + + const quests = Promise.all( + questNames.map(async (name) => { + const fullPath = path.join(questDirectory, name, 'README.md') + + try { + // Read and parse the README.md file. + const markdown = await fs.readFile(fullPath, 'utf-8') + + // Extract and parse YAML frontmatter. + const match = /---\n([\s\S]+?)\n---/.exec(markdown) + const metadata = yaml.parse(match[1]) + const content = markdown.slice(match[0].length) + const htmlContent = marked.parse(content) + + return { + name, + metadata, + content: htmlContent, + } + } catch (error) { + console.error(`Error parsing quest ${name}:`, error) + return null + } + }) + ) + + return quests +} + +parseQuests().then((quests) => console.log(quests)) diff --git a/yarn.lock b/yarn.lock index 2cc8662..b19df92 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3310,6 +3310,11 @@ makeerror@1.0.12: dependencies: tmpl "1.0.5" +marked@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/marked/-/marked-5.1.1.tgz#40b3963bb9da225314f746d5012ba7e34942f636" + integrity sha512-bTmmGdEINWmOMDjnPWDxGPQ4qkDLeYorpYbEtFOXzOruTwUE671q4Guiuchn4N8h/v6NGd7916kXsm3Iz4iUSg== + media-typer@0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"