drop attachment:// proto, improve docs

Removed attachment:// proto from docs, back compatibility is saved.
Now using the implementatin of `Attachment:` provided by @csoutherland.

Removed a bunch of swear stuff from docs, oh boy I was so frustrated at
that time.
This commit is contained in:
Egor Kovetskiy
2020-07-25 10:58:32 +03:00
parent f39aeb10d7
commit da99cbb9d7
4 changed files with 72 additions and 57 deletions

View File

@@ -186,16 +186,40 @@ func CompileAttachmentLinks(markdown []byte, attaches []Attachment) []byte {
})
for _, replace := range replaces {
from := replace
to := links[replace]
log.Debugf(nil, "replacing: %q -> %q", from, to)
found := false
if bytes.Contains(markdown, []byte("attachment://"+replace)) {
from := "attachment://" + replace
markdown = bytes.ReplaceAll(
markdown,
[]byte(from),
[]byte(to),
)
log.Debugf(nil, "replacing legacy link: %q -> %q", from, to)
markdown = bytes.ReplaceAll(
markdown,
[]byte(from),
[]byte(to),
)
found = true
}
if bytes.Contains(markdown, []byte(replace)) {
from := replace
log.Debugf(nil, "replacing link: %q -> %q", from, to)
markdown = bytes.ReplaceAll(
markdown,
[]byte(from),
[]byte(to),
)
found = true
}
if !found {
log.Warningf(nil, "unused attachment: %s", replace)
}
}
return markdown

View File

@@ -11,12 +11,11 @@ import (
)
const (
HeaderParent = `Parent`
HeaderSpace = `Space`
HeaderTitle = `Title`
HeaderLayout = `Layout`
HeaderAttachment = `Attachment`
HeaderExactAttachment = `ExactAttachment`
HeaderParent = `Parent`
HeaderSpace = `Space`
HeaderTitle = `Title`
HeaderLayout = `Layout`
HeaderAttachment = `Attachment`
)
type Meta struct {
@@ -89,9 +88,6 @@ func ExtractMeta(data []byte) (*Meta, []byte, error) {
meta.Layout = strings.TrimSpace(value)
case HeaderAttachment:
meta.Attachments["attachment://"+value] = value
case HeaderExactAttachment:
meta.Attachments[value] = value
default: