func findCustomDocFiles()

in scripts/generate-docs/custom_doc.go [72:98]


func findCustomDocFiles(root string) ([]customDocEvent, error) {
	// Return all the custom doc files under root. Intelligently understand the directory structure
	// and interpret the data_stream name from it for each file.
	var customFiles []customDocEvent

	dataStreamRoot := filepath.Clean(filepath.Join(root, "data_stream"))
	dataStreamNames, err := os.ReadDir(dataStreamRoot)
	if err != nil {
		return nil, errors.Wrapf(err, "Failed to list directory %s", dataStreamRoot)
	}
	for _, dataStreamName := range dataStreamNames {
		dataStreamNameRoot := filepath.Join(dataStreamRoot, dataStreamName.Name())
		err := filepath.WalkDir(dataStreamNameRoot, func(path string, info os.DirEntry, err error) error {

			if !info.IsDir() {
				cleanPath := filepath.Clean(path)
				event := customDocEvent{filePath: path, dataStream: dataStreamName.Name(), fileSubPath: cleanPath[len(dataStreamRoot):]}
				customFiles = append(customFiles, event)
			}
			return nil
		})
		if err != nil {
			return nil, errors.Wrapf(err, "failed to load data_stream directory %s", dataStreamName.Name())
		}
	}
	return customFiles, err
}