Skip to content

Conversation

@emmadal
Copy link
Contributor

@emmadal emmadal commented Oct 19, 2021

Parse markdown and generate JSON file for exercises

@linear
Copy link

linear bot commented Oct 19, 2021

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 19, 2021

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0842a27
Status: ✅  Deploy successful!
Preview URL: https://fce05f6a.platform-nan-dev-8sl.pages.dev

View logs

Copy link
Member

@kigiri kigiri left a comment

Choose a reason for hiding this comment

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

ya encore d'autres trucs a review je pense mais tu peu deja avancer sur les points que j'ai mis en avant la

const isH2 = (node) => node.type === 'heading' && node.depth === 2
const isH3 = (node) => node.type === 'heading' && node.depth === 3
const text = (node) => node.type === 'paragraph'
const isList = (node) => node.type === 'list'
Copy link
Member

Choose a reason for hiding this comment

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

I don't think text is a good name to check if something is a paragraph. I you want to keep it short call it isP and isList could be isLI so it's like HTML tags

just text give me the impression that it will return the text of the node

return content
}

const dirList = await readdir('js-introduction')
Copy link
Member

Choose a reason for hiding this comment

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

the name of the directory should be defined by the build.js file, not hard coded here

.flatMap((e) => e.children)
.flatMap((v) => v.children)
.map((k) => k.value)
content.notions = ul
Copy link
Member

Choose a reason for hiding this comment

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

fait plutot:

content.notions = children(node).map(getTrimValue).filter(Boolean)

} else if (mode === 'instructions') {
if (text(node)) {
let p = node.children.map((e) => e.value)
content.instructions = p.join('')
Copy link
Member

Choose a reason for hiding this comment

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

On veut garder la structure, juste stock toute la node, pas besoin de faire un cas special.
Comme ca on pourra render tout les element en (p)react

}
} else if (mode) {
// any other mode is stored in raw tree
content[mode].push(node)
Copy link
Member

Choose a reason for hiding this comment

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

## Instructions pourra etre gerer ici

content[mode].push(node)
} else {
// before any mode is set, we are writing the description
content.description += textContent(node)
Copy link
Member

Choose a reason for hiding this comment

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

ca vaut ptet le coup de rajouter un \n quand on concatene ici:

content.description += `${textContent(node).trim()}\n`

await rename(
join(fileURLToPath(dirname(import.meta.url)), `../${file}`),
join(fileURLToPath(dirname(import.meta.url)), `../exoBundle/${file}`),
)
Copy link
Member

Choose a reason for hiding this comment

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

ca serais bien d'avoir:

const rootDir = fileURLToPath(dirname(import.meta.url))

plutot que de le repeter a chaque fois

})

const rootFile = await (
await readdir('./')
Copy link
Member

Choose a reason for hiding this comment

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

la t'utilise un chemin relatif, ton script va pas faire la meme chose en fonction du cwd, ou tu le run, c'est mieu de ce baser sur la position du fichier la avec fileURLToPath(dirname(import.meta.url)) comme tu l'a fait ailleur


export const generateExoFile = async () => {
dirList.map(async (filename) => {
const data = Object.fromEntries(entries)[`${filename}`]
Copy link
Member

Choose a reason for hiding this comment

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

[`${filename}`] -> [filename]

dev/server.js Outdated
sendResponse({ body, options, res })
}).listen(PORT, () => console.log(`Dev server ready on ${process.env.DOMAIN}`))
}).listen(PORT, async () => {
await generateExoFile()
Copy link
Member

Choose a reason for hiding this comment

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

il faudrais generer avant ca, et aussi s'assurer que les fichier sont accessible a fetch


const moveFile = async (file) =>
await rename(join(rootDir, file), join(rootDir, 'exoBundle', file))
await rename(join(rootDir, file), join(rootDir, 'exobundle', file))
Copy link
Member

Choose a reason for hiding this comment

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

pas besoin d'async / await la:

const moveFile = (file) =>
  rename(join(rootDir, file), join(rootDir, 'exobundle', file))

await (await readdir(rootDir))
.filter((file) => file.includes('exercise.json'))
.map(moveFile)
return await Promise.all(
Copy link
Member

Choose a reason for hiding this comment

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

pas besoin d'await quand tu return non plus

dev/server.js Outdated

// generate bundle for js-introduction exercise
await getJsonExoFile()
await generateJSONExo()
Copy link
Member

Choose a reason for hiding this comment

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

j'avais fais des commentaires a ce niveau, le generate doit etre fait pas build.js, non pas par le server.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

J'ai completement omis de l'enlever je le faisais pour des tests locaux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants