Add support for likes, tags in content and micro section
parent
767683653a
commit
6d6d4baf82
16
entry.go
16
entry.go
|
@ -24,6 +24,8 @@ type Entry struct {
|
||||||
slug string
|
slug string
|
||||||
replyLink string
|
replyLink string
|
||||||
replyTitle string
|
replyTitle string
|
||||||
|
likeLink string
|
||||||
|
likeTitle string
|
||||||
filename string
|
filename string
|
||||||
location string
|
location string
|
||||||
token string
|
token string
|
||||||
|
@ -85,6 +87,9 @@ func createEntryFromValueMap(values map[string][]string) (*Entry, error) {
|
||||||
if inReplyTo, ok := values["in-reply-to"]; ok {
|
if inReplyTo, ok := values["in-reply-to"]; ok {
|
||||||
entry.replyLink = inReplyTo[0]
|
entry.replyLink = inReplyTo[0]
|
||||||
}
|
}
|
||||||
|
if likeOf, ok := values["like-of"]; ok {
|
||||||
|
entry.likeLink = likeOf[0]
|
||||||
|
}
|
||||||
if token, ok := values["access_token"]; ok {
|
if token, ok := values["access_token"]; ok {
|
||||||
entry.token = "Bearer " + token[0]
|
entry.token = "Bearer " + token[0]
|
||||||
}
|
}
|
||||||
|
@ -114,6 +119,9 @@ func computeExtraSettings(entry *Entry) error {
|
||||||
} else if strings.HasPrefix(text, "slug: ") {
|
} else if strings.HasPrefix(text, "slug: ") {
|
||||||
// Slug
|
// Slug
|
||||||
entry.slug = strings.TrimPrefix(text, "slug: ")
|
entry.slug = strings.TrimPrefix(text, "slug: ")
|
||||||
|
} else if strings.HasPrefix(text, "tags: ") {
|
||||||
|
// Tags
|
||||||
|
entry.tags = strings.Split(strings.TrimPrefix(text, "tags: "), ",")
|
||||||
} else if strings.HasPrefix(text, "link: ") {
|
} else if strings.HasPrefix(text, "link: ") {
|
||||||
// Link
|
// Link
|
||||||
entry.link = strings.TrimPrefix(text, "link: ")
|
entry.link = strings.TrimPrefix(text, "link: ")
|
||||||
|
@ -123,6 +131,12 @@ func computeExtraSettings(entry *Entry) error {
|
||||||
} else if strings.HasPrefix(text, "reply-title: ") {
|
} else if strings.HasPrefix(text, "reply-title: ") {
|
||||||
// Reply title
|
// Reply title
|
||||||
entry.replyTitle = strings.TrimPrefix(text, "reply-title: ")
|
entry.replyTitle = strings.TrimPrefix(text, "reply-title: ")
|
||||||
|
} else if strings.HasPrefix(text, "like-link: ") {
|
||||||
|
// Like link
|
||||||
|
entry.likeLink = strings.TrimPrefix(text, "like-link: ")
|
||||||
|
} else if strings.HasPrefix(text, "like-title: ") {
|
||||||
|
// Like title
|
||||||
|
entry.likeTitle = strings.TrimPrefix(text, "like-title: ")
|
||||||
} else {
|
} else {
|
||||||
_, _ = fmt.Fprintln(&filteredContent, text)
|
_, _ = fmt.Fprintln(&filteredContent, text)
|
||||||
}
|
}
|
||||||
|
@ -142,7 +156,7 @@ func computeExtraSettings(entry *Entry) error {
|
||||||
if entry.section == "posts" {
|
if entry.section == "posts" {
|
||||||
entry.filename = "content/" + entry.section + "/" + entry.slug + ".md"
|
entry.filename = "content/" + entry.section + "/" + entry.slug + ".md"
|
||||||
entry.location = blogURL + entry.section + "/" + entry.slug
|
entry.location = blogURL + entry.section + "/" + entry.slug
|
||||||
} else if entry.section == "thoughts" || entry.section == "links" {
|
} else if entry.section == "thoughts" || entry.section == "links" || entry.section == "micro" {
|
||||||
entry.filename = fmt.Sprintf("content/%v/%02d/%02d/%v.md", entry.section, now.Year(), int(now.Month()), entry.slug)
|
entry.filename = fmt.Sprintf("content/%v/%02d/%02d/%v.md", entry.section, now.Year(), int(now.Month()), entry.slug)
|
||||||
entry.location = fmt.Sprintf("%v%v/%02d/%02d/%v", blogURL, entry.section, now.Year(), int(now.Month()), entry.slug)
|
entry.location = fmt.Sprintf("%v%v/%02d/%02d/%v", blogURL, entry.section, now.Year(), int(now.Month()), entry.slug)
|
||||||
} else {
|
} else {
|
||||||
|
|
6
post.go
6
post.go
|
@ -30,6 +30,12 @@ func writeFrontMatter(entry *Entry) string {
|
||||||
buff.WriteString(" title: " + entry.replyTitle + "\n")
|
buff.WriteString(" title: " + entry.replyTitle + "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(entry.likeLink) > 0 {
|
||||||
|
buff.WriteString(" like:\n link: " + entry.likeLink + "\n")
|
||||||
|
if len(entry.likeTitle) > 0 {
|
||||||
|
buff.WriteString(" title: " + entry.likeTitle + "\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
buff.WriteString("---\n")
|
buff.WriteString("---\n")
|
||||||
return buff.String()
|
return buff.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ func checkAccess(token string) (bool, error) {
|
||||||
return false, errors.New("token string is empty")
|
return false, errors.New("token string is empty")
|
||||||
}
|
}
|
||||||
// form the request to check the token
|
// form the request to check the token
|
||||||
client := &http.Client{}
|
|
||||||
req, err := http.NewRequest("GET", indieAuthTokenUrl, nil)
|
req, err := http.NewRequest("GET", indieAuthTokenUrl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.New("error making the request for checking token access")
|
return false, errors.New("error making the request for checking token access")
|
||||||
|
@ -42,7 +41,7 @@ func checkAccess(token string) (bool, error) {
|
||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Accept", "application/json")
|
||||||
req.Header.Set("Authorization", token)
|
req.Header.Set("Authorization", token)
|
||||||
// send the request
|
// send the request
|
||||||
res, err := client.Do(req)
|
res, err := http.Client{}.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.New("error sending the request for checking token access")
|
return false, errors.New("error sending the request for checking token access")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue