@@ -656,7 +656,7 @@ def create_documentation_navigation_item(area, entry, position, parent: nil) # r
656656 if entry [ :type ] == :directory
657657 attributes [ :item_type ] = 'dropdown'
658658 if entry [ :default_path ] . present?
659- attributes [ :linkable ] = documentation_page_for ( entry [ :title ] , entry [ :default_path ] )
659+ attributes [ :linkable ] = documentation_page_for ( entry [ :title ] , entry [ :default_path ] , area )
660660 else
661661 attributes [ :url ] = '#'
662662 end
@@ -666,7 +666,7 @@ def create_documentation_navigation_item(area, entry, position, parent: nil) # r
666666 end
667667 else
668668 attributes [ :item_type ] = 'link'
669- attributes [ :linkable ] = documentation_page_for ( entry [ :title ] , entry [ :path ] )
669+ attributes [ :linkable ] = documentation_page_for ( entry [ :title ] , entry [ :path ] , area )
670670 create_documentation_item_with_context ( area , attributes )
671671 end
672672 end
@@ -693,9 +693,9 @@ def create_documentation_item_with_context(area, attributes)
693693 raise ActiveRecord ::RecordInvalid . new ( e . record ) , "#{ e . message } -- #{ attributes . inspect } "
694694 end
695695
696- def documentation_page_for ( title , relative_path )
696+ def documentation_page_for ( title , relative_path , sidebar_nav_area = nil )
697697 slug = documentation_slug ( relative_path )
698- attrs = documentation_page_attributes ( title , slug , relative_path )
698+ attrs = documentation_page_attributes ( title , slug , relative_path , sidebar_nav_area )
699699 page = ::BetterTogether ::Page . i18n . find_by ( slug : slug )
700700
701701 if page
@@ -704,16 +704,22 @@ def documentation_page_for(title, relative_path)
704704 locked_page . reload
705705 locked_page . assign_attributes ( attrs )
706706 locked_page . save!
707+ # Re-set the slug after save in case FriendlyId regenerated it
708+ locked_page . update_columns ( slug : slug ) if locked_page . slug != slug
707709 locked_page
708710 else
709- ::BetterTogether ::Page . create! ( attrs )
711+ new_page = ::BetterTogether ::Page . create! ( attrs )
712+ # Re-set the slug after creation in case FriendlyId regenerated it
713+ new_page . slug = slug if new_page . slug != slug
714+ new_page . save! ( validate : false ) if new_page . changed?
715+ new_page
710716 end
711717 end
712718
713- def documentation_page_attributes ( title , slug , relative_path ) # rubocop:todo Metrics/MethodLength
714- {
719+ def documentation_page_attributes ( title , slug , relative_path , sidebar_nav_area = nil ) # rubocop:todo Metrics/MethodLength
720+ attrs = {
715721 title_en : title ,
716- slug_en : slug ,
722+ slug_en : slug , # Set slug directly via Mobility to bypass FriendlyId normalization
717723 published_at : Time . zone . now ,
718724 privacy : 'public' ,
719725 protected : true ,
@@ -727,13 +733,19 @@ def documentation_page_attributes(title, slug, relative_path) # rubocop:todo Met
727733 }
728734 ]
729735 }
736+
737+ # Associate the documentation navigation area as the sidebar nav
738+ attrs [ :sidebar_nav ] = sidebar_nav_area if sidebar_nav_area . present?
739+
740+ attrs
730741 end
731742
732743 def documentation_slug ( path )
733744 relative = path . is_a? ( Pathname ) ? documentation_relative_path ( path ) : path . to_s
734- base_slug = relative . sub ( /\. md\z /i , '' ) . tr ( '/' , '-' ) . parameterize
735- base_slug = 'docs' if base_slug . blank?
736- "docs-#{ base_slug } "
745+ # Remove .md extension, downcase, and preserve directory structure with slashes
746+ base_slug = relative . sub ( /\. md\z /i , '' ) . downcase . tr ( '_' , '-' )
747+ base_slug = 'overview' if base_slug . blank?
748+ "docs/#{ base_slug } "
737749 end
738750
739751 def documentation_file_path ( relative_path )
0 commit comments