Skip to content

Commit

Permalink
docs: move injecturls helper to dedicated package
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Sep 21, 2023
1 parent af96adb commit 7ee4292
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 31 deletions.
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ command = "go run github.com/quay/claircore/internal/cmd/mdbook-godoc"
command = "go run docs/make_target.go"

[preprocessor.injecturls]
command = "go run docs/injecturls.go"
command = "go run github.com/quay/claircore/internal/cmd/mdbook-injecturls"
11 changes: 5 additions & 6 deletions docs/contributor/misc.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Here's various codebase conventions that don't have dedicated pages:

- URLs
URLs in code should be annotated with a `//doc:url` directive comment. See the
the `docs/injecturls.go` file for documentation on how the preprocessor works.
The list of keywords isn't an allowlist, so an invocation like the following
should list the ones actually used in the documentation:

git grep injecturls -- :/docs/*.md
URLs in code should be annotated with a `//doc:url` directive comment. See
the the `internal/cmd/mdbook-injecturls` command for documentation on how the
preprocessor works. The list of keywords isn't an allowlist, so an invocation
like the following should list the ones actually used in the documentation
using a command like `git grep injecturls -- :/docs/*.md`.
29 changes: 5 additions & 24 deletions docs/injecturls.go → internal/cmd/mdbook-injecturls/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//go:build ignore

// Injecturls is a helper meant to collect urls via a comment directive.
// Mdbook-injecturls is a helper meant to collect urls via a comment directive.
//
// Any string declaration with a directive like
//
Expand All @@ -17,15 +15,12 @@ package main

import (
"context"
"encoding/json"
"fmt"
"go/ast"
"go/parser"
"go/token"
"io/fs"
"log"
"os"
"os/signal"
"path/filepath"
"regexp"
"strconv"
Expand All @@ -40,18 +35,10 @@ var (
)

func main() {
log.SetFlags(log.LstdFlags | log.Lmsgprefix)
log.SetPrefix("injecturls: ")
mdbook.Args(os.Args)

cfg, book, err := mdbook.Decode(os.Stdin)
if err != nil {
panic(err)
}
ctx := context.Background()
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, os.Kill)
defer cancel()
mdbook.Main("injecturls", newProc)
}

func newProc(ctx context.Context, cfg *mdbook.Context) (*mdbook.Proc, error) {
proc := mdbook.Proc{
Chapter: func(ctx context.Context, b *strings.Builder, c *mdbook.Chapter) error {
if c.Path == nil {
Expand Down Expand Up @@ -165,11 +152,5 @@ func main() {
return nil
},
}
if err := proc.Walk(ctx, book); err != nil {
panic(err)
}

if err := json.NewEncoder(os.Stdout).Encode(&book); err != nil {
panic(err)
}
return &proc, nil
}

0 comments on commit 7ee4292

Please sign in to comment.