Skip to content

Commit 3208882

Browse files
committed
support external pages in navbar links
1 parent 81a23e9 commit 3208882

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

_includes/nav.html

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,26 @@
1212

1313
<div class="collapse navbar-collapse" id="main-navbar">
1414
<ul class="nav navbar-nav navbar-right">
15-
{% for link in site.navbar-links %}
15+
{% for link in site.navbar-links %}
16+
{% capture before %}{{ link[1] | split: "://" | first }}{% endcapture %}
17+
{% capture after %}{{ link[1] | split: "://" | last }}{% endcapture %}
1618
<li>
17-
<a href="{{ site.baseurl }}/{{ link[1] }}">{{ link[0] }}</a>
18-
</li>
19-
{% endfor %}
19+
{% assign internal = true %}
20+
{% if before != after %}
21+
{% if before == "http" or before == "https" %}
22+
{% assign internal = false %}
23+
{% endif %}
24+
{% endif %}
25+
26+
{% if internal %}
27+
{% capture linkurl %}{{ site.baseurl }}/{{ link[1] }}{% endcapture %}
28+
{% else %}
29+
{% capture linkurl %}{{ link[1] }}{% endcapture %}
30+
{% endif %}
31+
32+
<a href="{{ linkurl }}">{{ link[0] }}</a>
33+
</li>
34+
{% endfor %}
2035
</ul>
2136
</div>
2237

@@ -31,4 +46,4 @@
3146
{% endif %}
3247

3348
</div>
34-
</nav>
49+
</nav>

0 commit comments

Comments
 (0)