1
+# frozen_string_literal: true
2
+
3
+# On-page SEO helpers. The layout renders `shared/_seo`, which reads these to
4
+# emit the title, description, canonical, Open Graph, Twitter Card, and JSON-LD
5
+# tags. Pages override the defaults with `content_for`:
6
+#
7
+# <% content_for :title, "Models" %>
8
+# <% content_for :description, "Browse open-weights models on siGit." %>
9
+# <% content_for :og_image, image_or_absolute_url %> # optional
10
+# <% content_for :robots, "noindex, follow" %> # optional
11
+#
12
+# Everything degrades to a sensible sitewide default, so a page that sets
13
+# nothing still gets valid, non-empty tags.
14
+module SeoHelper
15
+ SITE_NAME = "siGit"
16
+ TITLE_SUFFIX = "siGit Code & Deploy"
17
+
18
+ DEFAULT_DESCRIPTION =
19
+ "siGit is Git hosting for the AI era. Version your repositories, publish " \
20
+ "open-weights models with full model cards and LFS-backed files, and hand " \
21
+ "the keys to your AI coding agent over the Agent Client Protocol."
22
+
23
+ # Square PWA icon used as the Open Graph / Twitter fallback image. A dedicated
24
+ # 1200×630 share image would render larger in social previews; drop one at
25
+ # /og-cover.png and point DEFAULT_OG_IMAGE_PATH at it to upgrade.
26
+ DEFAULT_OG_IMAGE_PATH = "/favicon/web-app-manifest-512x512.png"
27
+
28
+ # "<page> · siGit Code & Deploy", or just the suffix on the bare root.
29
+ def page_full_title
30
+ page = content_for(:title)
31
+ page.present? ? "#{page} · #{TITLE_SUFFIX}" : TITLE_SUFFIX
32
+ end
33
+
34
+ def meta_description
35
+ strip_tags(content_for(:description).presence || DEFAULT_DESCRIPTION).squish
36
+ end
37
+
38
+ # Canonical URL without query string or fragment, so tracking params and
39
+ # pagination don't fork duplicate URLs in the index.
40
+ def canonical_url
41
+ "#{request.base_url}#{request.path}"
42
+ end
43
+
44
+ def og_image_url
45
+ custom = content_for(:og_image)
46
+ return custom if custom.present? && custom.start_with?("http")
47
+
48
+ "#{request.base_url}#{custom.presence || DEFAULT_OG_IMAGE_PATH}"
49
+ end
50
+
51
+ def meta_robots
52
+ content_for(:robots).presence || "index, follow"
53
+ end
54
+
55
+ def og_type
56
+ content_for(:og_type).presence || "website"
57
+ end
58
+
59
+ # Organization + WebSite, emitted on every page. Establishes the site entity
60
+ # for knowledge-panel / sitelinks eligibility.
61
+ def organization_json_ld
62
+ {
63
+ "@context" => "https://schema.org",
64
+ "@graph" => [
65
+ {
66
+ "@type" => "Organization",
67
+ "@id" => "#{request.base_url}/#organization",
68
+ "name" => SITE_NAME,
69
+ "url" => request.base_url,
70
+ "logo" => "#{request.base_url}#{DEFAULT_OG_IMAGE_PATH}",
71
+ "description" => DEFAULT_DESCRIPTION
72
+ },
73
+ {
74
+ "@type" => "WebSite",
75
+ "@id" => "#{request.base_url}/#website",
76
+ "name" => SITE_NAME,
77
+ "url" => request.base_url,
78
+ "publisher" => { "@id" => "#{request.base_url}/#organization" }
79
+ }
80
+ ]
81
+ }
82
+ end
83
+end