Browse Source

generate links for section indexes

bryanl 2 years ago
parent
commit
6eea9ab1df

+ 15
- 8
cmd/doctl-gen-doc/main.go View File

@@ -32,7 +32,7 @@ func main() {
32 32
 		log.Fatalf("output directory %q does not exist", *outputDir)
33 33
 	}
34 34
 
35
-	err := genTree(cmd, *outputDir, filePrepender, linkHandler)
35
+	err := genTree(cmd, *outputDir, filePrepender)
36 36
 	if err != nil {
37 37
 		log.Fatalf("generate documentation tree: %v", err)
38 38
 	}
@@ -67,28 +67,35 @@ func filePrepender(section, filename string) string {
67 67
 	return string(b) + "\n\n"
68 68
 }
69 69
 
70
-func linkHandler(name string) string {
71
-	base := strings.TrimSuffix(name, path.Ext(name))
72
-	return "/commands/" + strings.ToLower(base) + "/"
70
+func linkHandler(section string) func(string) string {
71
+	return func(name string) string {
72
+		base := strings.TrimSuffix(name, path.Ext(name))
73
+		return fmt.Sprintf("/commands/%s/%s/", section, strings.ToLower(base))
74
+	}
73 75
 }
74 76
 
75 77
 func genTree(
76 78
 	cmd *commands.Command,
77 79
 	dir string,
78 80
 	filePrepender func(string, string) string,
79
-	linkHandler func(string) string,
80 81
 ) error {
81 82
 	for _, c := range cmd.ChildCommands() {
82 83
 		if !c.IsAvailableCommand() || c.IsHelpCommand() {
83 84
 			continue
84 85
 		}
85
-		if err := genTree(c, dir, filePrepender, linkHandler); err != nil {
86
+		if err := genTree(c, dir, filePrepender); err != nil {
86 87
 			return err
87 88
 		}
88 89
 	}
89 90
 
90 91
 	for _, cat := range cmd.DocCategories {
91
-		basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".md"
92
+		var basename string
93
+		if cmd.IsIndex {
94
+			basename = "index.md"
95
+		} else {
96
+			basename = strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".md"
97
+		}
98
+
92 99
 		baseDir := filepath.Join(dir, cat)
93 100
 		if err := os.MkdirAll(baseDir, 0755); err != nil {
94 101
 			return fmt.Errorf("create directory %q: %v", baseDir, err)
@@ -104,7 +111,7 @@ func genTree(
104 111
 		if _, err := io.WriteString(f, filePrepender(cat, filename)); err != nil {
105 112
 			return err
106 113
 		}
107
-		if err := doc.GenMarkdownCustom(cmd.Command, f, linkHandler); err != nil {
114
+		if err := doc.GenMarkdownCustom(cmd.Command, f, linkHandler(cat)); err != nil {
108 115
 			return err
109 116
 		}
110 117
 

+ 1
- 0
commands/account.go View File

@@ -11,6 +11,7 @@ func Account() *Command {
11 11
 			Long:  "account is used to access account commands",
12 12
 		},
13 13
 		DocCategories: []string{"account"},
14
+		IsIndex:       true,
14 15
 	}
15 16
 
16 17
 	CmdBuilder(cmd, RunAccountGet, "get", "get account", Writer,

+ 1
- 0
commands/command.go View File

@@ -13,6 +13,7 @@ type Command struct {
13 13
 	fmtCols []string
14 14
 
15 15
 	childCommands []*Command
16
+	IsIndex       bool
16 17
 }
17 18
 
18 19
 // AddCommand adds child commands and adds child commands for cobra as well.

+ 22
- 0
docs/layouts/_default/single.html View File

@@ -0,0 +1,22 @@
1
+{{ partial "header.html" . }}
2
+
3
+<body>
4
+
5
+  {{ partial "sidebar.html" . }}
6
+
7
+  <div class="wrapper">
8
+    <div class="content">
9
+
10
+      <div class="row">
11
+        <div class="small-12 columns">
12
+          {{ .Content }}
13
+        </div>
14
+      </div>
15
+
16
+
17
+    </div>
18
+  </div>
19
+
20
+</body>
21
+
22
+</html>

+ 31
- 30
docs/layouts/index.html View File

@@ -7,54 +7,55 @@
7 7
   <div class="wrapper">
8 8
     <div class="content">
9 9
       <div class="row">
10
-        <div class="small-6 columns small-centered">
10
+        <div class="small-8 columns small-centered">
11 11
           <strong>doctl</strong> is a command line interface to DigitalOcean
12 12
         </div>
13 13
       </div>
14 14
 
15 15
       <div class="row">
16
-        <div class="small-10 columns small-centered">
16
+        <div class="small-12 columns small-centered">
17 17
           <img class="u-mv-5" src="/images/doctl-intro.gif" alt="doctl intro">
18 18
         </div>
19 19
       </div>
20
-    </div>
21
-
22
-    <div class="row">
23
-      <div class="small-6 columns small-centered">
24
-        Download
25 20
 
26
-        <div class="row">
27
-          <div class="small-7 columns">
28
-            Linux
29
-          </div>
30
-          <div class="small-5 columns">
31
-            <a href="#">i386</a>
32
-            <a href="#">x64</a>
21
+      <div class="row">
22
+        <div class="small-8 columns">
23
+          <h3>Download</h3>
24
+
25
+          <div class="row">
26
+            <div class="small-3 columns">
27
+              Linux
28
+            </div>
29
+            <div class="small-9 columns">
30
+              <a href="#">i386</a>
31
+              <a href="#">x64</a>
32
+            </div>
33 33
           </div>
34
-        </div>
35 34
 
36
-        <div class="row">
37
-          <div class="small-7 columns">
38
-            OS X
35
+          <div class="row">
36
+            <div class="small-3 columns">
37
+              OS X
38
+            </div>
39
+            <div class="small-9 columns">
40
+              <a href="#">x64</a>
41
+            </div>
39 42
           </div>
40
-          <div class="small-5 columns">
41
-            <a href="#">x64</a>
42
-          </div>
43
-        </div>
44 43
 
45
-        <div class="row">
46
-          <div class="small-7 columns">
47
-            Windows
48
-          </div>
49
-          <div class="small-5 columns">
50
-            <a href="#">i386</a>
51
-            <a href="#">x64</a>
44
+          <div class="row">
45
+            <div class="small-3 columns">
46
+              Windows
47
+            </div>
48
+            <div class="small-9 columns">
49
+              <a href="#">i386</a>
50
+              <a href="#">x64</a>
51
+            </div>
52 52
           </div>
53
-        </div>
54 53
 
55 54
 
55
+        </div>
56 56
       </div>
57 57
     </div>
58
+  </div>
58 59
 
59 60
 </body>
60 61
 

+ 6
- 2
docs/layouts/partials/sidebar.html View File

@@ -1,9 +1,13 @@
1 1
 <nav class="SideNav displayNav">
2
-  <h3>doctl</h3>
2
+  <h3>doctl commands</h3>
3 3
   
4 4
   <ul>
5 5
     {{ range $section, $taxonomy := .Site.Sections }}
6
-      <li><a href="">{{ $section }}</a></li>
6
+      {{ range $taxonomy.Pages }}
7
+        {{ if eq .Slug "index" }}
8
+          <li><a href="{{ .Permalink }}">{{ $section }}</a></li>
9
+        {{ end }}         
10
+      {{ end }}
7 11
     {{ end }}
8 12
   </ul>
9 13
 </nav>

+ 18
- 1
docs/themes/buoy/layouts/_default/single.html View File

@@ -1 +1,18 @@
1
-single
1
+{{ partial "header.html" . }}
2
+
3
+<body>
4
+
5
+  {{ partial "sidebar.html" . }}
6
+
7
+  <div class="wrapper">
8
+    <div class="content">
9
+
10
+      <div class="row">
11
+        <div class="small-12 columns">
12
+          {{ .Content }}
13
+        </div>
14
+      </div>
15
+    </div>
16
+  </div>
17
+</body>
18
+</html>