Skip to content

Commit db34e4a

Browse files
authored
Added link checker + added check command. (#5)
Signed-off-by: Bartlomiej Plotka <[email protected]>
1 parent d895183 commit db34e4a

26 files changed

+1667
-156
lines changed

Makefile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ deps: ## Ensures fresh go.mod and go.sum.
5656
.PHONY: docs
5757
docs: build ## Generates config snippets and doc formatting.
5858
@echo ">> generating docs $(PATH)"
59-
@PATH=$(GOBIN) mdox fmt *.md
59+
@PATH=$(GOBIN) mdox fmt -l *.md
6060

6161
.PHONY: format
62-
format: ## Formats Go code including imports and cleans up white noise.
62+
format: ## Formats Go code.
6363
format: $(GOIMPORTS)
6464
@echo ">> formatting code"
6565
@$(GOIMPORTS) -w $(FILES_TO_FMT)
66-
@SED_BIN="$(SED)" scripts/cleanup-white-noise.sh $(FILES_TO_FMT)
6766

6867
.PHONY: test
6968
test: ## Runs all Go unit tests.
@@ -90,16 +89,14 @@ lint: ## Runs various static analysis against our code.
9089
lint: $(FAILLINT) $(GOLANGCI_LINT) $(MISSPELL) build format docs check-git deps
9190
$(call require_clean_work_tree,"detected not clean master before running lint")
9291
@echo ">> verifying modules being imported"
93-
@$(FAILLINT) -paths "errors=github.com/pkg/errors" ./...
92+
#TODO(bwplotka): Uncomment once we upstream merrors package: @$(FAILLINT) -paths "errors=github.com/pkg/errors" ./...
9493
@$(FAILLINT) -paths "fmt.{Print,PrintfPrintln,Sprint}" -ignore-tests ./...
9594
@echo ">> examining all of the Go files"
9695
@go vet -stdmethods=false ./...
9796
@echo ">> linting all of the Go files GOGC=${GOGC}"
9897
@$(GOLANGCI_LINT) run
9998
@echo ">> detecting misspells"
10099
@find . -type f | grep -v vendor/ | grep -vE '\./\..*' | xargs $(MISSPELL) -error
101-
@echo ">> detecting white noise"
102-
@find . -type f \( -name "*.md" -o -name "*.go" \) | SED_BIN="$(SED)" xargs scripts/cleanup-white-noise.sh
103100
@echo ">> ensuring Copyright headers"
104101
@go run ./scripts/copyright/...
105-
$(call require_clean_work_tree,"detected white noise or/and files without copyright; run make lint file and commit changes.")
102+
$(call require_clean_work_tree,"detected files without copyright; run make lint file and commit changes.")

README.md

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,105 @@
22

33
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/bwplotka/mdox) [![Latest Release](https://img.shields.io/github/release/bwplotka/mdox.svg?style=flat-square)](https://github.com/bwplotka/mdox/releases/latest) [![CI](https://github.com/bwplotka/mdox/workflows/go/badge.svg)](https://github.com/bwplotka/mdox/actions?query=workflow%3Ago) [![Go Report Card](https://goreportcard.com/badge/github.com/bwplotka/mdox)](https://goreportcard.com/report/github.com/bwplotka/mdox)
44

5-
CLI toolset for maintaining automated, high quality project documentation and website leveraging markdown and git.
5+
`mdox` (spelled as `md docs`) is a CLI for maintaining automated, high quality project documentation and website leveraging [Github Flavored Markdown](https://github.github.com/gfm/) and git.
66

7-
Goal: Allow projects to have self-updating up-to-date documentation available in both markdown (e.g readable from GitHub) and static HTML. Hosted in the same repository as code, fool-proof and integrated with Pull Requests CI and hosting CD.
7+
## Goals
88

9-
### Features
9+
Allow projects to have self-updating up-to-date documentation available in both markdown (e.g readable from GitHub) and static HTML. Hosted in the same repository as code and integrated with Pull Requests CI, hosting CD and code generation.
1010

11-
```bash mdox-gen-exec="mdox --help"
12-
usage: mdox [<flags>] <command> [<args> ...]
11+
## Features
1312

14-
Markdown Project Documentation Toolbox.
13+
* Enhanced amd consistent formatting for markdown files, focused on `.md` code readability.
14+
* Auto generation of code block content based on `mdoc-exec` directives (see [#code-generation](#code-generation)).
15+
* Robust and fast relative and remote link checking.
16+
* "Localizing" links to relative docs if specified (useful for multi-domain websites or multi-version doc).
1517

16-
Flags:
17-
-h, --help Show context-sensitive help (also try --help-long and
18-
--help-man).
19-
--version Show application version.
20-
--log.level=info Log filtering level.
21-
--log.format=logfmt Log format to use. Possible options: logfmt or json.
18+
## Usage
19+
20+
Just run `mdox fmt` and pass markdown files (or glob matching those).
2221

23-
Commands:
24-
help [<command>...]
25-
Show help.
22+
For example this README is formatted by the CI on every PR using [`mdox fmt -l *.md` command](https://github.com/bwplotka/mdox/blob/9e183714070f464b1ef089da3df8048aff1abeda/Makefile#L59).
2623

27-
fmt <files>...
28-
Formats given markdown files uniformly following GFM (Github Flavored
29-
Markdown: https://github.github.com/gfm/).
24+
```bash mdox-gen-exec="mdox fmt --help"
25+
usage: mdox fmt [<flags>] <files>...
3026

31-
Additionally it supports special fenced code directives to autogenerate code
32-
snippets:
27+
Formats in-place given markdown files uniformly following GFM (Github Flavored
28+
Markdown: https://github.github.com/gfm/). Example: mdox fmt *.md
3329

34-
```<lang> mdox-gen-exec="<executable + arguments>"
30+
Flags:
31+
-h, --help Show context-sensitive help (also try
32+
--help-long and --help-man).
33+
--version Show application version.
34+
--log.level=info Log filtering level.
35+
--log.format=logfmt Log format to use. Possible options: logfmt or
36+
json.
37+
--check If true, fmt will not modify the given files,
38+
instead it will fail if files needs formatting
39+
--code.disable-directives If false, fmt will parse custom fenced code
40+
directives prefixed with 'mdox-gen' to
41+
autogenerate code snippets. For example:
42+
43+
```<lang> mdox-gen-exec="<executable + arguments>"
44+
45+
This directive runs executable with arguments
46+
and put its stderr and stdout output inside
47+
code block content, replacing existing one.
48+
--links.anchor-dir=LINKS.ANCHOR-DIR
49+
Anchor directory for link transformers. PWD
50+
flag is not specified.
51+
--links.localise.address-regex=LINKS.LOCALISE.ADDRESS-REGEX
52+
If specified, all HTTP(s) links that target a
53+
domain and path matching given regexp will be
54+
transformed to relative to anchor dir path (if
55+
exists).Absolute path links will be converted
56+
to relative links to anchor dri as well.
57+
-l, --links.validate If true, all links will be validated
58+
--links.validate.address-regex=^$
59+
If specified, all links will be validated,
60+
except those matching the given target address.
61+
62+
Args:
63+
<files> Markdown file(s) to process.
3564
36-
This directive runs executable with arguments and put its stderr and stdout
37-
output inside code block content, replacing existing one.
65+
```
3866

39-
Example: mdox fmt *.md
67+
### Code Generation
4068

41-
web gen <files>...
42-
Generate versioned docs
69+
It's not uncommon that documentation is explaining code or configuration snippets. One of the challenges of such documentation is keeping it up to date. This is where `mdox` code block directives comes handy! To ensure mdox will auto update code snippet add `mdox-gen-exec="<whatever command you want take output from>"` after language directive on code block.
4370
71+
For example this Readme contains `mdox --help` which is has to be auto generated on every PR:
4472
73+
```markdown
74+
``` bash mdox-gen-exec="mdox fmt --help"
75+
...
4576
```
4677
47-
### Production Usage
78+
You can disable this feature by specifying `--code.disable-directives`
4879
49-
* [Thanos](https://github.com/bwplotka/thanos) (TBD)
80+
### Installing
5081
51-
## Requirements
82+
Requirements to build this tool:
5283
53-
* Go 1.14+
84+
* Go 1.15+
5485
* Linux or MacOS
5586
56-
## Installing
57-
5887
```shell
5988
go get github.com/bwplotka/mdox && go mod tidy
6089
```
6190
62-
or via [bingo](github.com/bwplotka/bingo) if want to pin it:
91+
or via [bingo](https://github.com/bwplotka/bingo) if want to pin it:
6392
6493
```shell
6594
bingo get -u github.com/bwplotka/mdox
6695
```
6796
68-
Any contributions are welcome! Just use GitHub Issues and Pull Requests as usual. We follow [Thanos Go coding style](https://thanos.io/contributing/coding-style-guide.md/) guide.
97+
### Production Usage
98+
99+
* [Thanos](https://github.com/bwplotka/thanos) (TBD)
100+
101+
## Contributing
102+
103+
Any contributions are welcome! Just use GitHub Issues and Pull Requests as usual. We follow [Thanos Go coding style](https://thanos.io/tip/contributing/coding-style-guide.md/) guide.
69104
70105
## Initial Author
71106

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ module github.com/bwplotka/mdox
33
go 1.14
44

55
require (
6-
github.com/Kunde21/markdownfmt/v2 v2.0.2
6+
github.com/Kunde21/markdownfmt/v2 v2.0.4-0.20201214081534-353201c4cdce
77
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
88
github.com/go-kit/kit v0.10.0
9+
github.com/gocolly/colly/v2 v2.1.0
910
github.com/gohugoio/hugo v0.74.3
10-
github.com/google/go-cmp v0.4.0 // indirect
1111
github.com/mattn/go-shellwords v1.0.10
1212
github.com/mitchellh/mapstructure v1.2.2 // indirect
1313
github.com/oklog/run v1.1.0
1414
github.com/pkg/errors v0.9.1
15+
github.com/sergi/go-diff v1.0.0
16+
github.com/stretchr/testify v1.5.1
1517
github.com/yuin/goldmark v1.2.1
16-
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
1718
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 // indirect
1819
gopkg.in/alecthomas/kingpin.v2 v2.2.6
1920
)
2021

21-
replace github.com/Kunde21/markdownfmt/v2 => github.com/bwplotka/markdownfmt/v2 v2.0.0-20201129164736-749754008490
22+
replace github.com/Kunde21/markdownfmt/v2 => github.com/bwplotka/markdownfmt/v2 v2.0.0-20201223130030-c496cb0bcc88

0 commit comments

Comments
 (0)