mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-23 13:22:40 +08:00
Add label support
This commit is contained in:
parent
8018b54627
commit
f86dd2723a
@ -25,6 +25,8 @@ File in the extended format should follow the specification:
|
||||
<!-- Parent: <parent 2> -->
|
||||
<!-- Title: <title> -->
|
||||
<!-- Attachment: <local path> -->
|
||||
<!-- Label: <label 1> -->
|
||||
<!-- Label: <label 2> -->
|
||||
|
||||
<page contents>
|
||||
```
|
||||
|
2
main.go
2
main.go
@ -240,7 +240,7 @@ func main() {
|
||||
html = buffer.String()
|
||||
}
|
||||
|
||||
err = api.UpdatePage(target, html)
|
||||
err = api.UpdatePage(target, html, meta.Labels)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ func (api *API) CreatePage(
|
||||
}
|
||||
|
||||
func (api *API) UpdatePage(
|
||||
page *PageInfo, newContent string,
|
||||
page *PageInfo, newContent string, newLabels []string,
|
||||
) error {
|
||||
nextPageVersion := page.Version.Number + 1
|
||||
|
||||
@ -450,6 +450,17 @@ func (api *API) UpdatePage(
|
||||
{"id": page.Ancestors[len(page.Ancestors)-1].Id},
|
||||
}
|
||||
|
||||
labels := []map[string]interface{}{}
|
||||
for _, label := range newLabels {
|
||||
if label != "" {
|
||||
item := map[string]interface{}{
|
||||
"prexix": "global",
|
||||
"name": label,
|
||||
}
|
||||
labels = append(labels, item)
|
||||
}
|
||||
}
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"id": page.ID,
|
||||
"type": "page",
|
||||
@ -465,6 +476,9 @@ func (api *API) UpdatePage(
|
||||
"representation": "storage",
|
||||
},
|
||||
},
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels,
|
||||
},
|
||||
}
|
||||
|
||||
request, err := api.rest.Res(
|
||||
|
@ -16,6 +16,7 @@ const (
|
||||
HeaderTitle = `Title`
|
||||
HeaderLayout = `Layout`
|
||||
HeaderAttachment = `Attachment`
|
||||
HeaderLabel = `Label`
|
||||
)
|
||||
|
||||
type Meta struct {
|
||||
@ -24,6 +25,7 @@ type Meta struct {
|
||||
Title string
|
||||
Layout string
|
||||
Attachments map[string]string
|
||||
Labels []string
|
||||
}
|
||||
|
||||
var (
|
||||
@ -90,6 +92,9 @@ func ExtractMeta(data []byte) (*Meta, []byte, error) {
|
||||
case HeaderAttachment:
|
||||
meta.Attachments[value] = value
|
||||
|
||||
case HeaderLabel:
|
||||
meta.Labels = append(meta.Labels, value)
|
||||
|
||||
default:
|
||||
log.Errorf(
|
||||
nil,
|
||||
|
Loading…
x
Reference in New Issue
Block a user