ソースを参照

docs: DRY sidebar categories

Renée Kooi 6 年 前
コミット
94f993a5a4
1 ファイル変更15 行追加17 行削除
  1. 15 17
      website/themes/uppy/layout/partials/sidebar.ejs

+ 15 - 17
website/themes/uppy/layout/partials/sidebar.ejs

@@ -1,3 +1,10 @@
+<%
+var categories = [
+  { path: 'docs/plugins/', name: 'Plugins', link: true },
+  { path: 'docs/providers/', name: 'Remote Providers', link: true },
+  { path: 'docs/react/', name: 'React Components', link: true },
+]
+%>
 <div class="Sidebar js-Sidebar">
 <div class="Sidebar js-Sidebar">
   <ul class="main-menu">
   <ul class="main-menu">
     <%- partial('partials/main_menu') %>
     <%- partial('partials/main_menu') %>
@@ -9,26 +16,17 @@
       <% } %>
       <% } %>
     </h2>
     </h2>
     <ul class="menu-root">
     <ul class="menu-root">
-      <% site.pages.find({type: type}).sort('order').each(function (p) { %>
+      <% site.pages.find({ type }).sort('order').each((p) => { %>
         <% var path = p.path.replace(/index\.html$/, ''); %>
         <% var path = p.path.replace(/index\.html$/, ''); %>
+        <% var category = categories.find((c) => c.path === path) %>
         <% // see https://github.com/vuejs/vuejs.org/blob/master/themes/vue/layout/partials/toc.ejs %>
         <% // see https://github.com/vuejs/vuejs.org/blob/master/themes/vue/layout/partials/toc.ejs %>
-        <% if (path === 'docs/plugins/') { %>
+        <% if (category) { %>
           <li>
           <li>
-            <h3><a href="/docs/plugins/">Plugins</a></h3>
-          </li>
-          <li>
-            <a href="/<%- path %>" class="sidebar-link<%- page.title === p.title ? ' current' : '' %><%- p.is_new ? ' new' : '' %>"><%- p.title %></a>
-          </li>
-        <% } else if (path === 'docs/providers/') { %>
-          <li>
-            <h3><a href="/docs/providers/">Remote Providers</a></h3>
-          </li>
-          <li>
-            <a href="/<%- path %>" class="sidebar-link<%- page.title === p.title ? ' current' : '' %><%- p.is_new ? ' new' : '' %>"><%- p.title %></a>
-          </li>
-        <% } else if (path === 'docs/react/') { %>
-          <li>
-            <h3><a href="/docs/react/">React Components</a></h3>
+            <% if (category.link) { %>
+              <h3><a href="<%- category.path %>"><%- category.name %></a></h3>
+            <% } else { %>
+              <h3><%- category.name %></h3>
+            <% } %>
           </li>
           </li>
           <li>
           <li>
             <a href="/<%- path %>" class="sidebar-link<%- page.title === p.title ? ' current' : '' %><%- p.is_new ? ' new' : '' %>"><%- p.title %></a>
             <a href="/<%- path %>" class="sidebar-link<%- page.title === p.title ? ' current' : '' %><%- p.is_new ? ' new' : '' %>"><%- p.title %></a>