Read all quest data in the folder

This commit is contained in:
wancat committed 2023-07-19 20:01:14 +08:00
1 parent 87f5e86108
commit b2173d180d
6 files changed
+69 -1

No files matched your search

+2 -1
View File
@@ -1,2 +1,3 @@
vite.config.js vite.config.js
.gitignore .gitignore
data
+1
View File
@@ -12,6 +12,7 @@
"dependencies": { "dependencies": {
"dockerode": "^3.3.5", "dockerode": "^3.3.5",
"express": "^4.18.2", "express": "^4.18.2",
"marked": "^5.1.1",
"mongoose": "^7.4.0", "mongoose": "^7.4.0",
"socket.io": "^4.7.1", "socket.io": "^4.7.1",
"socket.io-client": "^4.7.1", "socket.io-client": "^4.7.1",
+20
View File
@@ -4,3 +4,23 @@ order: 1
--- ---
# Hello World # 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.
+1
View File
@@ -18,6 +18,7 @@ async function main() {
const file = await fs.readFile('./swagger.yaml', 'utf8') const file = await fs.readFile('./swagger.yaml', 'utf8')
const swaggerDocument = YAML.parse(file) const swaggerDocument = YAML.parse(file)
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument)) app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument))
app.use(express.json())
app.get('/', (req, res) => { app.get('/', (req, res) => {
res.send('Hello World!') res.send('Hello World!')
+40
View File
@@ -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))
+5
View File
@@ -3310,6 +3310,11 @@ makeerror@1.0.12:
dependencies: dependencies:
tmpl "1.0.5" 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: media-typer@0.3.0:
version "0.3.0" version "0.3.0"
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"