Open MatteoRobbiati opened 1 year ago
The goal is to check whether the extension of the file is in a list of allowed extensions.
For Markdown notes, the list should be [".md", ".mdx"]
. Another option is to check against a RegExp pattern, e.g. /\.mdx?/
.
(or matches at least one pattern in a list, but most likely this is more than what we need)
path
is part of Node.js standard library: https://nodejs.org/api/path.html
The goal is to check whether the extension of the file is in a list of allowed extensions.
This is true for avoiding unsupported files in the tutorials.
The extname
function also solves the problem of unlucky names like you said in a previous comment.
It should be better to have a customized procedure for reading extension for each file, in order to avoid to use strings like
.mdx
or.md
in that process.A smart way for extracting the extension is to use
path.extname
provided by the already involved packagepath
, acting for example in the following way: