resolved warnings
This commit is contained in:
parent
a42da82516
commit
edf74aa330
|
@ -137,7 +137,7 @@ func userWebmentionHandler(repo *owl.Repository) func(http.ResponseWriter, *http
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if aliasPost != nil {
|
if aliasPost != nil {
|
||||||
foundPost = *aliasPost
|
foundPost = aliasPost
|
||||||
}
|
}
|
||||||
err = foundPost.AddIncomingWebmention(source[0])
|
err = foundPost.AddIncomingWebmention(source[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -197,7 +197,7 @@ func postHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Request,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
html, err := owl.RenderPost(&post)
|
html, err := owl.RenderPost(post)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("Error rendering post: ", err.Error())
|
println("Error rendering post: ", err.Error())
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|
|
@ -82,7 +82,7 @@ var webmentionCmd = &cobra.Command{
|
||||||
println("Error getting post: ", err.Error())
|
println("Error getting post: ", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
processPost(user, &post)
|
processPost(user, post)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package owl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,22 +23,6 @@ func fileExists(path string) bool {
|
||||||
return err == nil
|
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 {
|
func toDirectoryName(name string) string {
|
||||||
name = strings.ToLower(strings.ReplaceAll(name, " ", "-"))
|
name = strings.ToLower(strings.ReplaceAll(name, " ", "-"))
|
||||||
// remove all non-alphanumeric characters
|
// remove all non-alphanumeric characters
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
func TestCanRenderPost(t *testing.T) {
|
func TestCanRenderPost(t *testing.T) {
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
result, err := owl.RenderPost(&post)
|
result, err := owl.RenderPost(post)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error rendering post: " + err.Error())
|
t.Error("Error rendering post: " + err.Error())
|
||||||
|
@ -31,7 +31,7 @@ func TestRenderTwitterHandle(t *testing.T) {
|
||||||
config.TwitterHandle = "testhandle"
|
config.TwitterHandle = "testhandle"
|
||||||
user.SetConfig(config)
|
user.SetConfig(config)
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
result, err := owl.RenderPost(&post)
|
result, err := owl.RenderPost(post)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error rendering post: " + err.Error())
|
t.Error("Error rendering post: " + err.Error())
|
||||||
|
@ -50,7 +50,7 @@ func TestRenderGitHubHandle(t *testing.T) {
|
||||||
config.GitHubHandle = "testhandle"
|
config.GitHubHandle = "testhandle"
|
||||||
user.SetConfig(config)
|
user.SetConfig(config)
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
result, err := owl.RenderPost(&post)
|
result, err := owl.RenderPost(post)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error rendering post: " + err.Error())
|
t.Error("Error rendering post: " + err.Error())
|
||||||
|
@ -66,7 +66,7 @@ func TestRenderGitHubHandle(t *testing.T) {
|
||||||
func TestRenderPostHEntry(t *testing.T) {
|
func TestRenderPostHEntry(t *testing.T) {
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
result, _ := owl.RenderPost(&post)
|
result, _ := owl.RenderPost(post)
|
||||||
if !strings.Contains(result, "class=\"h-entry\"") {
|
if !strings.Contains(result, "class=\"h-entry\"") {
|
||||||
t.Error("h-entry container not rendered. Got: " + result)
|
t.Error("h-entry container not rendered. Got: " + result)
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func TestRenderPostHEntry(t *testing.T) {
|
||||||
func TestRendererUsesBaseTemplate(t *testing.T) {
|
func TestRendererUsesBaseTemplate(t *testing.T) {
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
result, err := owl.RenderPost(&post)
|
result, err := owl.RenderPost(post)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error rendering post: " + err.Error())
|
t.Error("Error rendering post: " + err.Error())
|
||||||
|
@ -171,7 +171,7 @@ func TestRendersHeaderTitle(t *testing.T) {
|
||||||
})
|
})
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
|
|
||||||
result, _ := owl.RenderPost(&post)
|
result, _ := owl.RenderPost(post)
|
||||||
if !strings.Contains(result, "Test Title") {
|
if !strings.Contains(result, "Test Title") {
|
||||||
t.Error("Header title not rendered. Got: " + result)
|
t.Error("Header title not rendered. Got: " + result)
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ func TestRenderPostIncludesRelToWebMention(t *testing.T) {
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
|
|
||||||
result, _ := owl.RenderPost(&post)
|
result, _ := owl.RenderPost(post)
|
||||||
if !strings.Contains(result, "rel=\"webmention\"") {
|
if !strings.Contains(result, "rel=\"webmention\"") {
|
||||||
t.Error("webmention rel not rendered. Got: " + result)
|
t.Error("webmention rel not rendered. Got: " + result)
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ func TestRenderPostAddsLinksToApprovedWebmention(t *testing.T) {
|
||||||
}
|
}
|
||||||
post.PersistIncomingWebmention(webmention)
|
post.PersistIncomingWebmention(webmention)
|
||||||
|
|
||||||
result, _ := owl.RenderPost(&post)
|
result, _ := owl.RenderPost(post)
|
||||||
if !strings.Contains(result, "http://example.com/source3") {
|
if !strings.Contains(result, "http://example.com/source3") {
|
||||||
t.Error("webmention not rendered. Got: " + result)
|
t.Error("webmention not rendered. Got: " + result)
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ func TestRenderPostAddsLinksToApprovedWebmention(t *testing.T) {
|
||||||
func TestRenderPostNotMentioningWebmentionsIfNoAvail(t *testing.T) {
|
func TestRenderPostNotMentioningWebmentionsIfNoAvail(t *testing.T) {
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
result, _ := owl.RenderPost(&post)
|
result, _ := owl.RenderPost(post)
|
||||||
|
|
||||||
if strings.Contains(result, "Webmention") {
|
if strings.Contains(result, "Webmention") {
|
||||||
t.Error("Webmention mentioned. Got: " + result)
|
t.Error("Webmention mentioned. Got: " + result)
|
||||||
|
@ -241,7 +241,7 @@ func TestRenderPostNotMentioningWebmentionsIfNoAvail(t *testing.T) {
|
||||||
func TestRenderIncludesFullUrl(t *testing.T) {
|
func TestRenderIncludesFullUrl(t *testing.T) {
|
||||||
user := getTestUser()
|
user := getTestUser()
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
result, _ := owl.RenderPost(&post)
|
result, _ := owl.RenderPost(post)
|
||||||
|
|
||||||
if !strings.Contains(result, "class=\"u-url\"") {
|
if !strings.Contains(result, "class=\"u-url\"") {
|
||||||
t.Error("u-url not rendered. Got: " + result)
|
t.Error("u-url not rendered. Got: " + result)
|
||||||
|
@ -272,7 +272,7 @@ func TestAuthorNameInPost(t *testing.T) {
|
||||||
})
|
})
|
||||||
post, _ := user.CreateNewPost("testpost", false)
|
post, _ := user.CreateNewPost("testpost", false)
|
||||||
|
|
||||||
result, _ := owl.RenderPost(&post)
|
result, _ := owl.RenderPost(post)
|
||||||
if !strings.Contains(result, "Test Author") {
|
if !strings.Contains(result, "Test Author") {
|
||||||
t.Error("Author Name not included. Got: " + result)
|
t.Error("Author Name not included. Got: " + result)
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ func TestRenderReplyWithoutText(t *testing.T) {
|
||||||
content += "Hi \n"
|
content += "Hi \n"
|
||||||
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
||||||
|
|
||||||
result, _ := owl.RenderPost(&post)
|
result, _ := owl.RenderPost(post)
|
||||||
if !strings.Contains(result, "https://example.com/post") {
|
if !strings.Contains(result, "https://example.com/post") {
|
||||||
t.Error("Reply url not rendered. Got: " + result)
|
t.Error("Reply url not rendered. Got: " + result)
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ func TestRenderReplyWithText(t *testing.T) {
|
||||||
content += "Hi \n"
|
content += "Hi \n"
|
||||||
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
||||||
|
|
||||||
result, _ := owl.RenderPost(&post)
|
result, _ := owl.RenderPost(post)
|
||||||
if !strings.Contains(result, "https://example.com/post") {
|
if !strings.Contains(result, "https://example.com/post") {
|
||||||
t.Error("Reply url not rendered. Got: " + result)
|
t.Error("Reply url not rendered. Got: " + result)
|
||||||
}
|
}
|
||||||
|
|
14
user.go
14
user.go
|
@ -86,7 +86,7 @@ func (user User) Posts() ([]*Post, error) {
|
||||||
if dirExists(path.Join(user.Dir(), "public", id)) {
|
if dirExists(path.Join(user.Dir(), "public", id)) {
|
||||||
if fileExists(path.Join(user.Dir(), "public", id, "index.md")) {
|
if fileExists(path.Join(user.Dir(), "public", id, "index.md")) {
|
||||||
post, _ := user.GetPost(id)
|
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
|
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
|
// check if posts index.md exists
|
||||||
if !fileExists(path.Join(user.Dir(), "public", id, "index.md")) {
|
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}
|
post := Post{user: &user, id: id}
|
||||||
|
@ -137,10 +137,10 @@ func (user User) GetPost(id string) (Post, error) {
|
||||||
title := meta.Title
|
title := meta.Title
|
||||||
post.title = fmt.Sprint(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)
|
folder_name := toDirectoryName(title)
|
||||||
post_dir := path.Join(user.Dir(), "public", folder_name)
|
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
|
// write meta
|
||||||
meta_bytes, err := yaml.Marshal(meta)
|
meta_bytes, err := yaml.Marshal(meta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Post{}, err
|
return &Post{}, err
|
||||||
}
|
}
|
||||||
initial_content += string(meta_bytes)
|
initial_content += string(meta_bytes)
|
||||||
initial_content += "---\n"
|
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)
|
os.WriteFile(post.ContentFile(), []byte(initial_content), 0644)
|
||||||
// create media dir
|
// create media dir
|
||||||
os.Mkdir(post.MediaDir(), 0755)
|
os.Mkdir(post.MediaDir(), 0755)
|
||||||
return post, nil
|
return &post, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user User) Template() (string, error) {
|
func (user User) Template() (string, error) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ func TestCreateNewPostMultipleCalls(t *testing.T) {
|
||||||
t.Error("Error reading directory")
|
t.Error("Error reading directory")
|
||||||
}
|
}
|
||||||
if len(files) < 3 {
|
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 += "---\n"
|
||||||
content += "This is a test"
|
content += "This is a test"
|
||||||
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
||||||
posts = append(posts, &post)
|
posts = append(posts, post)
|
||||||
}
|
}
|
||||||
|
|
||||||
retPosts, _ := user.Posts()
|
retPosts, _ := user.Posts()
|
||||||
|
|
Loading…
Reference in New Issue