hswg: don't link to drafts

This commit is contained in:
Přemysl Eric Janouch 2020-09-21 18:30:11 +02:00
parent 750f2139f5
commit ea8c59961c
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 6 additions and 1 deletions

View File

@ -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)))
}