From c5018c2a29eac42697d12319342154add47cddcf Mon Sep 17 00:00:00 2001
From: Zach Latta
Date: Thu, 29 May 2025 12:38:57 -0400
Subject: [PATCH] SEO pass
---
app/controllers/sitemap_controller.rb | 7 ++
app/controllers/static_pages_controller.rb | 13 +++
app/views/layouts/application.html.erb | 122 +++++++++++++++++++--
app/views/shared/_nav.html.erb | 10 +-
app/views/sitemap/sitemap.xml.erb | 21 ++++
app/views/static_pages/index.html.erb | 33 ++++--
config/routes.rb | 3 +
public/robots.txt | 4 +
8 files changed, 191 insertions(+), 22 deletions(-)
create mode 100644 app/controllers/sitemap_controller.rb
create mode 100644 app/views/sitemap/sitemap.xml.erb
diff --git a/app/controllers/sitemap_controller.rb b/app/controllers/sitemap_controller.rb
new file mode 100644
index 0000000..981baac
--- /dev/null
+++ b/app/controllers/sitemap_controller.rb
@@ -0,0 +1,7 @@
+class SitemapController < ApplicationController
+ def sitemap
+ respond_to do |format|
+ format.xml { render layout: false }
+ end
+ end
+end
diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb
index f8d3f1b..77c6368 100644
--- a/app/controllers/static_pages_controller.rb
+++ b/app/controllers/static_pages_controller.rb
@@ -67,6 +67,9 @@ class StaticPagesController < ApplicationController
instance_variable_set("@#{key}", value)
end
else
+ # Set homepage SEO content for logged-out users only
+ set_homepage_seo_content
+
@usage_social_proof = Cache::UsageSocialProofJob.perform_now
@home_stats = Cache::HomeStatsJob.perform_now
@@ -204,6 +207,16 @@ class StaticPagesController < ApplicationController
redirect_to root_path, alert: "You must be logged in to view this page" unless current_user
end
+ def set_homepage_seo_content
+ @page_title = "Hackatime - Free Coding Time Tracker | Track Your Programming Time"
+ @meta_description = "Track your coding time easily with Hackatime. See how long you spend programming in different languages. Free alternative to WakaTime. Join thousands of high schoolers!"
+ @meta_keywords = "coding time tracker, programming stats, wakatime alternative, free time tracking, code statistics, high school programming, coding analytics"
+ @og_title = "Hackatime - Free Coding Time Tracker"
+ @og_description = "Track your coding time easily with Hackatime. See how long you spend programming. Free and better than WakaTime!"
+ @twitter_title = "Hackatime - Free Coding Time Tracker"
+ @twitter_description = "Track your coding time easily with Hackatime. See how long you spend programming. Free and better than WakaTime!"
+ end
+
def filterable_dashboard_data
filters = %i[project language operating_system editor category]
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 80a5f53..e7f4438 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -1,36 +1,138 @@
">
- <%= content_for(:title) || "Hackatime" %>
+ <%= @page_title || content_for(:title) || "Hackatime" %>
-
-
+
+
+
+
+
+
-
-
+
+
-
+
+
+
+
-
-
-
-
+
+
+
+
+
+
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= yield :head %>
+
+
+
+
+
+
+
+
+ <% if request.path == "/" %>
+
+ <% end %>
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
diff --git a/app/views/shared/_nav.html.erb b/app/views/shared/_nav.html.erb
index c8637c4..d559445 100644
--- a/app/views/shared/_nav.html.erb
+++ b/app/views/shared/_nav.html.erb
@@ -29,6 +29,11 @@
Leaderboards
<% end %>
+
+ <%= link_to docs_path, class: "nav-item #{current_page?(docs_path) || request.path.start_with?('/docs') ? 'active' : ''}" do %>
+ Docs
+ <% end %>
+
<% if current_user %>
<%= link_to my_projects_path, class: "nav-item #{current_page?(my_projects_path) ? 'active' : ''}" do %>
@@ -40,11 +45,6 @@
Settings
<% end %>
-
- <%= link_to docs_path, class: "nav-item #{current_page?(docs_path) || request.path.start_with?('/docs') ? 'active' : ''}" do %>
- Docs
- <% end %>
-
<%= link_to signout_path, class: "nav-item", data: { turbo_method: :delete } do %>
Logout
diff --git a/app/views/sitemap/sitemap.xml.erb b/app/views/sitemap/sitemap.xml.erb
new file mode 100644
index 0000000..6869b27
--- /dev/null
+++ b/app/views/sitemap/sitemap.xml.erb
@@ -0,0 +1,21 @@
+
+
+
+ https://hackatime.hackclub.com/
+ <%= Date.current.iso8601 %>
+ daily
+ 1.0
+
+
+ https://hackatime.hackclub.com/leaderboard
+ <%= Date.current.iso8601 %>
+ hourly
+ 0.8
+
+
+ https://hackatime.hackclub.com/docs
+ <%= Date.current.iso8601 %>
+ weekly
+ 0.7
+
+
diff --git a/app/views/static_pages/index.html.erb b/app/views/static_pages/index.html.erb
index a25fa5e..f710498 100644
--- a/app/views/static_pages/index.html.erb
+++ b/app/views/static_pages/index.html.erb
@@ -3,7 +3,11 @@
<%= @flavor_text %>
- Keep Track of Your Coding Time
+ <% if current_user %>
+ Keep Track of Your Coding Time
+ <% else %>
+ Free Coding Time Tracker - See How Much You Code
+ <% end %>
<%# link_to "🃏", wildcard_static_pages_path, class: "wildcard" %>