resolved warnings

master
Niko Abeler 2 months ago
parent a42da82516
commit edf74aa330
  1. 4
      cmd/owl/web/handler.go
  2. 2
      cmd/owl/webmention.go
  3. 17
      directories.go
  4. 26
      renderer_test.go
  5. 14
      user.go
  6. 4
      user_test.go

@ -137,7 +137,7 @@ func userWebmentionHandler(repo *owl.Repository) func(http.ResponseWriter, *http
}
}
if aliasPost != nil {
foundPost = *aliasPost
foundPost = aliasPost
}
err = foundPost.AddIncomingWebmention(source[0])
if err != nil {
@ -197,7 +197,7 @@ func postHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Request,
return
}
html, err := owl.RenderPost(&post)
html, err := owl.RenderPost(post)
if err != nil {
println("Error rendering post: ", err.Error())
w.WriteHeader(http.StatusInternalServerError)

@ -82,7 +82,7 @@ var webmentionCmd = &cobra.Command{
println("Error getting post: ", err.Error())
return
}
processPost(user, &post)
processPost(user, post)
return
}

@ -2,7 +2,6 @@ package owl
import (
"os"
"path/filepath"
"strings"
)
@ -24,22 +23,6 @@ func fileExists(path string) bool {
return err == nil
}
// recursive list of all files in a directory
func walkDir(path string) []string {
files := make([]string, 0)
filepath.Walk(path, func(subPath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
files = append(files, subPath[len(path)+1:])
return nil
})
return files
}
func toDirectoryName(name string) string {
name = strings.ToLower(strings.ReplaceAll(name, " ", "-"))
// remove all non-alphanumeric characters

@ -12,7 +12,7 @@ import (
func TestCanRenderPost(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost", false)
result, err := owl.RenderPost(&post)
result, err := owl.RenderPost(post)
if err != nil {
t.Error("Error rendering post: " + err.Error())
@ -31,7 +31,7 @@ func TestRenderTwitterHandle(t *testing.T) {
config.TwitterHandle = "testhandle"
user.SetConfig(config)
post, _ := user.CreateNewPost("testpost", false)
result, err := owl.RenderPost(&post)
result, err := owl.RenderPost(post)
if err != nil {
t.Error("Error rendering post: " + err.Error())
@ -50,7 +50,7 @@ func TestRenderGitHubHandle(t *testing.T) {
config.GitHubHandle = "testhandle"
user.SetConfig(config)
post, _ := user.CreateNewPost("testpost", false)
result, err := owl.RenderPost(&post)
result, err := owl.RenderPost(post)
if err != nil {
t.Error("Error rendering post: " + err.Error())
@ -66,7 +66,7 @@ func TestRenderGitHubHandle(t *testing.T) {
func TestRenderPostHEntry(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost", false)
result, _ := owl.RenderPost(&post)
result, _ := owl.RenderPost(post)
if !strings.Contains(result, "class=\"h-entry\"") {
t.Error("h-entry container not rendered. Got: " + result)
}
@ -82,7 +82,7 @@ func TestRenderPostHEntry(t *testing.T) {
func TestRendererUsesBaseTemplate(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost", false)
result, err := owl.RenderPost(&post)
result, err := owl.RenderPost(post)
if err != nil {
t.Error("Error rendering post: " + err.Error())
@ -171,7 +171,7 @@ func TestRendersHeaderTitle(t *testing.T) {
})
post, _ := user.CreateNewPost("testpost", false)
result, _ := owl.RenderPost(&post)
result, _ := owl.RenderPost(post)
if !strings.Contains(result, "Test Title") {
t.Error("Header title not rendered. Got: " + result)
}
@ -187,7 +187,7 @@ func TestRenderPostIncludesRelToWebMention(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost", false)
result, _ := owl.RenderPost(&post)
result, _ := owl.RenderPost(post)
if !strings.Contains(result, "rel=\"webmention\"") {
t.Error("webmention rel not rendered. Got: " + result)
}
@ -214,7 +214,7 @@ func TestRenderPostAddsLinksToApprovedWebmention(t *testing.T) {
}
post.PersistIncomingWebmention(webmention)
result, _ := owl.RenderPost(&post)
result, _ := owl.RenderPost(post)
if !strings.Contains(result, "http://example.com/source3") {
t.Error("webmention not rendered. Got: " + result)
}
@ -230,7 +230,7 @@ func TestRenderPostAddsLinksToApprovedWebmention(t *testing.T) {
func TestRenderPostNotMentioningWebmentionsIfNoAvail(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost", false)
result, _ := owl.RenderPost(&post)
result, _ := owl.RenderPost(post)
if strings.Contains(result, "Webmention") {
t.Error("Webmention mentioned. Got: " + result)
@ -241,7 +241,7 @@ func TestRenderPostNotMentioningWebmentionsIfNoAvail(t *testing.T) {
func TestRenderIncludesFullUrl(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost", false)
result, _ := owl.RenderPost(&post)
result, _ := owl.RenderPost(post)
if !strings.Contains(result, "class=\"u-url\"") {
t.Error("u-url not rendered. Got: " + result)
@ -272,7 +272,7 @@ func TestAuthorNameInPost(t *testing.T) {
})
post, _ := user.CreateNewPost("testpost", false)
result, _ := owl.RenderPost(&post)
result, _ := owl.RenderPost(post)
if !strings.Contains(result, "Test Author") {
t.Error("Author Name not included. Got: " + result)
}
@ -293,7 +293,7 @@ func TestRenderReplyWithoutText(t *testing.T) {
content += "Hi \n"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
result, _ := owl.RenderPost(&post)
result, _ := owl.RenderPost(post)
if !strings.Contains(result, "https://example.com/post") {
t.Error("Reply url not rendered. Got: " + result)
}
@ -314,7 +314,7 @@ func TestRenderReplyWithText(t *testing.T) {
content += "Hi \n"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
result, _ := owl.RenderPost(&post)
result, _ := owl.RenderPost(post)
if !strings.Contains(result, "https://example.com/post") {
t.Error("Reply url not rendered. Got: " + result)
}

@ -86,7 +86,7 @@ func (user User) Posts() ([]*Post, error) {
if dirExists(path.Join(user.Dir(), "public", id)) {
if fileExists(path.Join(user.Dir(), "public", id, "index.md")) {
post, _ := user.GetPost(id)
posts = append(posts, &post)
posts = append(posts, post)
}
}
}
@ -125,10 +125,10 @@ func (user User) Posts() ([]*Post, error) {
return posts, nil
}
func (user User) GetPost(id string) (Post, error) {
func (user User) GetPost(id string) (*Post, error) {
// check if posts index.md exists
if !fileExists(path.Join(user.Dir(), "public", id, "index.md")) {
return Post{}, fmt.Errorf("post %s does not exist", id)
return &Post{}, fmt.Errorf("post %s does not exist", id)
}
post := Post{user: &user, id: id}
@ -137,10 +137,10 @@ func (user User) GetPost(id string) (Post, error) {
title := meta.Title
post.title = fmt.Sprint(title)
return post, nil
return &post, nil
}
func (user User) CreateNewPost(title string, draft bool) (Post, error) {
func (user User) CreateNewPost(title string, draft bool) (*Post, error) {
folder_name := toDirectoryName(title)
post_dir := path.Join(user.Dir(), "public", folder_name)
@ -168,7 +168,7 @@ func (user User) CreateNewPost(title string, draft bool) (Post, error) {
// write meta
meta_bytes, err := yaml.Marshal(meta)
if err != nil {
return Post{}, err
return &Post{}, err
}
initial_content += string(meta_bytes)
initial_content += "---\n"
@ -180,7 +180,7 @@ func (user User) CreateNewPost(title string, draft bool) (Post, error) {
os.WriteFile(post.ContentFile(), []byte(initial_content), 0644)
// create media dir
os.Mkdir(post.MediaDir(), 0755)
return post, nil
return &post, nil
}
func (user User) Template() (string, error) {

@ -59,7 +59,7 @@ func TestCreateNewPostMultipleCalls(t *testing.T) {
t.Error("Error reading directory")
}
if len(files) < 3 {
t.Error(fmt.Sprintf("Only %d posts created", len(files)))
t.Errorf("Only %d posts created", len(files))
}
}
@ -262,7 +262,7 @@ func TestPostsSortedByPublishingDateLatestFirst2(t *testing.T) {
content += "---\n"
content += "This is a test"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
posts = append(posts, &post)
posts = append(posts, post)
}
retPosts, _ := user.Posts()

Loading…
Cancel
Save