Make edit links GitHub aware (#5038)

* Make edit links GitHub aware

* Fix repo url

* don't mutate existing string

* Move comment

* Fix url
This commit is contained in:
Paulus Schoutsen 2018-03-28 00:18:38 -07:00 committed by Fabian Affolter
parent 88c8cc2ff1
commit 9cc2bce761
2 changed files with 18 additions and 1 deletions

View File

@ -0,0 +1,17 @@
module Jekyll
class EnvironmentVariablesGenerator < Generator
def generate(site)
# https://www.netlify.com/docs/continuous-deployment/#build-environment-variables
repo_url = ENV['REPOSITORY_URL'] || 'https://github.com/home-assistant/home-assistant.github.io'
# Rewrite urls if repo url is the ssh format.
if repo_url.start_with? 'git@github.com:'
repo_url = repo_url.sub 'git@github.com:', 'https://github.com/'
end
# These values will be available as {{ site.NLY_REPOSITORY_URL }}
site.config['NLY_REPOSITORY_URL'] = repo_url
site.config['NLY_HEAD'] = ENV['HEAD'] || 'current'
end
end
end

View File

@ -1,4 +1,4 @@
{% assign url_parts = page.url | split: '/' %}
{% if page.hide_github_edit != true %}
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/{{ page.path }}'>Edit this page on GitHub</a></div>
<div class='edit-github'><a href='{{ site.NLY_REPOSITORY_URL }}/tree/{{ site.NLY_HEAD }}/source/{{ page.path }}'>Edit this page on GitHub</a></div>
{% endif %}