writeSubdirMetas walks dstDir and emits a meta.json in every subdirectory (never the root) listing its direct children alphabetically, with an optional leading "index" when an index.mdx is present.
(ctx context.Context, dstDir string)
| 356 | // (never the root) listing its direct children alphabetically, with an |
| 357 | // optional leading "index" when an index.mdx is present. |
| 358 | func writeSubdirMetas(ctx context.Context, dstDir string) error { |
| 359 | return filepath.WalkDir(dstDir, func(p string, d fs.DirEntry, err error) error { |
| 360 | if err != nil { |
| 361 | return fmt.Errorf("docpost: walk %s: %w", p, err) |
| 362 | } |
| 363 | if err := ensureContext(ctx, fmt.Sprintf("write meta for %s", p)); err != nil { |
| 364 | return err |
| 365 | } |
| 366 | if !d.IsDir() { |
| 367 | return nil |
| 368 | } |
| 369 | rel, err := filepath.Rel(dstDir, p) |
| 370 | if err != nil { |
| 371 | return fmt.Errorf("docpost: relative path from %s to %s: %w", dstDir, p, err) |
| 372 | } |
| 373 | if rel == "." { |
| 374 | return nil // root is hand-maintained |
| 375 | } |
| 376 | return writeDirMeta(ctx, p) |
| 377 | }) |
| 378 | } |
| 379 | |
| 380 | func writeDirMeta(ctx context.Context, dir string) error { |
| 381 | if err := ensureContext(ctx, fmt.Sprintf("write meta for %s", dir)); err != nil { |
no test coverage detected