mirror of
https://github.com/kovetskiy/mark.git
synced 2025-06-02 03:32:42 +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 1> -->
|
||||||
<!-- Parent: <parent 2> -->
|
<!-- Parent: <parent 2> -->
|
||||||
<!-- Title: <title> -->
|
<!-- Title: <title> -->
|
||||||
|
<!-- Emoji: 🚀 -->
|
||||||
<!-- Attachment: <local path> -->
|
<!-- Attachment: <local path> -->
|
||||||
<!-- Label: <label 1> -->
|
<!-- Label: <label 1> -->
|
||||||
<!-- Label: <label 2> -->
|
<!-- Label: <label 2> -->
|
||||||
@ -977,6 +978,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|||||||
<tr>
|
<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/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/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>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/kovetskiy/gopencils"
|
"github.com/kovetskiy/gopencils"
|
||||||
"github.com/kovetskiy/lorg"
|
"github.com/kovetskiy/lorg"
|
||||||
@ -48,7 +49,7 @@ type PageInfo struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
|
||||||
Version struct {
|
Version struct {
|
||||||
Number int64 `json:"number"`
|
Number int64 `json:"number"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
} `json:"version"`
|
} `json:"version"`
|
||||||
|
|
||||||
@ -513,7 +514,7 @@ func (api *API) CreatePage(
|
|||||||
return request.Response.(*PageInfo), nil
|
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
|
nextPageVersion := page.Version.Number + 1
|
||||||
oldAncestors := []map[string]interface{}{}
|
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{}{
|
payload := map[string]interface{}{
|
||||||
"id": page.ID,
|
"id": page.ID,
|
||||||
"type": page.Type,
|
"type": page.Type,
|
||||||
@ -541,16 +565,7 @@ func (api *API) UpdatePage(page *PageInfo, newContent string, minorEdit bool, ve
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
// Fix to set full-width as has changed on Confluence APIs again.
|
"properties": properties,
|
||||||
// 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.
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,7 +616,7 @@ func (api *API) DeletePageLabel(page *PageInfo, label string) (*LabelInfo, error
|
|||||||
|
|
||||||
request, err := api.rest.Res(
|
request, err := api.rest.Res(
|
||||||
"content/"+page.ID+"/label", &LabelInfo{},
|
"content/"+page.ID+"/label", &LabelInfo{},
|
||||||
).SetQuery(map[string]string{"name": label}).Delete()
|
).SetQuery(map[string]string{"name": label}).Delete()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
5
main.go
5
main.go
@ -537,7 +537,7 @@ func processFile(
|
|||||||
)
|
)
|
||||||
|
|
||||||
versionPattern := `\[v([a-f0-9]{40})]$`
|
versionPattern := `\[v([a-f0-9]{40})]$`
|
||||||
re := regexp.MustCompile(versionPattern)
|
re := regexp.MustCompile(versionPattern)
|
||||||
|
|
||||||
matches := re.FindStringSubmatch(target.Version.Message)
|
matches := re.FindStringSubmatch(target.Version.Message)
|
||||||
|
|
||||||
@ -563,9 +563,8 @@ func processFile(
|
|||||||
finalVersionMessage = cCtx.String("version-message")
|
finalVersionMessage = cCtx.String("version-message")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if shouldUpdatePage {
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ const (
|
|||||||
HeaderType = `Type`
|
HeaderType = `Type`
|
||||||
HeaderTitle = `Title`
|
HeaderTitle = `Title`
|
||||||
HeaderLayout = `Layout`
|
HeaderLayout = `Layout`
|
||||||
|
HeaderEmoji = `Emoji`
|
||||||
HeaderAttachment = `Attachment`
|
HeaderAttachment = `Attachment`
|
||||||
HeaderLabel = `Label`
|
HeaderLabel = `Label`
|
||||||
HeaderInclude = `Include`
|
HeaderInclude = `Include`
|
||||||
@ -31,6 +32,7 @@ type Meta struct {
|
|||||||
Title string
|
Title string
|
||||||
Layout string
|
Layout string
|
||||||
Sidebar string
|
Sidebar string
|
||||||
|
Emoji string
|
||||||
Attachments []string
|
Attachments []string
|
||||||
Labels []string
|
Labels []string
|
||||||
ContentAppearance string
|
ContentAppearance string
|
||||||
@ -107,6 +109,9 @@ func ExtractMeta(data []byte, spaceFromCli string, titleFromH1 bool, parents []s
|
|||||||
meta.Layout = "article"
|
meta.Layout = "article"
|
||||||
meta.Sidebar = strings.TrimSpace(value)
|
meta.Sidebar = strings.TrimSpace(value)
|
||||||
|
|
||||||
|
case HeaderEmoji:
|
||||||
|
meta.Emoji = strings.TrimSpace(value)
|
||||||
|
|
||||||
case HeaderAttachment:
|
case HeaderAttachment:
|
||||||
meta.Attachments = append(meta.Attachments, value)
|
meta.Attachments = append(meta.Attachments, value)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user