docbrown/lib/tasks/temporary/add_dev_navigation_links.rake
Ridhwana 19c78d6072
[deploy] Prepare the database for the configurable navigation items (#10662)
* feat: add the order of the navigational items to the database + admin interface

* refactor: rename :display_when_signed_in to :display_only_when_signed_in

* chore: rename all instances of display_when_signed_in to display_only_when_signed_in

* feat: add a data script that will setup the base urls

* feat: add a temporary rake file that will allow us to seed prod db's

* chore: oops rename file

* chore: remove the index for now

* chore: remove validation

* feat: change the order field to position and add an index o the name and url

* feat: update everything that uses order to position

* refactor: order by name as a secondary attr
2020-10-07 11:20:32 -04:00

58 lines
4.8 KiB
Ruby

# rubocop:disable Metrics/BlockLength
namespace :temporary do
namespace :navigation_links do
desc "Update DEV's navigation_links"
task update_links: :environment do
protocol = ApplicationConfig["APP_PROTOCOL"].freeze
domain = Rails.application&.initialized? ? SiteConfig.app_domain : ApplicationConfig["APP_DOMAIN"]
base_url = "#{protocol}#{domain}".freeze
reading_icon = File.read(Rails.root.join("app/assets/images/twemoji/drawer.svg")).freeze
thumb_up_icon = File.read(Rails.root.join("app/assets/images/twemoji/thumb-up.svg")).freeze
smart_icon = File.read(Rails.root.join("app/assets/images/twemoji/smart.svg")).freeze
look_icon = File.read(Rails.root.join("app/assets/images/twemoji/look.svg")).freeze
contact_icon = File.read(Rails.root.join("app/assets/images/twemoji/contact.svg")).freeze
# we can probably remove these icons once they in the database
listing_icon = File.read(Rails.root.join("app/assets/images/twemoji/listing.svg")).freeze
mic_icon = File.read(Rails.root.join("app/assets/images/twemoji/mic.svg")).freeze
camera_icon = File.read(Rails.root.join("app/assets/images/twemoji/camera.svg")).freeze
tag_icon = File.read(Rails.root.join("app/assets/images/twemoji/tag.svg")).freeze
bulb_icon = File.read(Rails.root.join("app/assets/images/twemoji/bulb.svg")).freeze
shopping_icon = File.read(Rails.root.join("app/assets/images/twemoji/shopping.svg")).freeze
heart_icon = File.read(Rails.root.join("app/assets/images/twemoji/heart.svg")).freeze
rainbowdev = File.read(Rails.root.join("app/assets/images/rainbowdev.svg")).freeze
NavigationLink.where(url: "#{base_url}/readinglist").first_or_create(name: "Reading List", icon: reading_icon,
display_only_when_signed_in: true,
position: 0)
NavigationLink.where(url: "#{base_url}/listings").first_or_create(name: "Listings", icon: listing_icon,
display_only_when_signed_in: false, position: 1)
NavigationLink.where(url: "#{base_url}/pod").first_or_create(name: "Podcasts", icon: mic_icon,
display_only_when_signed_in: false, position: 2)
NavigationLink.where(url: "#{base_url}/videos").first_or_create(name: "Videos", icon: camera_icon,
display_only_when_signed_in: false, position: 3)
NavigationLink.where(url: "#{base_url}/tags").first_or_create(name: "Tags", icon: tag_icon,
display_only_when_signed_in: false, position: 4)
NavigationLink.where(url: "#{base_url}/code-of-conduct").first_or_create(name: "Code of Conduct",
icon: thumb_up_icon,
display_only_when_signed_in: false,
position: 5)
NavigationLink.where(url: "#{base_url}/faq").first_or_create(name: "FAQ", icon: bulb_icon,
display_only_when_signed_in: false, position: 6)
NavigationLink.where(url: "https://shop.dev.to/").first_or_create(name: "DEV Shop", icon: shopping_icon,
display_only_when_signed_in: false, position: 7)
NavigationLink.where(url: "#{base_url}/sponsors").first_or_create(name: "Sponsors", icon: heart_icon,
display_only_when_signed_in: false, position: 8)
NavigationLink.where(url: "#{base_url}/about").first_or_create(name: "About", icon: rainbowdev,
display_only_when_signed_in: false, position: 9)
NavigationLink.where(url: "#{base_url}/privacy").first_or_create(name: "Privacy Policy", icon: smart_icon,
display_only_when_signed_in: false, position: 10)
NavigationLink.where(url: "#{base_url}/terms").first_or_create(name: "Terms of use", icon: look_icon,
display_only_when_signed_in: false, position: 11)
NavigationLink.where(url: "#{base_url}/contact").first_or_create(name: "Contact", icon: contact_icon,
display_only_when_signed_in: false, position: 12)
end
end
end
# rubocop:enable Metrics/BlockLength