From b81647e7e32ba0fed09b02b77d1d46462325de1e Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 1 Dec 2022 08:25:05 -0800 Subject: [PATCH 1/2] Add markdown TOC generation using pandoc and shell See https://github.com/terrastruct/ci/blob/a875763eccbb51298807901be68c31e5b150dceb/lib/misc.sh#L28 The TOC is generated via pandoc and inserted via shell. `` marks the insertion point, the TOC is inserted right below. I'm using this in utils-go too. We should use it anywhere else we need TOCs. I'm sure pandoc can handle the frontmatter in d2-docs too. --- Makefile | 2 +- README.md | 39 ++++++++++++++++++--------------------- ci/fmt.sh | 7 +++++++ 3 files changed, 26 insertions(+), 22 deletions(-) create mode 100755 ci/fmt.sh diff --git a/Makefile b/Makefile index d4241d86f..fdc039a33 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ all: fmt gen lint build test .PHONY: fmt fmt: - prefix "$@" ./ci/sub/fmt/make.sh + prefix "$@" ./ci/fmt.sh .PHONY: gen gen: prefix "$@" ./ci/gen.sh diff --git a/README.md b/README.md index 6773c6d83..2bb844ccf 100644 --- a/README.md +++ b/README.md @@ -19,27 +19,24 @@ # Table of Contents - -- [What does D2 look like?](#what-does-d2-look-like) -- [Quickstart](#quickstart) -- [Install](#install) -- [D2 as a library](#d2-as-a-library) -- [Themes](#themes) -- [Fonts](#fonts) -- [Export file types](#export-file-types) -- [Language tooling](#language-tooling) -- [Plugins](#plugins) -- [Comparison](#comparison) -- [Contributing](#contributing) -- [License](#license) -- [Related](#related) - * [VSCode extension](#vscode-extension) - * [Vim extension](#vim-extension) - * [Language docs](#language-docs) - * [Misc](#misc) -- [FAQ](#faq) - - +- What does D2 look like? +- Quickstart +- Install +- D2 as a library +- Themes +- Fonts +- Export file types +- Language tooling +- Plugins +- Comparison +- Contributing +- License +- Related + - VSCode extension + - Vim extension + - Language docs + - Misc +- FAQ ## What does D2 look like? diff --git a/ci/fmt.sh b/ci/fmt.sh new file mode 100755 index 000000000..04038462d --- /dev/null +++ b/ci/fmt.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -eu +. "$(dirname "$0")/sub/lib.sh" +cd -- "$(dirname "$0")/.." + +sh_c tocsubst --skip 1 README.md +./ci/sub/fmt/make.sh From 91ac1280b36cd97b6c5a65cd4597273e4fb4485d Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 1 Dec 2022 09:37:20 -0800 Subject: [PATCH 2/2] ci/fmt.sh: More efficient --- ci/fmt.sh | 4 +++- ci/sub | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ci/fmt.sh b/ci/fmt.sh index 04038462d..75c1f1924 100755 --- a/ci/fmt.sh +++ b/ci/fmt.sh @@ -3,5 +3,7 @@ set -eu . "$(dirname "$0")/sub/lib.sh" cd -- "$(dirname "$0")/.." -sh_c tocsubst --skip 1 README.md +if is_changed README.md; then + sh_c tocsubst --skip 1 README.md +fi ./ci/sub/fmt/make.sh diff --git a/ci/sub b/ci/sub index a39a67857..e894a489a 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit a39a678570a0454d6bf63f9012fb5ec107e24df5 +Subproject commit e894a489abaead7314a3f126cdb32f18b272a23f