From ea8c59961cf4b1d1ee72f6c364bff460462f2447 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Mon, 21 Sep 2020 18:30:11 +0200 Subject: hswg: don't link to drafts --- hswg/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'hswg/main.go') diff --git a/hswg/main.go b/hswg/main.go index 0a92797..b8e6e40 100644 --- a/hswg/main.go +++ b/hswg/main.go @@ -80,6 +80,10 @@ type Metadata struct { Attributes types.Attributes } +// IsDraft returns whether the document is marked as a draft, and should not +// be linked anywhere else. +func (m *Metadata) IsDraft() bool { return m.Attributes.Has("draft") } + // Render converts an io.Reader with an AsciiDoc document to HTML. So long as // the file could be read at all, it will always return a non-empty document. func Render(r io.Reader, config configuration.Configuration) ( @@ -154,7 +158,8 @@ var linkWordRE = regexp.MustCompile(`\b\p{Lu}\p{L}*\b`) func expand(m *map[string]*entry, name string, chunk []byte) []byte { return linkWordRE.ReplaceAllFunc(chunk, func(match []byte) []byte { - if link, ok := (*m)[string(match)]; ok && string(match) != name { + if link, ok := (*m)[string(match)]; ok && string(match) != name && + !link.metadata.IsDraft() { link.backlinks = append(link.backlinks, name) return []byte(makeLink(m, string(match))) } -- cgit v1.2.3-70-g09d2