Last active
May 7, 2020 03:06
-
-
Save zootella/fa7c88fccbe01ab27356d9a7bfe04cc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"/> | |
<title>links</title> | |
</head> | |
<body> | |
<p>Output in Console...</p> | |
<script> | |
iTouchedTheRouter(); | |
function iTouchedTheRouter() { | |
function demonstrate(base, target, expected) { | |
var outcome = resolve(base, target); | |
var s = `"${base}" + "${target}" = "${outcome}"`; | |
if (outcome != expected) s += ` ---- but we wanted "${expected}"`; | |
return s; | |
} | |
function resolve(base, relative) { | |
return (new URL(relative, "http://www.example.com" + base)).pathname; | |
} | |
console.log(` | |
"current absolute path" + "relative link target" = "new absolute path" | |
First, with no trailing slashes: | |
${demonstrate("/a/b", "../c", "/c")} go up, then to c | |
${demonstrate("/a/b", "c", "/a/c")} go to c at the same level | |
${demonstrate("/a/b", "b/c", "/a/b/c")} go down to c | |
Even with dot-slash, you (seemingly?) still have to mention b to go down: | |
${demonstrate("/a/b", "../c", "/c")} go up, then to c | |
${demonstrate("/a/b", "./c", "/a/c")} go to c at the same level | |
${demonstrate("/a/b", "./b/c", "/a/b/c")} go down to c | |
Same three, but starting with a trailing slash: | |
${demonstrate("/a/b/", "../../c", "/c")} go up, then to c | |
${demonstrate("/a/b/", "../c", "/a/c")} go to c at the same level | |
${demonstrate("/a/b/", "c", "/a/b/c")} go down to c | |
The webserver knows when b is a directory and when b is a file, | |
and does a 301 redirect to apply the trailing slash when it's a directory. | |
But in magazine, there aren't directories and files, just paths. | |
And my thinking was to ban the trailing slash in magazine entirely. | |
But now I see if you do that, not only does coding it not work, | |
I'm not even sure *how* it should be coded to work. | |
I want there to be no trailing slashes | |
(rather than having some, having them be optional, or having them be required). | |
And, I want to give authors an easy way to link at the same level, | |
or jump up and down levels. | |
So, I could make up my own notation: | |
"/a/b" + "^c" = "/c" go up, then to c | |
"/a/b" + "c" = "/a/c" go to c at the same level | |
"/a/b" + ">c" = "/a/b/c" go down to c | |
but then everyone will ask me why I didn't use the UNIX-standard dots and slashes. | |
And the other thing to think about is: | |
Imagine in the future I'm making the no-JS build that creates many folders and html files. | |
I need to be careful to not come up with something that works well for magazine, | |
but makes a many-file, no-JavaScript build impossible. | |
`); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment