3 ms·
I recently thought through this problem and came up with the concept of building of a list of "candidates" for a given URL. Then the caller loops through and re
by simpaticoder 3y ago
I recently thought through this problem and came up with the concept of building of a list of "candidates" for a given URL. Then the caller loops through and returns the first candidate that actually exists. It's a nice boundary between functions. I wrote up my solution in literate markdown (and javascript) here [0].
(Apart from supporting optional extensions, this code also supports throwing an error if someone prepends dots into the url - which, for me, indicates someone probing the server for weaknesses and is not a legit request.)
The funny thing is that I still often use file extensions since IntelliJ can only let me easily navigate/check existence if I use the extension.
Eventually I'll support slugs in the filename by just ignoring everything after the first dash.
0 - https://simpatico.io/reflector#urltofilename https://simpatico.io/reflector#urltofilename