Selaa lähdekoodia

feat(docs): Improve generated index pages

Michael Bromley 7 vuotta sitten
vanhempi
sitoutus
8aa99ca887

+ 3 - 2
codegen/generate-docs.ts

@@ -125,7 +125,7 @@ function generateDocs(filePaths: string[], hugoApiDocsPath: string, typeMap: Typ
             fs.mkdirSync(categoryDir);
         }
         if (!fs.existsSync(indexFile)) {
-            const indexFileContent = generateFrontMatter(info.category, 10) + `\n\n# ${info.category}`;
+            const indexFileContent = generateFrontMatter(info.category, 10, false) + `\n\n# ${info.category}`;
             fs.writeFileSync(indexFile, indexFileContent);
         }
 
@@ -308,11 +308,12 @@ function renderType(type: string, knownTypeMap: Map<string, string>): string {
 /**
  * Generates the Hugo front matter with the title of the document
  */
-function generateFrontMatter(title: string, weight: number): string {
+function generateFrontMatter(title: string, weight: number, showToc: boolean = true): string {
     return `---
 title: "${title}"
 weight: ${weight}
 date: ${new Date().toISOString()}
+showtoc: ${showToc}
 generated: true
 ---
 <!-- This file was generated from the Vendure TypeScript source. Do not modify. Instead, re-run "generate-docs" -->

+ 4 - 0
docs/assets/styles/_markdown.scss

@@ -10,6 +10,10 @@ $block-border-radius: 4px;
         line-height: 1em;
     }
 
+    h1:first-of-type {
+        text-transform: capitalize;
+    }
+
     h2 {
         margin-top: 48px;
     }

+ 6 - 0
docs/assets/styles/main.scss

@@ -99,6 +99,12 @@ ul.pagination {
     margin: $top-bar-height auto 0;
 }
 
+ul.contents-list {
+    padding: 0;
+    list-style-type: none;
+    text-transform: capitalize;
+}
+
 .book-brand {
     margin-top: 0;
 }

+ 7 - 1
docs/content/docs/_index.md

@@ -1 +1,7 @@
-# Documentation Index
+---
+title: "Vendure Documentation"
+weight: 0
+showtoc: false
+---
+
+# Vendure Documentation

+ 12 - 7
docs/layouts/docs/list.html

@@ -1,17 +1,22 @@
 {{ define "main" }}
 <article class="markdown">
-  {{- .Content -}}
+    {{- .Content -}}
+    {{ $list := .Sections }}
+    {{ $list = $list | append .Pages }}
 
-    {{ if gt (len .Pages) 0 }}
-        <ul>
-        {{ range .Pages }}
-            <li>{{ .Title }}</li>
+    {{ if gt (len $list) 0 }}
+    <h3>Contents:</h3>
+    <ul class="contents-list">
+        {{ range sort $list "Weight" }}
+        <li>
+            <a href="{{ .RelPermalink }}">{{ .Title }}</a>
+        </li>
         {{ end}}
-        </ul>
+    </ul>
     {{ end }}
 </article>
 {{ end }}
 
 {{ define "toc" }}
-  {{ partial "docs/toc" . }}
+{{ partial "docs/toc" . }}
 {{ end }}

+ 1 - 1
docs/layouts/partials/docs/toc.html

@@ -1,4 +1,4 @@
-{{ $showToC := default (default true .Site.Params.BookShowToC) .Params.bookshowtoc }}
+{{ $showToC := default (default true .Site.Params.BookShowToC) .Params.showtoc }}
   {{ if and ($showToC) (.Page.TableOfContents) }}
   <aside class="book-toc fixed">
     {{ .Page.TableOfContents }}