diff --git a/generate_markdown_list.py b/generate_markdown_list.py index c1da5be..9c171f0 100644 --- a/generate_markdown_list.py +++ b/generate_markdown_list.py @@ -5,20 +5,19 @@ def generate_markdown_list(root_dir): markdown_list = [] - for subdir, dirs, files in os.walk(root_dir): + for subdir, _, files in os.walk(root_dir): for file in files: if file.endswith(".md"): file_path = os.path.join(subdir, file) - print(f"Processing file: {file_path}") # Debugging track, skill, module = get_levels(file_path) + title = get_header(file_path) markdown_list.append({ - "path": file_path, - "title": get_header(file_path), "track": track, "skill": skill, - "module": module + "module": module, + "title": title, + "path": file_path }) - print(f"Markdown files found: {len(markdown_list)}") # Debugging return markdown_list def get_header(file_path): @@ -30,39 +29,28 @@ def get_header(file_path): def get_levels(file_path): parts = file_path.split(os.sep) - if len(parts) >= 4: - return parts[-4], parts[-3], parts[-2] - return None, None, None + track = parts[1] if len(parts) > 1 else None + skill = parts[2] if len(parts) > 2 else None + module = parts[3] if len(parts) > 3 else None + return track, skill, module def save_to_csv(data, filename): - if not data: - print(f"No data to write to {filename}") - return - keys = data[0].keys() + keys = data[0].keys() if data else [] with open(filename, 'w', newline='') as output_file: dict_writer = csv.DictWriter(output_file, keys) dict_writer.writeheader() dict_writer.writerows(data) - print(f"CSV file saved: {filename}") # Debugging def save_to_json(data, filename): - if not data: - print(f"No data to write to {filename}") - return with open(filename, 'w') as f: json.dump(data, f, indent=2) - print(f"JSON file saved: {filename}") # Debugging def save_to_yaml(data, filename): - if not data: - print(f"No data to write to {filename}") - return with open(filename, 'w') as f: yaml.dump(data, f, default_flow_style=False) - print(f"YAML file saved: {filename}") # Debugging if __name__ == "__main__": - root_dir = "path/to/your/markdown/files" # Make sure this path is correct + root_dir = "." # Asegúrate de estar en la raíz del repositorio markdown_list = generate_markdown_list(root_dir) save_to_csv(markdown_list, "markdown_files.csv")