aureliojargas / aurelio.net

Sources for Aurelio.net website
26 stars 6 forks source link

Relative URLs may break (use root-relative) #20

Closed aureliojargas closed 5 years ago

aureliojargas commented 7 years ago

In Apache and GitHub Pages, a slashless folder URL is always 301 redirected to have a trailing slash:

In Netlify, both URLs are served. This breaks relative URLs for links and images, since now the "current" folder could be / or /shell, depending on the trailing slash presence.

One solution is to always use absolute URLs, for everything. I cannot browse the site locally (offline), but will have a consistent absolute-only references. The absolute URL can use the full domain or be just the path (called root-relative). Too many options to decide :(

Update: That was a Netlify bug, see https://github.com/aureliojargas/aurelio.net/issues/34#issuecomment-345417286. Now the folder redirects are working ok. But regardless, I'll leave this issue open because fixing those paths is a good idea.

aureliojargas commented 6 years ago

Using the full URL (domain + path) has the advantage of correctly loading the resources from the internet when viewing the site locally or from a feed reader. I will take this route.

aureliojargas commented 6 years ago

Commands to find the offending files:

# Images using /foo (HTML, Markdown, txt2tags)
git grep 'src="/[^/]'
git grep '!\[\](/[^/]'
git grep '\[/'

# links pointing to /foo (HTML and Markdown)
git grep "href=['\"]/[^/]"
git grep "\](/[^/]"
aureliojargas commented 6 years ago

After reading about URL best practices, I've changed my mind: will use root-relative URLs instead of absolute.

I'll keep those previous commits that added the domain. But all the relative URLs will be changed for root-relative.

# Silly ./ (leading and at the middle)
git grep -E '(src|href)="\./'
git grep -E '(src|href)="[^"]*/\./'

# Odd ../ (leading and at the middle)
git grep -E '(src|href)="\.\./'
git grep -E '(src|href)="[^"]*/\.\./'
aureliojargas commented 6 years ago

Well there is a lot more, since I was not doing a case insensitive search :(

# Silly ./ (leading and at the middle)
git grep -Ei '(src|href)="\./'
git grep -Ei '(src|href)="[^"]*/\./'

# Odd ../ (leading and at the middle)
git grep -Ei '(src|href)="\.\./'
git grep -Ei '(src|href)="[^"]*/\.\./'
aureliojargas commented 6 years ago

Well, it is a pain to fix the paths in txt2tags files with all the includes, preproc, postproc and magic.

So for now I'll wait for issue #11 be concluded. Then there is no txt2tags files and I can fix the path only in HTML files.

aureliojargas commented 6 years ago

To unbreak the site now, I've hardcoded 301 redirects to force always serving with the trailing slash. See issue #34.

aureliojargas commented 6 years ago

My workaround is not necessary anymore, problem fixed. See https://github.com/aureliojargas/aurelio.net/issues/34#issuecomment-345417286.

aureliojargas commented 5 years ago

At this point, all the links containing ./ and ../ where converted to root-relative links.

$ check-site                        
Running check_accidental_liquid_markup...
Running check_missing_article_date...
Running check_windows_linebreak...
Running check_unquoted_attributes...
Running check_mixed_content...
Running check_relative_urls...
$

I've left untouched the links . and .. for now. I also did not change the relative links which don't use dots.

I'll adapt the check-site script to detect those and continue the fixing.

aureliojargas commented 5 years ago

The original problem for this issue was fixed.

The URLs fixing work will continue in issue #65.