aboutsummaryrefslogtreecommitdiff
path: root/hswg
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-09-21 18:30:11 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-09-21 19:26:54 +0200
commitea8c59961cf4b1d1ee72f6c364bff460462f2447 (patch)
tree9f69e0424c6c6222c2d3b8c5eaeaf9ccb57b3d69 /hswg
parent750f2139f574dc98de0be185d6be05101630ef41 (diff)
downloadhaven-ea8c59961cf4b1d1ee72f6c364bff460462f2447.tar.gz
haven-ea8c59961cf4b1d1ee72f6c364bff460462f2447.tar.xz
haven-ea8c59961cf4b1d1ee72f6c364bff460462f2447.zip
hswg: don't link to drafts
Diffstat (limited to 'hswg')
-rw-r--r--hswg/main.go7
1 files changed, 6 insertions, 1 deletions
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)))
}