From 1ccd980f50534bfe005a8d7185ac3f97035d5458 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Mon, 7 Aug 2023 13:09:57 -0700 Subject: [PATCH] Update the README TOC and add script that can generate it --- README.md | 53 ++++++++++++++++++++++----------------------- script/markdown-toc | 31 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 27 deletions(-) create mode 100755 script/markdown-toc diff --git a/README.md b/README.md index b6670a8..4763102 100644 --- a/README.md +++ b/README.md @@ -9,33 +9,32 @@ The architecture is pluggable and the tooling is flexible to make it applicable ## Table of Contents -- [DNS as code - Tools for managing DNS across multiple providers](#dns-as-code---tools-for-managing-dns-across-multiple-providers) -- [Table of Contents](#table-of-contents) -- [Getting started](#getting-started) - * [Workspace](#workspace) - + [Installing a specific commit SHA](#installing-a-specific-commit-sha) - * [Config](#config) - * [Noop](#noop) - * [Making changes](#making-changes) - * [Workflow](#workflow) - * [Bootstrapping config files](#bootstrapping-config-files) -- [Providers](#providers) - * [Updating to use extracted providers](#updating-to-use-extracted-providers) -- [Sources](#sources) - + [Notes](#notes) -- [Compatibility and Compliance](#compatibilty-and-compliance) - * [`lenient`](#-lenient-) - * [`strict_supports`](#-strict-supports-) - * [Configuring `strict_supports`](#configuring--strict-supports-) -- [Custom Sources and Providers](#custom-sources-and-providers) -- [Other Uses](#other-uses) - * [Syncing between providers](#syncing-between-providers) - * [Dynamic sources](#dynamic-sources) -- [Contributing](#contributing) -- [Getting help](#getting-help) -- [Related Projects and Resources](#related-projects-and-resources) -- [License](#license) -- [Authors](#authors) +* [Getting started](#getting-started) + * [Workspace](#workspace) + * [Installing a specific commit SHA](#installing-a-specific-commit-sha) + * [Config](#config) + * [Noop](#noop) + * [Making changes](#making-changes) + * [Workflow](#workflow) + * [Bootstrapping config files](#bootstrapping-config-files) +* [Providers](#providers) + * [Updating to use extracted providers](#updating-to-use-extracted-providers) +* [Sources](#sources) + * [Notes](#notes) +* [Automatic PTR generation](#automatic-ptr-generation) +* [Compatibility and Compliance](#compatibility-and-compliance) + * [`lenient`](#lenient) + * [`strict_supports`](#strict_supports) + * [Configuring `strict_supports`](#configuring-strict_supports) +* [Custom Sources and Providers](#custom-sources-and-providers) +* [Other Uses](#other-uses) + * [Syncing between providers](#syncing-between-providers) + * [Dynamic sources](#dynamic-sources) +* [Contributing](#contributing) +* [Getting help](#getting-help) +* [Related Projects and Resources](#related-projects-and-resources) +* [License](#license) +* [Authors](#authors) ## Getting started diff --git a/script/markdown-toc b/script/markdown-toc new file mode 100755 index 0000000..2b192ef --- /dev/null +++ b/script/markdown-toc @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +from re import compile +from sys import stdin + +splitter = compile(r'\s+') + +in_pre = False +headings = [] +for line in stdin: + if line.startswith('```'): + in_pre = not in_pre + if in_pre or not line.startswith('#'): + continue + level, heading = splitter.split(line, 1) + if 'Table of Contents' in heading: + continue + headings.append((len(level), heading.strip())) + +# ignore the first one, it's more of a title +headings.pop(0) + +print('\n## Table of Contents\n') +min_level = min(h[0] for h in headings) +for heading in headings: + level = heading[0] - min_level + pre = ' ' * (level * 3) + title = heading[1] + link = title.lower().replace(' ', '-').replace('`', '') + print(f'{pre}* [{title}](#{link})') +print()