-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.rb
1205 lines (1010 loc) · 40.6 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
146
147
148
149
150
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
189
190
191
192
193
194
195
196
197
198
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
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
312
313
314
315
316
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# frozen_string_literal: true
require "dotenv"
require "lib/path_helpers"
require "lib/image_helpers"
require "lib/text_helpers"
Dotenv.load
page "/*.xml", layout: false
page "/*.json", layout: false
page "/*.txt", layout: false
ENV["TZ"] = "Europe/Rome"
set :url_root, ENV.fetch("BASE_URL")
set :markdown_engine, :redcarpet
ignore "/templates/*"
LOCALES = %w[it en].freeze
activate :i18n, langs: LOCALES, mount_at_root: LOCALES[0].intern
activate :asset_hash
activate :directory_indexes
activate :pagination
RETRY_CLASSES = [
Faraday::ClientError,
Faraday::ConnectionFailed,
Net::OpenTimeout,
NoMethodError,
SocketError
].freeze
def retry_on_error(limit: 5)
tries ||= 1
yield
rescue *RETRY_CLASSES => e
if tries < limit
warn "#### Error: #{e}, tried #{tries} times"
tries += 1
retry
end
raise e
end
DATO_ENV = ENV.has_key?("DATO_ENV") ? ENV.fetch("DATO_ENV") : nil
retry_on_error(limit: 10) do
activate :dato,
token: ENV.fetch("DATO_API_TOKEN"),
live_reload: true,
preview: ENV.fetch("BUILD_ENV") != "production",
environment: DATO_ENV
end
webpack_command =
if build?
"yarn run build"
else
"yarn run dev"
end
activate :external_pipeline,
name: :webpack,
command: webpack_command,
source: ".tmp/dist",
latency: 1
configure :build do
activate :minify_html do |html|
html.remove_input_attributes = false
end
activate :search_engine_sitemap,
default_priority: 0.5,
default_change_frequency: "weekly"
end
configure :development do
# activate :livereload
activate :search_engine_sitemap,
default_priority: 0.5,
default_change_frequency: "weekly"
end
# Item selection functions
module PresentationHelper
def self.published_announcements(announcements)
announcements.sort_by(&:date_shown).reverse
end
def self.published_articles(articles)
articles.select(&:slug).sort_by(&:date_shown).reverse
end
def self.published_pages(pages)
pages.select(&:slug).sort_by(&:position)
end
def self.published_work_positions(work_positions)
open, others = work_positions.partition { |p| p.announcement_status.name == "APERTO"}
open_sorted = open.select(&:slug).sort_by(&:date_shown).reverse
others_sorted = others.select(&:slug).sort_by(&:date_shown).reverse
open_sorted + others_sorted
end
def self.published_children_pages(page)
page.children.select(&:slug).sort_by(&:position)
end
def self.published_focus_pages(focus_pages)
focus_pages.sort_by(&:position)
end
def self.published_interviews(interviews)
interviews.select(&:slug).sort_by(&:date_shown).reverse
end
def self.published_participations(participations)
participations.select(&:slug).sort_by(&:date_shown).reverse
end
def self.published_press_releases(press_releases)
press_releases.select(&:slug).sort_by(&:date_shown).reverse
end
def self.published_projects_categories(projects_categories)
projects_categories.sort_by(&:position)
end
def self.published_projects(projects)
projects.sort_by(&:position).reject do |project|
!project.state_block.empty? && project.state_block.first.completed == true
end
end
def self.published_completed_projects(projects)
(projects.select do |project|
!project.state_block.empty? && project.state_block.first.completed == true
end).sort_by { |project| project.state_block.first.date_completed}.reverse
end
def self.published_schedule_events(schedule_events)
schedule_events.sort_by(&:date_shown)
end
def self.published_tags(tags)
tags.sort_by(&:name)
end
def self.published_redirects(redirects)
redirects.select(&:old_url)
end
def self.published_videos(videos)
videos.select(&:slug).sort_by(&:date_shown).reverse
end
def self.path_without_domain(url)
url.gsub("https://innovazione.gov.it", "")
end
end
helpers do
include PathHelpers
include ImageHelpers
include TextHelpers
def visible_announcements
PresentationHelper.published_announcements(dato.announcements)
end
def visible_articles
PresentationHelper.published_articles(dato.articles)
end
def visible_focus_pages
PresentationHelper.published_focus_pages(dato.focus_pages)
end
def visible_interviews
PresentationHelper.published_interviews(dato.interviews)
end
def visible_participations
PresentationHelper.published_participations(dato.participations)
end
def visible_press_releases
PresentationHelper.published_press_releases(dato.press_releases)
end
def visible_projects_categories
PresentationHelper.published_projects_categories(dato.projects_categories)
end
def visible_projects
PresentationHelper.published_projects(dato.projects)
end
def visible_completed_projects
PresentationHelper.published_completed_projects(dato.projects)
end
def visible_schedule_events
PresentationHelper.published_schedule_events(dato.schedule_events)
end
def visible_videos
PresentationHelper.published_videos(dato.videos)
end
def visible_work_positions
PresentationHelper.published_work_positions(dato.work_positions)
end
def past_events
visible_schedule_events.reverse.select do |event|
event.date_shown < DateTime.now
end
end
def current_and_past_events
visible_schedule_events.reverse.select do |event|
event.date_shown <= DateTime.now
end
end
def current_and_future_events
visible_schedule_events.select do |event|
event.date_shown >= DateTime.now
end
end
def nearest_date
return current_and_future_events.first.date_shown unless current_and_future_events.empty?
end
def days_in_minister_schedule
days = (visible_schedule_events.each_with_object([]) do |event, daily_arr|
daily_arr << event.date_shown.strftime("%d%B%Y")
end)
days.uniq!
end
def schedule_events_by_day
days_in_minister_schedule.each_with_object({}) do |day, hash|
hash[day] = (visible_schedule_events.select do |e|
e.date_shown.strftime("%d%B%Y") == day
end)
end
end
def months_in_minister_schedule
m = (visible_schedule_events.each_with_object([]) do |e, arr|
arr << e.date_shown.strftime("%B%Y")
end)
m.uniq!
end
def schedule_events_by_month
months_in_minister_schedule.each_with_object({}) do |month, h|
h[month] = (schedule_events_by_day.select do |k, v|
k.downcase.include?(month.downcase)
end)
end
end
def visible_taggable_contents
(visible_announcements +
visible_articles +
visible_interviews +
visible_participations +
visible_press_releases +
visible_projects +
visible_completed_projects +
visible_focus_pages +
visible_videos +
visible_schedule_events +
visible_work_positions +
visible_pages(dato.general_pages) +
visible_pages(dato.minister_subpages) +
visible_pages(dato.undersecretary_subpages) +
visible_pages(dato.department_subpages) +
visible_pages(dato.projects_subpages) +
visible_pages(dato.news_subpages))
end
def visible_tags
PresentationHelper.published_tags(dato.tags) &
visible_taggable_contents.collect(&:tags).flatten
end
def featured_tags
visible_tags & dato.company.featured_tags
end
def visible_pages(pages)
PresentationHelper.published_pages(pages)
end
def visible_fl_pages(pages)
PresentationHelper.published_pages(pages).reject(&:parent)
end
def links_to_existing_page?(link)
if link.link.respond_to?(:slug)
link.link.slug
else
true
end
end
def visible_links(links)
links.select { |l| links_to_existing_page?(l) }
end
def menu_label_with_fallback(page)
if page.respond_to?(:menu_label) && page.menu_label.present?
page.menu_label
elsif page.respond_to?(:name) && page.name.present?
page.name
elsif page.respond_to?(:title) && page.title.present?
HTML_Truncator.truncate(page.title, 5)
end
end
def project_link_label(link)
if link.cta_label.present?
link.cta_label
else
t("link_labels.website")
end
end
def cta_label(item)
item.cta_label.present? ? item.cta_label : item.title
end
def editorial_models_api_keys
%w[announcement
article
interview
participation
press_release
focus_page
project
video
general_page
work_position
work_positions_index
minister_subpage
undersecretary_subpage
department_subpage
italy2026_subpage
innovate_subpage
projects_subpage
news_subpage]
end
def page_is_editorial(page)
editorial_models_api_keys.include?(page.item_type.api_key)
end
def explore_models_api_keys
%w[tags_index tag explore_page]
end
def page_is_explore(page)
explore_models_api_keys.include?(page.item_type.api_key)
end
def anchor_id(title)
return "" if !title
title.parameterize
end
def show_update_date_api_keys
%w[focus_page
project
general_page
work_position
minister_subpage
undersecretary_subpage
department_subpage
italy2026_subpage
innovate_subpage
projects_subpage
news_subpage]
end
def page_show_update_date?(page)
show_update_date_api_keys.include?(page.item_type.api_key)
end
def show_update_date_in_preview_api_keys
%w[announcement
article
interview
participation
press_release]
end
def page_show_update_date_in_preview?(page)
show_update_date_in_preview_api_keys.include?(page.item_type.api_key)
end
def all_index_pages
[dato.articles_index,
dato.announcements_index,
dato.interviews_index,
dato.work_positions_index,
dato.participations_index,
dato.press_releases_index,
dato.focus_index,
dato.projects_page,
#dato.completed_projects_index,
dato.videos_index
]
end
def sharable_socials
%w[facebook twitter linkedin whatsapp]
end
def localizable_api_keys
%w[article
interview
participation
press_release
general_page
work_position
innovate_subpage
minister_subpage
undersecretary_subpage
department_subpage
italy2026_subpage
projects_subpage
news_subpage
video]
end
def page_is_localizable?(page)
localizable_api_keys.include?(page.item_type.api_key)
end
def main_locale?(locale)
locale == locales[0]
end
def in_italian_zone(time)
time.in_time_zone(ENV["TZ"])
end
end
dato.tap do |dato|
I18n.with_locale(:en) do
locale = :en
I18n.fallbacks[:en] = [:en]
visible_articles = PresentationHelper.published_articles(dato.articles)
visible_interviews = PresentationHelper.published_interviews(dato.interviews)
visible_participations = PresentationHelper.published_participations(dato.participations)
visible_press_releases = PresentationHelper.published_press_releases(dato.press_releases)
visible_general_pages = PresentationHelper.published_pages(dato.general_pages)
visible_minister_subpages = PresentationHelper.published_pages(dato.minister_subpages)
visible_undersecretary_subpages = PresentationHelper.published_pages(dato.undersecretary_subpages)
visible_department_subpages = PresentationHelper.published_pages(dato.department_subpages)
visible_italy2026_subpages = PresentationHelper.published_pages(dato.italy2026_subpages)
visible_innovate_subpages = PresentationHelper.published_pages(dato.innovate_subpages)
visible_projects_subpages = PresentationHelper.published_pages(dato.projects_subpages)
visible_news_subpages = PresentationHelper.published_pages(dato.news_subpages)
visible_resource_redirects = PresentationHelper.published_redirects(dato.resource_redirects)
visible_videos = PresentationHelper.published_videos(dato.videos)
visible_innovate_subpages.each do |innovate_subpage|
parent_path = innovate_subpage.parent ? "/#{innovate_subpage.parent.slug}" : ""
proxy "/#{dato.innovate_page.slug}#{parent_path}/#{locale}/#{innovate_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: innovate_subpage,
children: PresentationHelper.published_children_pages(innovate_subpage)},
locale: locale
end
visible_articles.each do |article|
proxy "/#{dato.news_page.slug}/#{dato.articles_index.slug}/#{locale}/#{article.slug}/index.html",
"/templates/article.html",
locals: {page: article},
locale: locale
end
visible_interviews.each do |interview|
proxy "/#{dato.news_page.slug}/#{dato.interviews_index.slug}/#{locale}/#{interview.slug}/index.html",
"/templates/interview.html",
locals: {page: interview},
locale: locale
end
visible_participations.each do |participation|
proxy "/#{dato.news_page.slug}/#{dato.participations_index.slug}/#{locale}/#{participation.slug}/index.html",
"/templates/participation.html",
locals: {page: participation},
locale: locale
end
visible_press_releases.each do |press_release|
proxy "/#{dato.news_page.slug}/#{dato.press_releases_index.slug}/#{locale}/#{press_release.slug}/index.html",
"/templates/press_release.html",
locals: {page: press_release},
locale: locale
end
visible_videos.each do |video|
proxy "/#{dato.news_page.slug}/#{dato.videos_index.slug}/#{locale}/#{video.slug}/index.html",
"/templates/video.html",
locals: {page: video},
locale: locale
end
visible_general_pages.each do |general_page|
parent_path = ""
parent_path = "/#{general_page.parent.slug}" if general_page.parent && general_page.parent.slug.present?
proxy "#{parent_path}/#{locale}/#{general_page.slug}/index.html",
"/templates/page.html",
locals: {page: general_page,
children: PresentationHelper.published_children_pages(general_page)},
locale: locale
end
visible_minister_subpages.each do |minister_subpage|
parent_path = minister_subpage.parent ? "/#{minister_subpage.parent.slug}" : ""
proxy "/#{dato.minister_page.slug}#{parent_path}/#{locale}/#{minister_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: minister_subpage,
children: PresentationHelper.published_children_pages(minister_subpage)},
locale: locale
end
visible_undersecretary_subpages.each do |undersecretary_subpage|
parent_path = undersecretary_subpage.parent ? "/#{undersecretary_subpage.parent.slug}" : ""
proxy "/#{dato.undersecretary_page.slug}#{parent_path}/#{locale}/#{undersecretary_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: undersecretary_subpage,
children: PresentationHelper.published_children_pages(undersecretary_subpage)},
locale: locale
end
visible_italy2026_subpages.each do |italy2026_subpage|
parent_path = italy2026_subpage.parent ? "/#{italy2026_subpage.parent.slug}" : ""
proxy "/#{dato.italy2026_page.slug}#{parent_path}/#{locale}/#{italy2026_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: italy2026_subpage,
children: PresentationHelper.published_children_pages(italy2026_subpage)},
locale: locale
end
visible_department_subpages.each do |department_subpage|
parent_path = department_subpage.parent ? "/#{department_subpage.parent.slug}" : ""
proxy "/#{dato.department_page.slug}#{parent_path}/#{locale}/#{department_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: department_subpage,
children: PresentationHelper.published_children_pages(department_subpage)},
locale: locale
end
visible_projects_subpages.each do |projects_subpage|
parent_path = projects_subpage.parent ? "/#{projects_subpage.parent.slug}" : ""
proxy "/#{dato.projects_page.slug}#{parent_path}/#{locale}/#{projects_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: projects_subpage,
children: PresentationHelper.published_children_pages(projects_subpage)},
locale: locale
end
visible_news_subpages.each do |news_subpage|
parent_path = news_subpage.parent ? "/#{news_subpage.parent.slug}" : ""
proxy "/#{dato.news_page.slug}#{parent_path}/#{locale}/#{news_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: news_subpage,
children: PresentationHelper.published_children_pages(news_subpage)},
locale: locale
end
visible_resource_redirects.each do |resource_redirect|
path = PresentationHelper.path_without_domain(resource_redirect.old_url)
proxy "#{path}index.html",
"/templates/resource_redirect.html",
locals: {page: resource_redirect},
locale: locale
end
end
I18n.with_locale(:it) do
locale = :it
visible_announcements = PresentationHelper.published_announcements(dato.announcements)
visible_articles = PresentationHelper.published_articles(dato.articles)
visible_interviews = PresentationHelper.published_interviews(dato.interviews)
visible_participations = PresentationHelper.published_participations(dato.participations)
visible_press_releases = PresentationHelper.published_press_releases(dato.press_releases)
visible_focus_pages = PresentationHelper.published_focus_pages(dato.focus_pages)
visible_projects = PresentationHelper.published_projects(dato.projects)
visible_completed_projects = PresentationHelper.published_completed_projects(dato.projects)
visible_general_pages = PresentationHelper.published_pages(dato.general_pages)
visible_innovate_subpages = PresentationHelper.published_pages(dato.innovate_subpages)
visible_work_positions = PresentationHelper.published_work_positions(dato.work_positions)
visible_minister_subpages = PresentationHelper.published_pages(dato.minister_subpages)
visible_undersecretary_subpages = PresentationHelper.published_pages(dato.undersecretary_subpages)
visible_department_subpages = PresentationHelper.published_pages(dato.department_subpages)
visible_italy2026_subpages = PresentationHelper.published_pages(dato.italy2026_subpages)
visible_projects_subpages = PresentationHelper.published_pages(dato.projects_subpages)
visible_news_subpages = PresentationHelper.published_pages(dato.news_subpages)
visible_tags = PresentationHelper.published_tags(dato.tags)
visible_videos = PresentationHelper.published_videos(dato.videos)
visible_resource_redirects = PresentationHelper.published_redirects(dato.resource_redirects)
def paginate_with_fallback(
items,
index_page,
parent_page,
locale,
per_page,
index_template = "/templates/index_page.html"
)
parent_path = "#{parent_page.slug}/"
index_path = index_page.slug.to_s
path = "/#{parent_path}#{index_path}"
if items.any?
paginate items,
path,
index_template,
suffix: "/page/:num/index",
locals: {page: index_page},
per_page: per_page
else
proxy "#{path}/index.html",
index_template,
locals: {page: index_page},
locale: locale
end
end
visible_resource_redirects.each do |resource_redirect|
path = PresentationHelper.path_without_domain(resource_redirect.old_url)
proxy "#{path}index.html",
"/templates/resource_redirect.html",
locals: {page: resource_redirect},
locale: locale
end
proxy "/index.html",
"/templates/homepage.html",
locals: {page: dato.homepage},
locale: locale
proxy "/#{dato.search_page.slug}/index.html",
"/templates/search.html",
locals: {page: dato.search_page},
locale: locale
proxy "/#{dato.explore_page.slug}/index.html",
"/templates/explore.html",
locals: {page: dato.explore_page},
locale: locale
visible_general_pages.each do |general_page|
parent_path = general_page.parent ? "/#{general_page.parent.slug}" : ""
proxy "#{parent_path}/#{general_page.slug}/index.html",
"/templates/page.html",
locals: {page: general_page,
children: PresentationHelper.published_children_pages(general_page)},
locale: locale
end
proxy "/#{dato.completed_projects_index.slug}/index.html",
"/templates/completed_projects.html",
locals: {page: dato.completed_projects_index},
locale: locale
paginate_with_fallback(visible_completed_projects,
dato.completed_projects_index,
dato.projects_page,
locale,
10,
"/templates/completed_projects.html")
visible_completed_projects.each do |completed_project|
proxy "/#{dato.projects_page.slug}/#{completed_project.slug}/index.html",
"/templates/project.html",
locals: {page: completed_project},
locale: locale
end
proxy "/#{dato.schedule_archive_page.slug}/index.html",
"/templates/archive.html",
locals: {page: dato.schedule_archive_page},
locale: locale
proxy "/#{dato.schedule_page.slug}/index.html",
"/templates/schedule.html",
locals: {page: dato.schedule_page},
locale: locale
visible_schedule_events = dato.schedule_events.sort_by(&:date_shown)
current_and_future_events = visible_schedule_events.select do |event|
event.date_shown >= DateTime.now
end
days = (current_and_future_events.each_with_object([]) do |event, daily_arr|
daily_arr << event.date_shown.strftime("%d %B %Y")
end)
days.uniq!
events_by_day = (days.each_with_object({}) do |day, h|
h[day] = (current_and_future_events.select do |e|
e.date_shown.strftime("%d %B %Y") == day
end)
end)
months = (current_and_future_events.each_with_object([]) do |e, arr|
arr << e.date_shown.strftime("%B %Y")
end)
months.uniq!
events_by_month = months.each_with_object({}) do |month, h|
h[month] = (events_by_day.select do |k, v|
k.downcase.include?(month.downcase)
end)
end
if events_by_month.any?
paginate events_by_month,
"/#{dato.schedule_page.slug}",
"/templates/schedule.html",
suffix: "/page/:num/index",
locals: {page: dato.schedule_page},
per_page: 10
else
proxy "#{dato.schedule_page.slug}/index.html",
"/templates/schedule.html",
locals: {page: dato.schedule_page},
locale: locale
end
archive_events = visible_schedule_events.reverse.select do |event|
event.date_shown <= DateTime.now
end
days_in_archive = (archive_events.each_with_object([]) do |event, daily_arr|
daily_arr << event.date_shown.strftime("%d %B %Y")
end)
days_in_archive.uniq!
archive_events_by_day = (days_in_archive.each_with_object({}) do |day, h|
h[day] = (archive_events.select do |e|
e.date_shown.strftime("%d %B %Y") == day
end)
end)
months_in_archive = (archive_events.each_with_object([]) do |e, arr|
arr << e.date_shown.strftime("%B %Y")
end)
months_in_archive.uniq!
archive_events_by_month = months_in_archive.each_with_object({}) do |month, h|
h[month] = (archive_events_by_day.select do |k, v|
k.downcase.include?(month.downcase)
end)
end
if archive_events_by_month.any?
paginate archive_events_by_month,
"/#{dato.schedule_archive_page.slug}",
"/templates/archive.html",
suffix: "/page/:num/index",
locals: {page: dato.schedule_archive_page},
per_page: 10
else
proxy "#{dato.schedule_archive_page.slug}/index.html",
"/templates/archive.html",
locals: {page: dato.schedule_archive_page},
locale: locale
end
PresentationHelper.published_schedule_events(dato.schedule_events).each do |schedule_event|
proxy "/#{dato.schedule_page.slug}/#{schedule_event.slug}/index.html",
"/templates/schedule_event.html",
locals: {page: schedule_event},
locale: locale
end
if dato.undersecretary_page
proxy "/#{dato.undersecretary_page.slug}/index.html",
"/templates/undersecretary.html",
locals: {page: dato.undersecretary_page},
locale: locale
undersecretary_articles = visible_articles.select { |a| a.owners.include?(dato.undersecretary_page) }
paginate_with_fallback(undersecretary_articles,
dato.undersecretary_articles_index,
dato.undersecretary_page,
locale,
10)
undersecretary_interviews = visible_interviews.select { |i| i.owners.include?(dato.undersecretary_page) }
paginate_with_fallback(undersecretary_interviews,
dato.undersecretary_interviews_index,
dato.undersecretary_page,
locale,
10)
undersecretary_participations = visible_participations.select { |i| i.owners.include?(dato.undersecretary_page) }
paginate_with_fallback(undersecretary_participations,
dato.undersecretary_participations_index,
dato.undersecretary_page,
locale,
10)
undersecretary_press_releases = visible_press_releases.select { |i| i.owners.include?(dato.undersecretary_page) }
paginate_with_fallback(undersecretary_press_releases,
dato.undersecretary_press_releases_index,
dato.undersecretary_page,
locale,
10)
visible_undersecretary_subpages.each do |undersecretary_subpage|
parent_path = undersecretary_subpage.parent ? "/#{undersecretary_subpage.parent.slug}" : ""
proxy "/#{dato.undersecretary_page.slug}#{parent_path}/#{undersecretary_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: undersecretary_subpage,
children: PresentationHelper.published_children_pages(undersecretary_subpage)},
locale: locale
end
end
if dato.minister_page
proxy "/#{dato.minister_page.slug}/index.html",
"/templates/minister.html",
locals: {page: dato.minister_page},
locale: locale
minister_articles = visible_articles.select { |a| a.owners.include?(dato.minister_page) }
paginate_with_fallback(minister_articles,
dato.minister_articles_index,
dato.minister_page,
locale,
10)
minister_interviews = visible_interviews.select { |i| i.owners.include?(dato.minister_page) }
paginate_with_fallback(minister_interviews,
dato.minister_interviews_index,
dato.minister_page,
locale,
10)
minister_participations = visible_participations.select { |i| i.owners.include?(dato.minister_page) }
paginate_with_fallback(minister_participations,
dato.minister_participations_index,
dato.minister_page,
locale,
10)
minister_press_releases = visible_press_releases.select { |i| i.owners.include?(dato.minister_page) }
paginate_with_fallback(minister_press_releases,
dato.minister_press_releases_index,
dato.minister_page,
locale,
10)
visible_minister_subpages.each do |minister_subpage|
parent_path = minister_subpage.parent ? "/#{minister_subpage.parent.slug}" : ""
proxy "/#{dato.minister_page.slug}#{parent_path}/#{minister_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: minister_subpage,
children: PresentationHelper.published_children_pages(minister_subpage)},
locale: locale
end
end
if dato.department_page
proxy "/#{dato.department_page.slug}/index.html",
"/templates/department.html",
locals: {page: dato.department_page},
locale: locale
paginate_with_fallback(visible_focus_pages,
dato.focus_index,
dato.department_page,
locale,
10)
visible_focus_pages.each do |focus_page|
proxy "/#{dato.department_page.slug}/#{dato.focus_index.slug}/#{focus_page.slug}/index.html",
"/templates/focus.html",
locals: {page: focus_page},
locale: locale
end
department_announcements = visible_announcements.select { |i| i.owners.include?(dato.department_page) }
paginate_with_fallback(department_announcements,
dato.department_announcements_index,
dato.department_page,
locale,
10)
department_articles = visible_articles.select { |i| i.owners.include?(dato.department_page) }
paginate_with_fallback(department_articles,
dato.department_articles_index,
dato.department_page,
locale,
10)
department_press_releases = visible_press_releases.select { |i| i.owners.include?(dato.department_page) }
paginate_with_fallback(department_press_releases,
dato.department_press_releases_index,
dato.department_page,
locale,
10)
visible_department_subpages.each do |department_subpage|
parent_path = department_subpage.parent ? "/#{department_subpage.parent.slug}" : ""
proxy "/#{dato.department_page.slug}#{parent_path}/#{department_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: department_subpage,
children: PresentationHelper.published_children_pages(department_subpage)},
locale: locale
end
end
if dato.italy2026_page
proxy "/#{dato.italy2026_page.slug}/index.html",
"/templates/italy2026.html",
locals: {page: dato.italy2026_page},
locale: locale
if dato.dataviz_page
proxy "/#{dato.italy2026_page.slug}/#{dato.dataviz_page.slug}/index.html",
"/templates/data.html",
locals: {page: dato.dataviz_page},
locale: locale
end
italy2026_articles = visible_articles.select { |i| i.owners.include?(dato.italy2026_page) }
paginate_with_fallback(italy2026_articles,
dato.italy2026_articles_index,
dato.italy2026_page,
locale,
10)
italy2026_press_releases = visible_press_releases.select { |i| i.owners.include?(dato.italy2026_page) }
paginate_with_fallback(italy2026_press_releases,
dato.italy2026_press_releases_index,
dato.italy2026_page,
locale,
10)
italy2026_announcements = visible_announcements.select { |i| i.owners.include?(dato.italy2026_page) }
paginate_with_fallback(italy2026_announcements,
dato.italy2026_announcements_index,
dato.italy2026_page,
locale,
10)
visible_italy2026_subpages.each do |italy2026_subpage|
if italy2026_subpage.template == "dashboard"
parent_path = italy2026_subpage.parent ? "/#{italy2026_subpage.parent.slug}" : ""
proxy "/#{dato.italy2026_page.slug}#{parent_path}/#{italy2026_subpage.slug}/index.html",
"/templates/data.html",
locals: {page: italy2026_subpage,
children: PresentationHelper.published_children_pages(italy2026_subpage)},
locale: locale
else
parent_path = italy2026_subpage.parent ? "/#{italy2026_subpage.parent.slug}" : ""
proxy "/#{dato.italy2026_page.slug}#{parent_path}/#{italy2026_subpage.slug}/index.html",
"/templates/page.html",
locals: {page: italy2026_subpage,
children: PresentationHelper.published_children_pages(italy2026_subpage)},
locale: locale
end