Skip to content

Commit

Permalink
Allow docs section to have a static order
Browse files Browse the repository at this point in the history
  • Loading branch information
eelcoj committed Oct 21, 2022
1 parent 47909db commit fc1839f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions components/bridgetown_docs_template/navigation_component.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
<div class="fixed top-[3.5rem] h-screen shadow-xl px-4 left-0 hidden peer-checked:block lg:relative lg:top-0 lg:h-auto lg:px-0 lg:block lg:flex-none lg:shadow-none">
<div class="absolute inset-y-0 right-0 w-full lg:w-[50vw] bg-white lg:bg-slate-50"></div>

<nav class="sticky top-[4.5rem] w-64 pr-8 text-base lg:text-sm xl:w-72 xl:pr-16">
<ul role="list" class="-ml-0.5 h-[calc(100vh-4.5rem)] overflow-y-auto py-7 pl-0.5 space-y-8">
<% group_by(@resources, "category").each do |resource| %>
<nav class="sticky top-[4.5rem] w-64 text-base lg:text-sm xl:w-72">
<ul role="list" class="-ml-0.5 h-[calc(100vh-4.5rem)] overflow-y-auto py-7 pl-0.5 pr-8 space-y-8 xl:pr-16">
<% grouped_and_sorted_documentation_resources.each do |resource| %>
<li>
<h3 class="font-semibold tracking-tight text-slate-900">
<%= resource.fetch("name", "No Category").titleize %>
</h3>

<ul role="list" class="pl-3 mt-3 space-y-2">
<% sort(resource.fetch("items", []), "order").each do |item| %>
<% next if !item.published? %>

<li>
<a href="<%= url_for(item) %>" class="text-slate-900 hover:text-slate-800">
<%= item.data.title %>
Expand Down
11 changes: 11 additions & 0 deletions components/bridgetown_docs_template/navigation_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@ class BridgetownDocsTemplate::NavigationComponent < Bridgetown::Component
def initialize(resources)
@resources = resources
end

def grouped_and_sorted_documentation_resources
group_by(@resources, "section")
.sort_by { |resources| documentation_sections_order.find_index(resources["name"]) }
end

private

def documentation_sections_order
[]
end
end

0 comments on commit fc1839f

Please sign in to comment.