Module: Crm::SiteMapsHelper
- Defined in:
- app/helpers/crm/site_maps_helper.rb
Overview
View helper: site maps.
Constant Summary collapse
- EXPECTED_SCHEMAS =
Expected schema types based on page category
{ 'post' => %w[BlogPosting], 'faqs' => %w[FAQPage], 'product' => %w[Product], 'product_line' => %w[Product], 'showcase' => %w[Article] }.freeze
Instance Method Summary collapse
-
#expected_schema_types(category) ⇒ Array<String>
Returns the schema types expected for a given page category.
-
#site_map_ai_score_badge_class(score) ⇒ String
Badge class for AI analysis overall_score (0–100) in index table Matches Crm::SeoDashboardComponent#score_badge_class.
-
#site_map_crawl_status(sm) ⇒ String
Compact display of last crawl time + content presence indicator.
-
#site_map_resource_icon(site_map) ⇒ String
Returns an icon class for the resource type.
-
#site_map_resource_name(site_map) ⇒ String
Returns a display name for the resource.
-
#site_map_resource_path(site_map) ⇒ String?
Returns the CRM URL path for a SiteMap's linked resource.
-
#site_map_resource_type_label(site_map) ⇒ String
Returns a human-readable label for the resource type Handles Article subtypes (blog_post -> Blog Post, faq -> FAQ, etc.).
-
#site_map_schema_badges(sm) ⇒ String
Schema types as small Bootstrap badges.
-
#site_map_schema_health(sm) ⇒ String
Health indicator icon based on expected schemas for the page category.
-
#site_map_seo_commands(site_map) ⇒ Array<String>
Builds the link array for render_combo_drop_down.
-
#suggested_keyword_target(site_map, keyword, search_volume: nil) ⇒ String
Intent-based suggestion (desired / undesired / ignore) for display and apply-to-selected.
-
#suggestion_badge_class(suggestion) ⇒ String
Bootstrap badge class for a suggestion intent.
-
#suggestion_label(suggestion) ⇒ String
Human-readable label for a suggestion intent.
-
#url_path_only(site_map_or_url) ⇒ String
Returns the path portion for display Now that SiteMap stores path directly, this is a simple accessor.
Instance Method Details
#expected_schema_types(category) ⇒ Array<String>
Returns the schema types expected for a given page category.
360 361 362 |
# File 'app/helpers/crm/site_maps_helper.rb', line 360 def expected_schema_types(category) EXPECTED_SCHEMAS[category] || [] end |
#site_map_ai_score_badge_class(score) ⇒ String
Badge class for AI analysis overall_score (0–100) in index table
Matches Crm::SeoDashboardComponent#score_badge_class
369 370 371 372 373 374 375 376 377 378 |
# File 'app/helpers/crm/site_maps_helper.rb', line 369 def site_map_ai_score_badge_class(score) return 'bg-secondary' unless score case score when 80..100 then 'bg-success' when 60..79 then 'bg-primary' when 40..59 then 'bg-warning text-dark' else 'bg-danger' end end |
#site_map_crawl_status(sm) ⇒ String
Compact display of last crawl time + content presence indicator
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'app/helpers/crm/site_maps_helper.rb', line 256 def site_map_crawl_status(sm) crawl_time = sm.try(:rendered_schema_at) || sm.last_status_datetime return content_tag(:span, 'never', class: 'text-body-secondary fst-italic') if crawl_time.nil? parts = [] parts << content_tag(:span, "#{time_ago_in_words(crawl_time)} ago", title: crawl_time.to_fs(:short), class: crawl_time < 7.days.ago ? 'text-warning' : 'text-body-secondary') # Content indicator if sm.extracted_content.present? parts << fa_icon('file-lines', family: :solid, class: 'fa-sm text-success ms-1', title: "Content extracted (#{sm.extracted_content.length} chars)") end safe_join(parts) end |
#site_map_resource_icon(site_map) ⇒ String
Returns an icon class for the resource type
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'app/helpers/crm/site_maps_helper.rb', line 151 def site_map_resource_icon(site_map) return 'fa-solid fa-file' if site_map.resource.blank? resource = site_map.resource resource_type = site_map.resource_type case resource_type when 'Article' case resource.class.name when 'Post' then 'fa-solid fa-pen-fancy' when 'ArticleFaq' then 'fa-solid fa-circle-question' when 'ArticleTechnical' then 'fa-solid fa-screwdriver-wrench' when 'ArticleTraining' then 'fa-solid fa-graduation-cap' when 'ArticleProcedure' then 'fa-solid fa-file-lines' else 'fa-solid fa-file-lines' end when 'DigitalAsset' if resource.is_a?(Image) 'fa-solid fa-image' elsif resource.is_a?(Video) 'fa-solid fa-video' else 'fa-solid fa-photo-film' end when 'Showcase' 'fa-solid fa-images' when 'FloorPlanDisplay' 'fa-solid fa-map' when 'Item' 'fa-solid fa-box' when 'ProductLine' 'fa-solid fa-boxes-stacked' when 'CatalogItem' 'fa-solid fa-tag' else 'fa-solid fa-file' end end |
#site_map_resource_name(site_map) ⇒ String
Returns a display name for the resource
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/helpers/crm/site_maps_helper.rb', line 91 def site_map_resource_name(site_map) return nil if site_map.resource.blank? resource = site_map.resource resource_type = site_map.resource_type case resource_type when 'Article' resource.subject.presence || "#{site_map_resource_type_label(site_map)} ##{resource.id}" when 'DigitalAsset' resource.title.presence || resource.name.presence || "#{site_map_resource_type_label(site_map)} ##{resource.id}" else resource.try(:name) || resource.try(:title) || resource.try(:subject) || "#{resource_type} ##{resource.id}" end end |
#site_map_resource_path(site_map) ⇒ String?
Returns the CRM URL path for a SiteMap's linked resource
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/helpers/crm/site_maps_helper.rb', line 61 def site_map_resource_path(site_map) return nil if site_map.resource.blank? resource = site_map.resource resource_type = site_map.resource_type case resource_type when 'Article' article_resource_path(resource) when 'DigitalAsset' digital_asset_resource_path(resource) when 'Showcase' showcase_path(resource) when 'FloorPlanDisplay' floor_plan_display_path(resource) when 'Item' item_path(resource) when 'ProductLine' product_line_path(resource) when 'CatalogItem' catalog_item_path(resource) end rescue StandardError nil end |
#site_map_resource_type_label(site_map) ⇒ String
Returns a human-readable label for the resource type
Handles Article subtypes (blog_post -> Blog Post, faq -> FAQ, etc.)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/helpers/crm/site_maps_helper.rb', line 112 def site_map_resource_type_label(site_map) return nil if site_map.resource.blank? resource = site_map.resource resource_type = site_map.resource_type case resource_type when 'Article' case resource.class.name when 'Post' then 'Blog Post' when 'ArticleFaq' then 'FAQ' when 'ArticleTechnical' then 'Technical Article' when 'ArticleTraining' then 'Training Article' when 'ArticleProcedure' then 'Procedure' else 'Article' end when 'DigitalAsset' if resource.is_a?(Image) 'Image' elsif resource.is_a?(Video) 'Video' else 'Digital Asset' end when 'ProductLine' 'Product Line' when 'FloorPlanDisplay' 'Floor Plan' when 'CatalogItem' 'Catalog Item' else resource_type.titleize end end |
#site_map_schema_badges(sm) ⇒ String
Schema types as small Bootstrap badges
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'app/helpers/crm/site_maps_helper.rb', line 279 def site_map_schema_badges(sm) types = sm.rendered_schema_types if types.blank? count_label = content_tag(:span, '0', class: 'text-body-secondary') return safe_join([content_tag(:span, "\u2014", class: 'text-body-secondary me-1'), count_label]) end # Short display names for common schema types short_names = { 'BlogPosting' => 'Blog', 'FAQPage' => 'FAQ', 'HowTo' => 'HowTo', 'Article' => 'Article', 'Product' => 'Product', 'BreadcrumbList' => 'Bread', 'Organization' => 'Org', 'LocalBusiness' => 'Biz', 'WebPage' => 'Page', 'CollectionPage' => 'Coll', 'OnlineStore' => 'Store', 'VideoObject' => 'Video', 'ImageObject' => 'Image' } badges = types.map do |type| label = short_names[type] || type.truncate(10) content_tag(:span, label, class: 'badge text-bg-info badge-sm me-1', title: type) end count = content_tag(:span, "(#{types.size})", class: 'text-body-secondary ms-1') safe_join(badges + [count]) end |
#site_map_schema_health(sm) ⇒ String
Health indicator icon based on expected schemas for the page category
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'app/helpers/crm/site_maps_helper.rb', line 317 def site_map_schema_health(sm) if sm.rendered_schema_at.nil? return fa_icon('minus', family: :solid, class: 'fa-sm text-body-secondary', title: 'Not yet crawled for schema') end types = sm.rendered_schema_types expected = expected_schema_types(sm.category) if expected.blank? # No specific expectation for this category — neutral if types.any? fa_icon('circle-check', family: :solid, class: 'fa-sm text-success', title: "#{types.size} schema type(s) found") else fa_icon('minus', family: :solid, class: 'fa-sm text-body-secondary', title: 'No schemas (none expected)') end else missing = expected - types if missing.empty? fa_icon('circle-check', family: :solid, class: 'fa-sm text-success', title: "All expected schemas present: #{expected.join(', ')}") else fa_icon('triangle-exclamation', family: :solid, class: 'fa-sm text-warning', title: "Missing expected: #{missing.join(', ')}") end end end |
#site_map_seo_commands(site_map) ⇒ Array<String>
Builds the link array for render_combo_drop_down.
Primary action: full SEO analysis. Dropdown: individual sync steps.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'app/helpers/crm/site_maps_helper.rb', line 199 def site_map_seo_commands(site_map) cmds = [] # Primary action (becomes the main button) cmds << link_to(analyze_site_map_path(site_map), data: { turbo_method: :post }) do fa_icon('wand-magic-sparkles', family: :solid, class: 'me-1') + ' Run Full Analysis' end # Individual sync steps (become dropdown items) cmds << link_to(analyze_only_site_map_path(site_map), data: { turbo_method: :post }) do fa_icon('brain', family: :solid, class: 'me-1') + ' Analysis Only' end cmds << link_to(analyze_premium_site_map_path(site_map), data: { turbo_method: :post }) do fa_icon('gem', family: :solid, class: 'me-1') + ' Premium Analysis (Opus)' end cmds << link_to(sync_visits_site_map_path(site_map), data: { turbo_method: :post }) do fa_icon('eye', family: :solid, class: 'me-1') + ' Sync Visits Only' end cmds << link_to(sync_gsc_site_map_path(site_map), data: { turbo_method: :post }) do fa_icon('google', family: :brands, class: 'me-1') + ' Sync GSC Only' end cmds << link_to(sync_ga4_site_map_path(site_map), data: { turbo_method: :post }) do fa_icon('chart-bar', family: :solid, class: 'me-1') + ' Sync GA4 Only' end cmds << link_to(sync_keywords_site_map_path(site_map), data: { turbo_method: :post }) do fa_icon('key', family: :solid, class: 'me-1') + ' Sync Keywords Only' end cmds << link_to(recrawl_site_map_path(site_map), data: { turbo_method: :post, turbo_confirm: 'Recrawl this page? This will fetch the latest content and schema.' }) do fa_icon('rotate', family: :solid, class: 'me-1') + ' Recrawl Page' end cmds end |
#suggested_keyword_target(site_map, keyword, search_volume: nil) ⇒ String
Intent-based suggestion (desired / undesired / ignore) for display and apply-to-selected.
11 12 13 |
# File 'app/helpers/crm/site_maps_helper.rb', line 11 def suggested_keyword_target(site_map, keyword, search_volume: nil) site_map.suggested_keyword_target_for(keyword, search_volume: search_volume) end |
#suggestion_badge_class(suggestion) ⇒ String
Bootstrap badge class for a suggestion intent.
19 20 21 22 23 24 25 26 |
# File 'app/helpers/crm/site_maps_helper.rb', line 19 def suggestion_badge_class(suggestion) case suggestion when 'desired' then 'bg-success' when 'undesired' then 'bg-warning text-dark' when 'ignore' then 'bg-secondary' else 'bg-light text-dark' end end |
#suggestion_label(suggestion) ⇒ String
Human-readable label for a suggestion intent.
32 33 34 35 36 37 38 39 |
# File 'app/helpers/crm/site_maps_helper.rb', line 32 def suggestion_label(suggestion) case suggestion when 'desired' then 'Desired' when 'undesired' then 'Not desired' when 'ignore' then 'Ignore' else '—' end end |
#url_path_only(site_map_or_url) ⇒ String
Returns the path portion for display
Now that SiteMap stores path directly, this is a simple accessor
46 47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/crm/site_maps_helper.rb', line 46 def url_path_only(site_map_or_url) case site_map_or_url when SiteMap site_map_or_url.path.presence || '/' when String SiteMap.extract_path_from_url(site_map_or_url) else '/' end end |