| // Copyright 2022 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package docgen |
| |
| import ( |
| "fmt" |
| "io" |
| "sort" |
| ) |
| |
| func WriteToc(settings WriteSettings, index *Index, f io.Writer) { |
| fmt.Fprintf(f, "# Generated by cppdocgen. Do not edit.\n") |
| |
| fmt.Fprintf(f, "toc:\n") |
| fmt.Fprintf(f, "- title: \"Overview\"\n") |
| fmt.Fprintf(f, " path: %s%s\n", settings.TocPath, "index.md") |
| fmt.Fprintf(f, "- heading: \"%s headers\"\n", settings.LibName) |
| |
| // Sort the headers by name for the output (the map ordering is not stable). |
| Headers := make([]*Header, 0, len(index.Headers)) |
| for _, h := range index.Headers { |
| Headers = append(Headers, h) |
| } |
| sort.Sort(headerByName(Headers)) |
| |
| for _, h := range Headers { |
| title := h.CustomTitle() |
| if title == "" { |
| fmt.Fprintf(f, "- title: \"%s\"\n", settings.GetUserIncludePath(h.Name)) |
| } else { |
| fmt.Fprintf(f, "- title: \"%s\"\n", title) |
| } |
| |
| fmt.Fprintf(f, " path: %s%s\n", settings.TocPath, h.ReferenceFileName()) |
| } |
| } |