From 6d6d4baf8229b06c8b115975feb0a90c0a7f8b24 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Tue, 19 Nov 2019 10:02:20 +0100 Subject: [PATCH] Add support for likes, tags in content and micro section --- entry.go | 16 +++++++++++++++- post.go | 6 ++++++ validation.go | 3 +-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/entry.go b/entry.go index fbf590b..11ee555 100644 --- a/entry.go +++ b/entry.go @@ -24,6 +24,8 @@ type Entry struct { slug string replyLink string replyTitle string + likeLink string + likeTitle string filename string location string token string @@ -85,6 +87,9 @@ func createEntryFromValueMap(values map[string][]string) (*Entry, error) { if inReplyTo, ok := values["in-reply-to"]; ok { entry.replyLink = inReplyTo[0] } + if likeOf, ok := values["like-of"]; ok { + entry.likeLink = likeOf[0] + } if token, ok := values["access_token"]; ok { entry.token = "Bearer " + token[0] } @@ -114,6 +119,9 @@ func computeExtraSettings(entry *Entry) error { } else if strings.HasPrefix(text, "slug: ") { // 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: ") { // Link entry.link = strings.TrimPrefix(text, "link: ") @@ -123,6 +131,12 @@ func computeExtraSettings(entry *Entry) error { } else if strings.HasPrefix(text, "reply-title: ") { // 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 { _, _ = fmt.Fprintln(&filteredContent, text) } @@ -142,7 +156,7 @@ func computeExtraSettings(entry *Entry) error { if entry.section == "posts" { entry.filename = "content/" + entry.section + "/" + entry.slug + ".md" 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.location = fmt.Sprintf("%v%v/%02d/%02d/%v", blogURL, entry.section, now.Year(), int(now.Month()), entry.slug) } else { diff --git a/post.go b/post.go index 80739b9..0f56c78 100644 --- a/post.go +++ b/post.go @@ -30,6 +30,12 @@ func writeFrontMatter(entry *Entry) string { 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") return buff.String() } diff --git a/validation.go b/validation.go index 976143b..73ece0b 100644 --- a/validation.go +++ b/validation.go @@ -34,7 +34,6 @@ func checkAccess(token string) (bool, error) { return false, errors.New("token string is empty") } // form the request to check the token - client := &http.Client{} req, err := http.NewRequest("GET", indieAuthTokenUrl, nil) if err != nil { 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("Authorization", token) // send the request - res, err := client.Do(req) + res, err := http.Client{}.Do(req) if err != nil { return false, errors.New("error sending the request for checking token access") }