1
0

manifest_serializer.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # frozen_string_literal: true
  2. class ManifestSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. include ActionView::Helpers::TextHelper
  5. ICON_SIZES = %w(
  6. 36
  7. 48
  8. 72
  9. 96
  10. 144
  11. 192
  12. 256
  13. 384
  14. 512
  15. ).freeze
  16. attributes :id, :name, :short_name,
  17. :icons, :theme_color, :background_color,
  18. :display, :start_url, :scope,
  19. :share_target, :shortcuts
  20. def id
  21. # This is set to `/home` because that was the old value of `start_url` and
  22. # thus the fallback ID computed by Chrome:
  23. # https://developer.chrome.com/blog/pwa-manifest-id/
  24. '/home'
  25. end
  26. def name
  27. object.title
  28. end
  29. def short_name
  30. object.title
  31. end
  32. def icons
  33. ICON_SIZES.map do |size|
  34. {
  35. src: full_pack_url("media/icons/android-chrome-#{size}x#{size}.png"),
  36. sizes: "#{size}x#{size}",
  37. type: 'image/png',
  38. purpose: 'any maskable',
  39. }
  40. end
  41. end
  42. def theme_color
  43. '#191b22'
  44. end
  45. def background_color
  46. '#191b22'
  47. end
  48. def display
  49. 'standalone'
  50. end
  51. def start_url
  52. '/'
  53. end
  54. def scope
  55. '/'
  56. end
  57. def share_target
  58. {
  59. url_template: 'share?title={title}&text={text}&url={url}',
  60. action: 'share',
  61. method: 'GET',
  62. enctype: 'application/x-www-form-urlencoded',
  63. params: {
  64. title: 'title',
  65. text: 'text',
  66. url: 'url',
  67. },
  68. }
  69. end
  70. def shortcuts
  71. [
  72. {
  73. name: 'Compose new post',
  74. url: '/publish',
  75. },
  76. {
  77. name: 'Notifications',
  78. url: '/notifications',
  79. },
  80. {
  81. name: 'Explore',
  82. url: '/explore',
  83. },
  84. ]
  85. end
  86. end