Making Relative Links
04/11/15
So, I almost forgot that I still have references to local links as absolute paths (aka http://www.ksionda.me/blog/ instead of /blog/).
I got a findReplace script (though I could also just use sed for this, I'm trying to keep site modifications pure HTML5), so let's make unnecessary absolute path links relative..
First off, let's find all the posts that have such a link. I'm going to break my HTML5 focus and just use grep. Let's just count the total occurances.
$ grep -R '"http://ksionda.me\|"http://www.ksionda.me' public/
360
So, that's about 180 occurances, and 180 copies into the index.html files. Let's break this down by section. First, let's clean up the inprogress areas.
$ grep -R '"http://ksionda.me/blog\|"http://www.ksionda.me/blog' public/blog/inprogress/ | wc -l
0
All right, so nothing in my blog inprogress area is trying to point at anything in my blog area. Let's go ahead and findReplace all occurances of '"http://www.ksionda.me' and '"http://ksionda.me' to ''.
$ findReplace '"http://www.ksionda.me' '' public/blog/inprogress
$ findReplace '"http://ksionda.me' '' public/blog/inprogress
Oh, wait, that's wrong, should still have a '"' in there. This is why I committed before starting these changes.
$ git revert public/blog/inprogress
$ findReplace '"http://www.ksionda.me' '"' public/blog/inprogress
$ findReplace '"http://ksionda.me' '"' public/blog/inprogress
All right, absolute paths made relative in my blog inprogress area. Now, then, let's fix the blog area:
$ findReplace '"http://www.ksionda.me/blog/' '"' public/blog
$ findReplace '"http://ksionda.me/blog/' '"' public/blog
This makes each absolute link to a blog link from the blog area a basic relative link to that file instead.
$ findReplace '"http://www.ksionda.me' '"' public/blog
$ findReplace '"http://ksionda.me' '"' public/blog
This makes all other absolute links relative from the root of the server area (aka, from the public directory). This covers links to other parts of my site from the blog area.
There were lots of files changed with those last two commands.
Okay, where else do I reference ksionda.me explicitly?
$ grep -lR '"http://ksionda.me\|"http://www.ksionda.me' public/
public/diary/end_of_day_review_20150304.html
public/diary/inprogress/making_relative_links_150411.html
public/diary/end_of_day_log_20150306.html
public/diary/planning_20150305.html
public/diary/building_plan_20150307.html
public/diary/end_of_day_review_20150306.html
public/diary/end_of_day_review_20150223.html
public/diary/end_of_day_log_20150305.html
public/diary/building_planning_20150222.html
public/diary/planning_20150307.html
public/diary/end_of_day_log_20150223.html
public/diary/end_of_day_routine_20150304.html
public/diary/end_of_day_review_20150222.html
public/diary/implementing_pomodoro_with_my_blog.html
public/diary/blogging_brainstorming_20150223.html
public/diary/planning_20150306.html
public/diary/morning_plan_document_20150223.html
public/diary/log_20150222.html
public/diary/building_plan_20150306.html
public/diary/fiction_a_ramble_and_a_proposition.html
public/diary/end_of_day_routine_20150306.html
public/diary/end_of_day_review_20150303.html
public/diary/end_of_day_routine_20150305.html
public/diary/end_of_day_review_20150305.html
public/diary/building_pomodoro_plan_20150305.html
public/diary/review_20150307.html
public/diary/end_of_day_routine_20150307.html
public/diary/site_browsebar_modification_script_iterate.html
public/diary/planning_20150222.html
public/distracted/atwork.html
public/distracted/athome.html
Oh, look, this file gets flagged by that grep. That's only because I have the exact string it greps for... for obviouse reasons. The rest of the flagged files seem to all have the same cause of being flagged:
<link rel="stylesheet" href="http://www.ksionda.me/style.css">
Should be easily fixed by:
$ findReplace '"http://www.ksionda.me' '"' public/distracted public/diary/*.html
All right, I think I've properly fixed all the links! Hopefully I didn't break anything. Hooray for cleaning up my site! Woo!