Skip to content

Commit

Permalink
Update page tree to menu odes Rake task
Browse files Browse the repository at this point in the history
It now adds the first public child as nodes page for
visible but not public pages that have public children.
  • Loading branch information
tvdeyen committed Dec 27, 2019
1 parent 3f936fc commit 4837df8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/tasks/alchemy/convert.rake
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,31 @@ namespace :alchemy do
abort "\n⨯ There are already menus present in your database. Aborting!"
end

def name_for_node(page)
if page.visible? && page.public? && !page.redirects_to_external?
nil
else
page.name
end
end

def page_for_node(page)
if page.visible? && page.public? && !page.redirects_to_external?
page
elsif Alchemy::Config.get(:redirect_to_public_child) && page.visible? && !page.public? && page.children.published.any?
page.children.published.first
end
end

def convert_to_nodes(children, node:)
children.each do |page|
has_children = page.children.any?
next unless page.visible || has_children

Alchemy::Deprecation.silence do
new_node = node.children.create!(
name: page.visible? && page.public? && !page.redirects_to_external? ? nil : page.name,
page: page.visible? && page.public? && !page.redirects_to_external? ? page : nil,
name: name_for_node(page),
page: page_for_node(page),
url: page.redirects_to_external? ? page.urlname : nil,
external: page.redirects_to_external? && Alchemy::Config.get(:open_external_links_in_new_tab),
language_id: page.language_id
Expand Down

0 comments on commit 4837df8

Please sign in to comment.