From ecac1e7e8c6b52e9d981ff149161a57557f154d7 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Fri, 24 May 2024 12:39:57 +0200 Subject: [PATCH 1/3] Enable track campaign of in-tutorial links --- _includes/event-table.html | 2 +- _layouts/tutorial_hands_on.html | 18 ++++++++++ _plugins/gtn.rb | 58 +++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/_includes/event-table.html b/_includes/event-table.html index 7cd5d773fa9ed7..6d2ba6e66ef52d 100644 --- a/_includes/event-table.html +++ b/_includes/event-table.html @@ -14,7 +14,7 @@ {{event | collapse_date_pretty }} - {{event.title}}{% if event.draft %} (draft, will be hidden) {% endif %} + {{event.title}}{% if event.draft %} (draft, will be hidden) {% endif %}
{{event.description}}
{{event.location | format_location_short }} diff --git a/_layouts/tutorial_hands_on.html b/_layouts/tutorial_hands_on.html index 1e9bd8a9bd9f80..801fde2c138ea1 100644 --- a/_layouts/tutorial_hands_on.html +++ b/_layouts/tutorial_hands_on.html @@ -519,6 +519,24 @@

{{locale['citing-tutorial'] | default: "Citing this Tutorial"}}

{% endfor %} + + + + {% assign upcoming_events = site | get_upcoming_events_for_this: new_material %} + {% assign upcoming_event_count = upcoming_events | size %} + {% if upcoming_event_count > 0 %} +
+
+ +
+ +

Want to learn more with a live instructor? Check out these upcoming events:

+ {% include _includes/event-table.html events=upcoming_events campaign="via-tutorial" %} +
+ {% endif %} diff --git a/_plugins/gtn.rb b/_plugins/gtn.rb index 78e3a4051547df..878dca25f6294d 100644 --- a/_plugins/gtn.rb +++ b/_plugins/gtn.rb @@ -646,6 +646,51 @@ def get_topic(page) page['path'].split('/')[1] end + ## + # Get the list of 'upcoming' events (i.e. reg deadline or start is 30 days away.) + # Params: + # +site+:: The site object + # Returns: + # +Array+:: List of events + # + # Example: + # {{ site | get_upcoming_events }} + def get_upcoming_events(site) + cache.getset('upcoming-events') do + upcoming_events = site.pages + .select{|p| p.data['layout'] == 'event' || p.data['layout'] == 'event-external' } + .reject{|p| p.data['program'].nil? } # Only those with programs + .select{|p| p.data['event_upcoming'] == true } # Only those coming soon + .map{|p| + materials = p.data['program'] + .map{|section| section['tutorials']} + .flatten + .reject{|x| x.nil?} # Remove nil entries + .reject{|x| x.fetch('type', nil) == 'custom'} # Remove custom entries + .map{|x| "#{x['topic']}/#{x['name']}"} # Just the material IDs. + .sort.uniq + [p, materials] + } + end + end + + + ## + # Get the list of 'upcoming' events that include this material's ID + # Params: + # +site+:: The site object + # +material+:: The 'material' to get the topic of, it will inspect page.id (use new_material) + # Returns: + # +Array+:: List of events + # + # Example: + # {{ site | get_upcoming_events }} + def get_upcoming_events_for_this(site, material) + get_upcoming_events(site) + .select{|p, materials| materials.include? material['id']} + .map{|p, materials| p} + end + def shuffle(array) array.shuffle end @@ -877,6 +922,19 @@ def group_icons(icons) else (page.data['date_end'] - page.data['date_start']).to_i + 1 end + + # reg deadline + if page.data.key?('registration') && page.data['registration'].key?('deadline') + deadline = page.data['registration']['deadline'] + else + deadline = page.data['date_start'] + end + + # If it's an 'upcoming event' + if Date.today < deadline - 30 + page.data['event_upcoming'] = true + end + end end From c86f3604fedf212bb9756561c083922560169e90 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Fri, 24 May 2024 12:40:05 +0200 Subject: [PATCH 2/3] fix date math --- _plugins/gtn.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_plugins/gtn.rb b/_plugins/gtn.rb index 878dca25f6294d..48b3c892ea1325 100644 --- a/_plugins/gtn.rb +++ b/_plugins/gtn.rb @@ -931,7 +931,7 @@ def group_icons(icons) end # If it's an 'upcoming event' - if Date.today < deadline - 30 + if deadline - 30 <= Date.today && Date.today <= deadline page.data['event_upcoming'] = true end From 83f0b2bf70f7ce5e86f72d495b8ae41a5cae3f65 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Fri, 24 May 2024 12:40:12 +0200 Subject: [PATCH 3/3] better typography --- _plugins/util.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/_plugins/util.rb b/_plugins/util.rb index 42c699c5438c96..4878c446cba1a7 100644 --- a/_plugins/util.rb +++ b/_plugins/util.rb @@ -12,17 +12,18 @@ def collapse_event_date_pretty(event) event['date_end'] end # want dates like "Mar 22-25, 2024" or "Mar 22-May 1, 2024" + dash = " – " # thin space, en dash, thin space if s.year == e.year if s.month == e.month if s.day == e.day "#{s.strftime('%B')} #{s.day}, #{s.year}" else - "#{s.strftime('%B')} #{s.day}-#{e.day}, #{s.year}" + "#{s.strftime('%B')} #{s.day}#{dash}#{e.day}, #{s.year}" end else - "#{s.strftime('%B')} #{s.day}-#{e.strftime('%B')} #{e.day}, #{s.year}" + "#{s.strftime('%B')} #{s.day}#{dash}#{e.strftime('%B')} #{e.day}, #{s.year}" end else - "#{s.strftime('%B')} #{s.day}, #{s.year}-#{e.strftime('%B')} #{e.day}, #{e.year}" + "#{s.strftime('%B')} #{s.day}, #{s.year}#{dash}#{e.strftime('%B')} #{e.day}, #{e.year}" end end