From 29d8644db160f48f4f6f41cd9c337315413c8660 Mon Sep 17 00:00:00 2001 From: Erik Strand <erik.strand@cba.mit.edu> Date: Wed, 13 Feb 2019 19:04:20 -0500 Subject: [PATCH] Use relative URLs --- _includes/navigation.html | 2 +- _layouts/default.html | 2 +- _plugins/real_relative_url.rb | 17 +++++++++++++++++ _sass/main.scss | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 _plugins/real_relative_url.rb diff --git a/_includes/navigation.html b/_includes/navigation.html index ab853aa..2e0739d 100644 --- a/_includes/navigation.html +++ b/_includes/navigation.html @@ -1,5 +1,5 @@ <nav> {% for item in site.data.navigation %} - <a href="{{ item.link }}" {% if page.url == item.link %}class="current"{% endif %}>{{ item.name }}</a> + <a href="{{ item.link | real_relative_url }}" {% if page.url == item.link %}class="current"{% endif %}>{{ item.name }}</a> {% endfor %} </nav> diff --git a/_layouts/default.html b/_layouts/default.html index ceef12e..2b0a996 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -3,7 +3,7 @@ <head> <meta charset="utf-8"> <title>{{ page.title }}</title> - <link rel="stylesheet" href="/assets/css/styles.css"> + <link rel="stylesheet" href="{{ "/assets/css/styles.css" | real_relative_url }}"> {% include mathjax.html %} </head> <body> diff --git a/_plugins/real_relative_url.rb b/_plugins/real_relative_url.rb new file mode 100644 index 0000000..37ceb8c --- /dev/null +++ b/_plugins/real_relative_url.rb @@ -0,0 +1,17 @@ +require 'pathname' + +# Jekyll's built-in "relative_url" filter does not generate relative URLs, it generates URLs that +# don't contain the domain. This plugin was posted to a GitHub issue in which @aioobe asks about +# making real relative URLs: https://github.com/jekyll/jekyll/issues/6360. + +module Jekyll + module RealRelativeUrl + def real_relative_url(url) + pageUrl = @context.registers[:page]["url"] + pageDir = Pathname(pageUrl).parent + Pathname(url).relative_path_from(pageDir).to_s + end + end +end + +Liquid::Template.register_filter(Jekyll::RealRelativeUrl) diff --git a/_sass/main.scss b/_sass/main.scss index bc25e9e..9ecbc41 100644 --- a/_sass/main.scss +++ b/_sass/main.scss @@ -1,3 +1,3 @@ .current { - color: green; + font-weight: bold; } -- GitLab