diff --git a/Userland/Libraries/LibManual/SectionNode.cpp b/Userland/Libraries/LibManual/SectionNode.cpp index 1d18e77613..1dc0e447ff 100644 --- a/Userland/Libraries/LibManual/SectionNode.cpp +++ b/Userland/Libraries/LibManual/SectionNode.cpp @@ -7,9 +7,11 @@ #include "SectionNode.h" #include "PageNode.h" #include "Path.h" +#include "SubsectionNode.h" #include #include #include +#include namespace Manual { @@ -40,20 +42,34 @@ ErrorOr SectionNode::reify_if_needed() const return {}; m_reified = true; - Core::DirIterator dir_iter { TRY(path()).to_deprecated_string(), Core::DirIterator::Flags::SkipDots }; + auto own_path = TRY(path()); + Core::DirIterator dir_iter { own_path.to_deprecated_string(), Core::DirIterator::Flags::SkipDots }; + + struct Child { + NonnullRefPtr node; + String name_for_sorting; + }; + Vector children; - Vector page_names; while (dir_iter.has_next()) { LexicalPath lexical_path(dir_iter.next_path()); - if (lexical_path.extension() != "md") - continue; - page_names.append(TRY(String::from_utf8(lexical_path.title()))); + if (lexical_path.extension() != "md") { + if (Core::File::is_directory(LexicalPath::absolute_path(own_path.to_deprecated_string(), lexical_path.string()))) { + dbgln("Found subsection {}", lexical_path); + children.append({ .node = TRY(try_make_ref_counted(*this, lexical_path.title())), + .name_for_sorting = TRY(String::from_utf8(lexical_path.title())) }); + } + } else { + children.append({ .node = TRY(try_make_ref_counted(*this, TRY(String::from_utf8(lexical_path.title())))), + .name_for_sorting = TRY(String::from_utf8(lexical_path.title())) }); + } } - quick_sort(page_names); + quick_sort(children, [](auto const& a, auto const& b) { return a.name_for_sorting < b.name_for_sorting; }); - for (auto& page_name : page_names) - m_children.append(TRY(try_make_ref_counted(*this, move(page_name)))); + m_children.ensure_capacity(children.size()); + for (auto child : children) + m_children.unchecked_append(move(child.node)); return {}; }