From 4b4634385e460749473d3c9c85264d9466b9c3ed Mon Sep 17 00:00:00 2001 From: Chris Buckley Date: Tue, 28 Apr 2026 22:18:46 +0000 Subject: [PATCH] Custom git metadata plugin to get branch name (fixes #559) --- _includes/footer.html | 17 ++++++++++++----- _plugins/git-metadata.rb | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 _plugins/git-metadata.rb diff --git a/_includes/footer.html b/_includes/footer.html index f087b8e8..f44916ff 100755 --- a/_includes/footer.html +++ b/_includes/footer.html @@ -1,14 +1,21 @@ -{%- capture edit_link -%}{% github_edit_link "source" %}{%- endcapture -%} -{%- if page.paginated and paginator.page > 1 -%} - {%- assign first_page = site.pages | where_exp: 'p','p.paginated == true' | sort: 'path' | first -%} - {%- assign edit_link = edit_link | replace: page.path, first_page.path -%} +{%- if site.git -%} + {%- comment %}If we have our git plugin, construct the source URL ourselves as we can be more sure of the branch{% endcomment -%} + {%- assign source_url = site.github.repository_url | append: '/blob/' | append: site.git.branch | append: '/' | append: page.path -%} +{%- else -%} + {%- capture source_url -%}{% github_edit_link %}{%- endcapture -%} + {%- assign source_url = source_url | replace_first: '/edit/','/blob/' -%} + + {%- if page.paginated and paginator.page > 1 -%} + {%- assign first_page = site.pages | where_exp: 'p','p.paginated == true' | sort: 'path' | first -%} + {%- assign source_url = source_url | replace: page.path, first_page.path -%} + {%- endif -%} {%- endif -%}