mirror of
https://github.com/kovetskiy/mark.git
synced 2025-05-31 18:22:40 +08:00
feat: support emojis on pages
Define an emoji in the markdown files and get them published as page emoji icons.
This commit is contained in:
parent
f0b4d460a9
commit
1a0e452910
@ -29,6 +29,7 @@ File in the extended format should follow the specification:
|
||||
<!-- Parent: <parent 1> -->
|
||||
<!-- Parent: <parent 2> -->
|
||||
<!-- Title: <title> -->
|
||||
<!-- Emoji: 🚀 -->
|
||||
<!-- Attachment: <local path> -->
|
||||
<!-- Label: <label 1> -->
|
||||
<!-- Label: <label 2> -->
|
||||
@ -977,6 +978,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/recrtl"><img src="https://avatars.githubusercontent.com/u/14078835?v=4?s=100" width="100px;" alt="recrtl"/><br /><sub><b>recrtl</b></sub></a><br /><a href="https://github.com/kovetskiy/mark/commits?author=recrtl" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/seletskiy"><img src="https://avatars.githubusercontent.com/u/674812?v=4?s=100" width="100px;" alt="Stanislav Seletskiy"/><br /><sub><b>Stanislav Seletskiy</b></sub></a><br /><a href="https://github.com/kovetskiy/mark/commits?author=seletskiy" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/nr18"><img src="https://avatars.githubusercontent.com/u/674812?v=4?s=100" width="100px;" alt="Joris Conijn"/><br /><sub><b>Joris Conijn</b></sub></a><br /><a href="https://github.com/kovetskiy/mark/commits?author=nr18" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/kovetskiy/gopencils"
|
||||
"github.com/kovetskiy/lorg"
|
||||
@ -48,7 +49,7 @@ type PageInfo struct {
|
||||
Type string `json:"type"`
|
||||
|
||||
Version struct {
|
||||
Number int64 `json:"number"`
|
||||
Number int64 `json:"number"`
|
||||
Message string `json:"message"`
|
||||
} `json:"version"`
|
||||
|
||||
@ -513,7 +514,7 @@ func (api *API) CreatePage(
|
||||
return request.Response.(*PageInfo), nil
|
||||
}
|
||||
|
||||
func (api *API) UpdatePage(page *PageInfo, newContent string, minorEdit bool, versionMessage string, newLabels []string, appearance string) error {
|
||||
func (api *API) UpdatePage(page *PageInfo, newContent string, minorEdit bool, versionMessage string, newLabels []string, appearance string, emojiString string) error {
|
||||
nextPageVersion := page.Version.Number + 1
|
||||
oldAncestors := []map[string]interface{}{}
|
||||
|
||||
@ -524,6 +525,29 @@ func (api *API) UpdatePage(page *PageInfo, newContent string, minorEdit bool, ve
|
||||
}
|
||||
}
|
||||
|
||||
properties := map[string]interface{}{
|
||||
// Fix to set full-width as has changed on Confluence APIs again.
|
||||
// https://jira.atlassian.com/browse/CONFCLOUD-65447
|
||||
//
|
||||
"content-appearance-published": map[string]interface{}{
|
||||
"value": appearance,
|
||||
},
|
||||
// content-appearance-draft should not be set as this is impacted by
|
||||
// the user editor default configurations - which caused the sporadic published widths.
|
||||
}
|
||||
|
||||
if emojiString != "" {
|
||||
r, _ := utf8.DecodeRuneInString(emojiString)
|
||||
unicodeHex := fmt.Sprintf("%x", r)
|
||||
|
||||
properties["emoji-title-draft"] = map[string]interface{}{
|
||||
"value": unicodeHex,
|
||||
}
|
||||
properties["emoji-title-published"] = map[string]interface{}{
|
||||
"value": unicodeHex,
|
||||
}
|
||||
}
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"id": page.ID,
|
||||
"type": page.Type,
|
||||
@ -541,16 +565,7 @@ func (api *API) UpdatePage(page *PageInfo, newContent string, minorEdit bool, ve
|
||||
},
|
||||
},
|
||||
"metadata": map[string]interface{}{
|
||||
// Fix to set full-width as has changed on Confluence APIs again.
|
||||
// https://jira.atlassian.com/browse/CONFCLOUD-65447
|
||||
//
|
||||
"properties": map[string]interface{}{
|
||||
"content-appearance-published": map[string]interface{}{
|
||||
"value": appearance,
|
||||
},
|
||||
},
|
||||
// content-appearance-draft should not be set as this is impacted by
|
||||
// the user editor default configurations - which caused the sporadic published widths.
|
||||
"properties": properties,
|
||||
},
|
||||
}
|
||||
|
||||
@ -601,7 +616,7 @@ func (api *API) DeletePageLabel(page *PageInfo, label string) (*LabelInfo, error
|
||||
|
||||
request, err := api.rest.Res(
|
||||
"content/"+page.ID+"/label", &LabelInfo{},
|
||||
).SetQuery(map[string]string{"name": label}).Delete()
|
||||
).SetQuery(map[string]string{"name": label}).Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
5
main.go
5
main.go
@ -537,7 +537,7 @@ func processFile(
|
||||
)
|
||||
|
||||
versionPattern := `\[v([a-f0-9]{40})]$`
|
||||
re := regexp.MustCompile(versionPattern)
|
||||
re := regexp.MustCompile(versionPattern)
|
||||
|
||||
matches := re.FindStringSubmatch(target.Version.Message)
|
||||
|
||||
@ -563,9 +563,8 @@ func processFile(
|
||||
finalVersionMessage = cCtx.String("version-message")
|
||||
}
|
||||
|
||||
|
||||
if shouldUpdatePage {
|
||||
err = api.UpdatePage(target, html, cCtx.Bool("minor-edit"), finalVersionMessage, meta.Labels, meta.ContentAppearance)
|
||||
err = api.UpdatePage(target, html, cCtx.Bool("minor-edit"), finalVersionMessage, meta.Labels, meta.ContentAppearance, meta.Emoji)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ const (
|
||||
HeaderType = `Type`
|
||||
HeaderTitle = `Title`
|
||||
HeaderLayout = `Layout`
|
||||
HeaderEmoji = `Emoji`
|
||||
HeaderAttachment = `Attachment`
|
||||
HeaderLabel = `Label`
|
||||
HeaderInclude = `Include`
|
||||
@ -31,6 +32,7 @@ type Meta struct {
|
||||
Title string
|
||||
Layout string
|
||||
Sidebar string
|
||||
Emoji string
|
||||
Attachments []string
|
||||
Labels []string
|
||||
ContentAppearance string
|
||||
@ -107,6 +109,9 @@ func ExtractMeta(data []byte, spaceFromCli string, titleFromH1 bool, parents []s
|
||||
meta.Layout = "article"
|
||||
meta.Sidebar = strings.TrimSpace(value)
|
||||
|
||||
case HeaderEmoji:
|
||||
meta.Emoji = strings.TrimSpace(value)
|
||||
|
||||
case HeaderAttachment:
|
||||
meta.Attachments = append(meta.Attachments, value)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user