(sections [][]byte)
| 126 | } |
| 127 | |
| 128 | func writeDocs(sections [][]byte) error { |
| 129 | log.Println("Write docs to destination") |
| 130 | |
| 131 | apiDir := path.Join(docsDirectory, apiSubdir) |
| 132 | err := atomicwrite.File(path.Join(apiDir, apiIndexFile), []byte(apiIndexContent)) |
| 133 | if err != nil { |
| 134 | return xerrors.Errorf(`can't write the index file: %w`, err) |
| 135 | } |
| 136 | |
| 137 | type mdFile struct { |
| 138 | title string |
| 139 | path string |
| 140 | } |
| 141 | var mdFiles []mdFile |
| 142 | |
| 143 | // Write .md files for grouped API method (Templates, Workspaces, etc.) |
| 144 | for _, section := range sections { |
| 145 | sectionName, err := extractSectionName(section) |
| 146 | if err != nil { |
| 147 | return xerrors.Errorf("can't extract section name: %w", err) |
| 148 | } |
| 149 | log.Printf("Write section: %s", sectionName) |
| 150 | |
| 151 | mdFilename := toMdFilename(sectionName) |
| 152 | docPath := path.Join(apiDir, mdFilename) |
| 153 | err = atomicwrite.File(docPath, section) |
| 154 | if err != nil { |
| 155 | return xerrors.Errorf(`can't write doc file "%s": %w`, docPath, err) |
| 156 | } |
| 157 | mdFiles = append(mdFiles, mdFile{ |
| 158 | title: sectionName, |
| 159 | path: "./" + path.Join(apiSubdir, mdFilename), |
| 160 | }) |
| 161 | } |
| 162 | |
| 163 | // Sort API pages |
| 164 | // The "General" section is expected to be always first. |
| 165 | sort.Slice(mdFiles, func(i, j int) bool { |
| 166 | if mdFiles[i].title == "General" { |
| 167 | return true // "General" < ... - sorted |
| 168 | } |
| 169 | if mdFiles[j].title == "General" { |
| 170 | return false // ... < "General" - not sorted |
| 171 | } |
| 172 | return slices.IsSorted([]string{mdFiles[i].title, mdFiles[j].title}) |
| 173 | }) |
| 174 | |
| 175 | // Update manifest.json |
| 176 | type route struct { |
| 177 | Title string `json:"title,omitempty"` |
| 178 | Description string `json:"description,omitempty"` |
| 179 | Path string `json:"path,omitempty"` |
| 180 | IconPath string `json:"icon_path,omitempty"` |
| 181 | State []string `json:"state,omitempty"` |
| 182 | Children []route `json:"children,omitempty"` |
| 183 | } |
| 184 | |
| 185 | type manifest struct { |
no test coverage detected