Skip to content

Commit 9d429fa

Browse files
abelcheungdaattali
authored andcommitted
Abs link patch (daattali#506)
* Fix absolute URL generation url and baseurl config for this theme deviates from jekyll standard, and that results in double inclusion of project path if this theme is used as project page. Switching to Jekyll accepted url usage so that absolute_url filter works. * Alternate links need to be aboslute * mention url and baseurl only need to be modified in local dev * Update readme on new url/baseurl setting changes
1 parent 7061f6b commit 9d429fa

File tree

10 files changed

+52
-42
lines changed

10 files changed

+52
-42
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,13 @@ If you're not sure what the difference is, you can probably safely ignore this s
176176

177177
If you want to use this theme to host a website that will be available at `https://YOURUSERNAME.github.io`, then you do not need to read this section. That is called a User Page, you can only have one User Page in your GitHub account, and it is what you get by default when forking this project.
178178

179-
If you want to use this theme to create a website for a particular repository, it will be available at `https://YOURUSERNAME.github.io/REPONAME`, and that is called a [Project Page](https://help.github.com/articles/user-organization-and-project-pages/). You can have a Project Page for each repository you have on GitHub. There are two important things to note when creating a project page:
179+
If you want to use this theme to create a website for a particular repository, it will be available at `https://YOURUSERNAME.github.io/REPONAME`, and that is called a [Project Page](https://help.github.com/articles/user-organization-and-project-pages/). You can have a Project Page for each repository you have on GitHub.
180180

181-
1. In the configuration file (`_config.yml`), you should set `baseurl` to be `/projectname` instead of `""`.
182-
2. Project Pages are served from a branch named `gh-pages`, and you should be generating all the website content on that branch. When you fork Beautiful Jekyll, you'll already have a `gh-pages` branch but you should delete it and generate it again from the `master` branch. The reason is that the `gh-pages` branch in its current form does not have the updated code of Beautiful Jekyll, so you need to create that branch from the `master` branch (which is where all my new features and work go into).
181+
There are two important point to note, assuming your project website will be served under `gh-pages` branch (check [Github Page official documentation](https://help.github.com/en/articles/configuring-a-publishing-source-for-github-pages) for usable source):
182+
183+
1. When copying files from this repository, **only copy from `master` branch** of this theme, which is where all my new features and work go into. After copying stuff to `gh-pages` branch under your project...
184+
185+
2. Adjust all configurations and templates according to your taste, but in particular, there is no need to set `url` and `baseurl` inside `_config.yml`. Github will fill in the variables for you. Just push the changes and enjoy!
183186

184187
## Showcased users (success stories!)
185188

@@ -280,6 +283,17 @@ The default style of Beautiful Jekyll is to feature the blog feed on the front p
280283

281284
Unfortunately, this is a no-answer! There isn't a one-size-fits-all solution to this, because every person will view your site on a different browser with different dimensions. Some browsers will have very wide aspect ratio, some will be narrower, some will be vertical (such as phones), different phones have different screens, etc. The image will always be centered, so the only tip I can give is that you should make sure the important part of the image is in the middle so that it'll always show. Other than that, every browser will show a different clipping of the image.
282285

286+
#### After recent update some links in my project page appear to be broken!
287+
288+
Since late June 2019, some URL related setting are adjusted to be in line with how Jekyll uses them officially. Project page absolute links might appear to be broken if you haven't propagated all necessary changes to your local templates, or you have created additional templates making use of old settings. If links contain duplicated project path component, this is most likely the cause. In summary:
289+
290+
|   | Old behavior | New behavior |
291+
| --- | --- | --- |
292+
| `url` setting | `https://user.github.io/project` | (unset, GitHub auto detect) |
293+
| `baseurl` setting | `/project` | (unset, GitHub auto detect) |
294+
| Absolute link construction | `{{ site.url }}/your/path` | `{{ '/your/path' \| absolute_url }}` |
295+
| Relative link construction | `{{ site.baseurl }}/your/path` | `{{ '/your/path' \| relative_url }}` |
296+
283297
## Credits
284298
285299
This template was not made entirely from scratch. I would like to give special thanks to:

_config.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
# --- General options --- #
22

3-
# url is the full website URL
4-
# baseurl is the website's URL without the hostname
5-
6-
# If you are building a simple GitHub user page (https://username.github.io) then use these settings:
7-
url: "https://username.github.io"
8-
baseurl: ""
9-
10-
# If you are building a GitHub project page then use these settings:
11-
#url: "http://username.github.io/projectname"
12-
#baseurl: "/projectname"
13-
14-
# Of course don't forget to change the username and projectname to YOUR username and project
15-
163
# Name of website
174
title: My website
185

196
# Short description of your site
20-
description: A virtual proof that name is awesome!
7+
description: A virtual proof that I'm awesome
8+
9+
# --- Local development options ---
10+
# If your website is hosted locally rather than on GitHub, then you need to uncomment the next two parameters to set the url and baseurl
11+
# *** If you're not sure what this mean, then leave this section as it is. Only modify the url and baseurl if you know what you're doing!***
12+
13+
# url is the the website domain URL without a trailing slash
14+
#url: "https://example.com"
15+
16+
# baseurl should be an empty string
17+
#baseurl: ""
2118

2219
# --- Navigation bar options --- #
2320

@@ -27,7 +24,6 @@ navbar-links:
2724
Resources:
2825
- Beautiful Jekyll: "http://deanattali.com/beautiful-jekyll/"
2926
- Learn markdown: "http://www.markdowntutorial.com/"
30-
- GitHub Pages: "https://pages.github.com/"
3127
Author's home: "http://deanattali.com"
3228

3329
# Image to show in the navigation bar - image must be a square (width = height)

_includes/fb-comment.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.12&appId={{ site.fb_comment_id }}&autoLogAppEvents=1';
99
fjs.parentNode.insertBefore(js, fjs);
1010
}(document, 'script', 'facebook-jssdk'));</script>
11-
<div class="fb-comments" data-href="{{ site.url }}{{ page.url }}" data-width="100%" data-numposts="5"></div>
11+
<div class="fb-comments" data-href="{{ page.url | absolute_url }}" data-width="100%" data-numposts="5"></div>
1212
<noscript>Please enable JavaScript to view the comments powered by Facebook.</noscript>
1313
</div>
1414
{%- endif -%}

_includes/footer-minimal.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
{% else %}
88
{{ site.time | date: '%Y' }}
99
{% endif %}
10-
10+
1111
{% if site.url-pretty %}
1212
&nbsp;&nbsp;&bull;&nbsp;&nbsp;
13-
<a href="{{ site.url }}">{{ site.url-pretty }}</a>
14-
{% endif %}
13+
<a href="{{ '' | absolute_url }}">{{ site.url-pretty }}</a>
14+
{% endif %}
1515
</div>
1616
</footer>

_includes/footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
{% if site.url-pretty %}
3232
&nbsp;&bull;&nbsp;
33-
<a href="{{ site.url }}">{{ site.url-pretty }}</a>
33+
<a href="{{ '' | absolute_url }}">{{ site.url-pretty }}</a>
3434
{% endif %}
3535

3636
{% if site.matomo %}

_includes/head.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<meta name="description" content="{{ page.subtitle }}">
1212
{% endif %}
1313

14-
<link rel="alternate" type="application/rss+xml" title="{{ site.title }} {{ site.title-separator }} {{ site.description }}" href="{{ '/feed.xml' | relative_url }}" />
14+
<link rel="alternate" type="application/rss+xml" title="{{ site.title }} {{ site.title-separator }} {{ site.description }}" href="{{ '/feed.xml' | absolute_url }}" />
1515

1616
{% include gtag.html %}
1717
{% include gtm_head.html %}
@@ -78,17 +78,17 @@
7878
<meta property="og:type" content="website" />
7979

8080
{% if page.id %}
81-
<meta property="og:url" content="{{ site.url }}{{ page.url }}" />
82-
<link rel="canonical" href="{{ site.url }}{{ page.url }}" />
81+
<meta property="og:url" content="{{ page.url | absolute_url }}" />
82+
<link rel="canonical" href="{{ page.url | absolute_url }}" />
8383
{% else %}
84-
<meta property="og:url" content="{{ site.url }}{{ page.url | remove: '/index.html' | remove: '.html' }}" />
85-
<link rel="canonical" href="{{ site.url }}{{ page.url | remove: '/index.html' | remove: '.html' }}" />
84+
<meta property="og:url" content="{{ page.url | absolute_url | strip_index }}" />
85+
<link rel="canonical" href="{{ page.url | absolute_url | strip_index }}" />
8686
{% endif %}
8787

8888
{% if page.share-img %}
8989
<meta property="og:image" content="{{ page.share-img }}" />
9090
{% elsif site.avatar %}
91-
<meta property="og:image" content="{{ site.url }}{{ site.avatar }}" />
91+
<meta property="og:image" content="{{ site.avatar | absolute_url }}" />
9292
{% endif %}
9393

9494

@@ -116,7 +116,7 @@
116116
{% if page.share-img %}
117117
<meta name="twitter:image" content="{{ page.share-img }}" />
118118
{% elsif site.avatar %}
119-
<meta name="twitter:image" content="{{ site.url }}{{ site.avatar }}" />
119+
<meta name="twitter:image" content="{{ site.avatar | absolute_url }}" />
120120
{% endif %}
121121

122122
{% if site.matomo %}

_includes/nav.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<span class="icon-bar"></span>
99
</button>
1010
{% if site.title-img %}
11-
<a class="navbar-brand navbar-brand-logo" href="{{ site.url }}"><img src="{{ site.title-img }}"/></a>
11+
<a class="navbar-brand navbar-brand-logo" href="{{ '' | absolute_url }}"><img src="{{ site.title-img }}"/></a>
1212
{% else %}
13-
<a class="navbar-brand" href="{{ site.url }}">{{ site.title }}</a>
13+
<a class="navbar-brand" href="{{ '' | absolute_url }}">{{ site.title }}</a>
1414
{% endif %}
1515
</div>
1616

@@ -40,15 +40,15 @@
4040
{% if page.image and (layout.show-avatar or page.show-avatar) %}
4141
<div class="avatar-container">
4242
<div class="avatar-img-border">
43-
<a href="{{ site.url }}">
43+
<a href="{{ '' | absolute_url }}">
4444
<img class="avatar-img" src="{{ page.image | relative_url }}" />
4545
</a>
4646
</div>
4747
</div>
4848
{% elsif site.avatar and (layout.show-avatar or page.show-avatar) %}
4949
<div class="avatar-container">
5050
<div class="avatar-img-border">
51-
<a href="{{ site.url }}">
51+
<a href="{{ '' | absolute_url }}">
5252
<img class="avatar-img" src="{{ site.avatar | relative_url }}" />
5353
</a>
5454
</div>

_includes/social-share.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
{% if site.share-links-active.twitter %}
1414
<!--- Share on Twitter -->
15-
<a href="https://twitter.com/intent/tweet?text={{ page.title | url_encode }}+{{ site.url }}{{ page.url }}"
15+
<a href="https://twitter.com/intent/tweet?text={{ page.title | url_encode }}&url={{ page.url | absolute_url | url_encode }}"
1616
class="btn btn-social-icon btn-twitter" title="Share on Twitter">
1717
<span class="fa fa-fw fa-twitter" aria-hidden="true"></span>
1818
<span class="sr-only">Twitter</span>
@@ -21,7 +21,7 @@
2121

2222
{% if site.share-links-active.facebook %}
2323
<!--- Share on Facebook -->
24-
<a href="https://www.facebook.com/sharer/sharer.php?u={{ site.url }}{{ page.url }}"
24+
<a href="https://www.facebook.com/sharer/sharer.php?u={{ page.url | absolute_url | url_encode }}"
2525
class="btn btn-social-icon btn-facebook" title="Share on Facebook">
2626
<span class="fa fa-fw fa-facebook" aria-hidden="true"></span>
2727
<span class="sr-only">Facebook</span>
@@ -30,7 +30,7 @@
3030

3131
{% if site.share-links-active.linkedin %}
3232
<!--- Share on LinkedIn -->
33-
<a href="https://www.linkedin.com/shareArticle?mini=true&url={{ site.url }}{{ page.url }}"
33+
<a href="https://www.linkedin.com/shareArticle?mini=true&url={{ page.url | absolute_url | url_encode }}"
3434
class="btn btn-social-icon btn-linkedin" title="Share on LinkedIn">
3535
<span class="fa fa-fw fa-linkedin" aria-hidden="true"></span>
3636
<span class="sr-only">LinkedIn</span>

feed.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ layout: null
66
<channel>
77
<title>{{ site.title | xml_escape }}</title>
88
<description>{{ site.description | xml_escape }}</description>
9-
<link>{{ site.url }}</link>
10-
<atom:link href="{{ site.url }}/feed.xml" rel="self" type="application/rss+xml" />
9+
<link>{{ '' | absolute_url }}</link>
10+
<atom:link href="{{ 'feed.xml' | absolute_url }}" rel="self" type="application/rss+xml" />
1111
{% for post in site.posts limit:20 %}
1212
<item>
1313
<title>{{ post.title | xml_escape }}</title>
@@ -16,8 +16,8 @@ layout: null
1616
{{ post.content | strip_html | xml_escape | truncatewords: 50 }}
1717
</description>
1818
<pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
19-
<link>{{ site.url }}{{ post.url }}</link>
20-
<guid isPermaLink="true">{{ site.url }}{{ post.url }}</guid>
19+
<link>{{ post.url | absolute_url }}</link>
20+
<guid isPermaLink="true">{{ post.url | absolute_url }}</guid>
2121
</item>
2222
{% endfor %}
2323
</channel>

tags.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h2 id="{{- tag -}}" class="linked-section">
2323
<div class="post-list">
2424
{%- for post in site.tags[tag] -%}
2525
<div class="tag-entry">
26-
<a href="{{- site.url -}}{{- post.url -}}">{{- post.title -}}</a>
26+
<a href="{{ post.url | relative_url }}">{{- post.title -}}</a>
2727
<div class="entry-date">
2828
<time datetime="{{- post.date | date_to_xmlschema -}}">{{- post.date | date: "%B %d, %Y" -}}</time>
2929
</div>

0 commit comments

Comments
 (0)