Skip to content

Commit

Permalink
Link to last commit on GitHub which modified a page
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Nov 2, 2023
1 parent 4fd0edb commit f529728
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/components/page/authors_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<% if last_commit_date %>
<div class="flex mt-24 mb-3 justify-between items-center content-center gap-3 border-t pt-6 border-gray-600">
<div>
<%= link_to helpers.github_commit_url(last_commit), target: :_blank do %>
<% page_authors.each_with_index do |(name, email), index| %>
<%= image_tag "https://avatars.githubusercontent.com/u/e?email=#{email}&s=128", class: "relative z-#{index * 10} inline-block h-6 w-6 rounded-full ring-1 ring-white", data: { controller: "tippy", tippy_content: name } %>
<% end %>

<span class="text-gray-300 ml-3">
Last modified: <%= time_ago_in_words(last_commit_date) %> ago
</span>
</div>
<% end %>

<%= link_to helpers.github_edit_file_url(@paths.first), class: "text-gray-300 hover:text-white flex" do %>
<svg class="h-6 w-6" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512">
Expand Down
6 changes: 5 additions & 1 deletion app/components/page/authors_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def page_authors
[]
end

def last_commit
commits.last
end

def last_commit_date
commits.last&.author_date
last_commit.try(:author_date)
end
end
15 changes: 12 additions & 3 deletions app/helpers/github_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# frozen_string_literal: true

module GitHubHelper
def github_edit_file_url(path)
github_repo_url = "https://github.com/marcoroth/hotwire.io"
github_default_branch = "main"
def github_repo_url
"https://github.com/marcoroth/hotwire.io"
end

def github_default_branch
"main"
end

def github_edit_file_url(path)
"#{github_repo_url}/edit/#{github_default_branch}/#{path}"
end

def github_commit_url(commit)
"#{github_repo_url}/commit/#{commit.sha}"
end
end

0 comments on commit f529728

Please sign in to comment.