diff --git a/cmd/owl/new_post.go b/cmd/owl/new_post.go index 583bbfc..4c22e21 100644 --- a/cmd/owl/new_post.go +++ b/cmd/owl/new_post.go @@ -40,11 +40,12 @@ var newPostCmd = &cobra.Command{ return } - _, err = user.CreateNewPost(postTitle) + post, err := user.CreateNewPost(postTitle, true) if err != nil { println("Error creating post: ", err.Error()) } else { println("Post created: ", postTitle) + println("Edit: ", post.ContentFile()) } }, } diff --git a/cmd/owl/web/aliases_test.go b/cmd/owl/web/aliases_test.go index dc9f4b1..7382df7 100644 --- a/cmd/owl/web/aliases_test.go +++ b/cmd/owl/web/aliases_test.go @@ -12,7 +12,7 @@ import ( func TestRedirectOnAliases(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) content := "---\n" content += "title: Test\n" @@ -50,7 +50,7 @@ func TestRedirectOnAliases(t *testing.T) { func TestNoRedirectOnNonExistingAliases(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) content := "---\n" content += "title: Test\n" @@ -81,8 +81,8 @@ func TestNoRedirectOnNonExistingAliases(t *testing.T) { func TestNoRedirectIfValidPostUrl(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") - post2, _ := user.CreateNewPost("post-2") + post, _ := user.CreateNewPost("post-1", false) + post2, _ := user.CreateNewPost("post-2", false) content := "---\n" content += "title: Test\n" @@ -112,7 +112,7 @@ func TestNoRedirectIfValidPostUrl(t *testing.T) { func TestRedirectIfInvalidPostUrl(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) content := "---\n" content += "title: Test\n" @@ -142,7 +142,7 @@ func TestRedirectIfInvalidPostUrl(t *testing.T) { func TestRedirectIfInvalidUserUrl(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) content := "---\n" content += "title: Test\n" @@ -172,7 +172,7 @@ func TestRedirectIfInvalidUserUrl(t *testing.T) { func TestRedirectIfInvalidMediaUrl(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) content := "---\n" content += "title: Test\n" @@ -202,7 +202,7 @@ func TestRedirectIfInvalidMediaUrl(t *testing.T) { func TestDeepAliasInSingleUserMode(t *testing.T) { repo := getTestRepo(owl.RepoConfig{SingleUser: "test-1"}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) content := "---\n" content += "title: Create tileable textures with GIMP\n" diff --git a/cmd/owl/web/multi_user_test.go b/cmd/owl/web/multi_user_test.go index 279798a..97c11ca 100644 --- a/cmd/owl/web/multi_user_test.go +++ b/cmd/owl/web/multi_user_test.go @@ -66,7 +66,7 @@ func TestMultiUserRepoIndexHandler(t *testing.T) { func TestMultiUserUserIndexHandler(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - user.CreateNewPost("post-1") + user.CreateNewPost("post-1", false) // Create Request and Response req, err := http.NewRequest("GET", user.UrlPath(), nil) @@ -93,7 +93,7 @@ func TestMultiUserUserIndexHandler(t *testing.T) { func TestMultiUserPostHandler(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) // Create Request and Response req, err := http.NewRequest("GET", post.UrlPath(), nil) @@ -114,7 +114,7 @@ func TestMultiUserPostHandler(t *testing.T) { func TestMultiUserPostMediaHandler(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) // Create test media file path := path.Join(post.MediaDir(), "data.txt") diff --git a/cmd/owl/web/post_test.go b/cmd/owl/web/post_test.go index 9c6e42d..1b41982 100644 --- a/cmd/owl/web/post_test.go +++ b/cmd/owl/web/post_test.go @@ -12,7 +12,7 @@ import ( func TestPostHandlerReturns404OnDrafts(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) content := "---\n" content += "title: test\n" diff --git a/cmd/owl/web/rss_test.go b/cmd/owl/web/rss_test.go index 904cdf7..b799acf 100644 --- a/cmd/owl/web/rss_test.go +++ b/cmd/owl/web/rss_test.go @@ -12,7 +12,7 @@ import ( func TestMultiUserUserRssIndexHandler(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - user.CreateNewPost("post-1") + user.CreateNewPost("post-1", false) // Create Request and Response req, err := http.NewRequest("GET", user.UrlPath()+"index.xml", nil) diff --git a/cmd/owl/web/single_user_test.go b/cmd/owl/web/single_user_test.go index 7ee722c..9734d59 100644 --- a/cmd/owl/web/single_user_test.go +++ b/cmd/owl/web/single_user_test.go @@ -19,7 +19,7 @@ func getSingleUserTestRepo() (owl.Repository, owl.User) { func TestSingleUserUserIndexHandler(t *testing.T) { repo, user := getSingleUserTestRepo() - user.CreateNewPost("post-1") + user.CreateNewPost("post-1", false) // Create Request and Response req, err := http.NewRequest("GET", user.UrlPath(), nil) @@ -45,7 +45,7 @@ func TestSingleUserUserIndexHandler(t *testing.T) { func TestSingleUserPostHandler(t *testing.T) { repo, user := getSingleUserTestRepo() - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) // Create Request and Response req, err := http.NewRequest("GET", post.UrlPath(), nil) @@ -65,7 +65,7 @@ func TestSingleUserPostHandler(t *testing.T) { func TestSingleUserPostMediaHandler(t *testing.T) { repo, user := getSingleUserTestRepo() - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) // Create test media file path := path.Join(post.MediaDir(), "data.txt") @@ -98,7 +98,7 @@ func TestSingleUserPostMediaHandler(t *testing.T) { func TestHasNoDraftsInList(t *testing.T) { repo, user := getSingleUserTestRepo() - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) content := "" content += "---\n" content += "title: Articles September 2019\n" diff --git a/cmd/owl/web/webmention_test.go b/cmd/owl/web/webmention_test.go index d85c2fb..04c68b8 100644 --- a/cmd/owl/web/webmention_test.go +++ b/cmd/owl/web/webmention_test.go @@ -45,7 +45,7 @@ func assertStatus(t *testing.T, rr *httptest.ResponseRecorder, expStatus int) { func TestWebmentionHandleAccepts(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) target := post.FullUrl() source := "https://example.com" @@ -63,7 +63,7 @@ func TestWebmentionWrittenToPost(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) target := post.FullUrl() source := "https://example.com" @@ -92,7 +92,7 @@ func TestWebmentionSourceValidation(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) target := post.FullUrl() source := "ftp://example.com" @@ -109,7 +109,7 @@ func TestWebmentionTargetValidation(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) target := "ftp://example.com" source := post.FullUrl() @@ -128,7 +128,7 @@ func TestWebmentionSameTargetAndSource(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) target := post.FullUrl() source := post.FullUrl() @@ -147,7 +147,7 @@ func TestWebmentionSameTargetAndSource(t *testing.T) { func TestValidationOfTarget(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) target := post.FullUrl() target = target[:len(target)-1] + "invalid" @@ -164,7 +164,7 @@ func TestValidationOfTarget(t *testing.T) { func TestAcceptWebmentionForAlias(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("test-1") - post, _ := user.CreateNewPost("post-1") + post, _ := user.CreateNewPost("post-1", false) content := "---\n" content += "title: Test\n" diff --git a/post_test.go b/post_test.go index e10f582..cfbb8f4 100644 --- a/post_test.go +++ b/post_test.go @@ -13,7 +13,7 @@ import ( func TestCanGetPostTitle(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result := post.Title() if result != "testpost" { t.Error("Wrong Title. Got: " + result) @@ -22,7 +22,7 @@ func TestCanGetPostTitle(t *testing.T) { func TestMediaDir(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result := post.MediaDir() if result != path.Join(post.Dir(), "media") { t.Error("Wrong MediaDir. Got: " + result) @@ -31,7 +31,7 @@ func TestMediaDir(t *testing.T) { func TestPostUrlPath(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) expected := "/user/" + user.Name() + "/posts/" + post.Id() + "/" if !(post.UrlPath() == expected) { t.Error("Wrong url path") @@ -42,7 +42,7 @@ func TestPostUrlPath(t *testing.T) { func TestPostFullUrl(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) expected := "http://localhost:8080/user/" + user.Name() + "/posts/" + post.Id() + "/" if !(post.FullUrl() == expected) { t.Error("Wrong url path") @@ -53,7 +53,7 @@ func TestPostFullUrl(t *testing.T) { func TestPostUrlMediaPath(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) expected := "/user/" + user.Name() + "/posts/" + post.Id() + "/media/data.png" if !(post.UrlMediaPath("data.png") == expected) { t.Error("Wrong url path") @@ -64,7 +64,7 @@ func TestPostUrlMediaPath(t *testing.T) { func TestPostUrlMediaPathWithSubDir(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) expected := "/user/" + user.Name() + "/posts/" + post.Id() + "/media/foo/data.png" if !(post.UrlMediaPath("foo/data.png") == expected) { t.Error("Wrong url path") @@ -75,7 +75,7 @@ func TestPostUrlMediaPathWithSubDir(t *testing.T) { func TestDraftInMetaData(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: test\n" content += "draft: true\n" @@ -93,7 +93,7 @@ func TestDraftInMetaData(t *testing.T) { func TestNoRawHTMLIfDisallowedByRepo(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: test\n" content += "draft: true\n" @@ -111,7 +111,7 @@ func TestNoRawHTMLIfDisallowedByRepo(t *testing.T) { func TestRawHTMLIfAllowedByRepo(t *testing.T) { repo := getTestRepo(owl.RepoConfig{AllowRawHtml: true}) user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: test\n" content += "draft: true\n" @@ -129,7 +129,7 @@ func TestRawHTMLIfAllowedByRepo(t *testing.T) { func TestLoadMeta(t *testing.T) { repo := getTestRepo(owl.RepoConfig{AllowRawHtml: true}) user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: test\n" @@ -172,7 +172,7 @@ func TestLoadMeta(t *testing.T) { func TestPersistIncomingWebmention(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) webmention := owl.WebmentionIn{ Source: "http://example.com/source", } @@ -195,7 +195,7 @@ func TestAddIncomingWebmentionCreatesFile(t *testing.T) { repo.HttpClient = &MockHttpClient{} repo.Parser = &MockHtmlParser{} user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) err := post.AddIncomingWebmention("https://example.com") if err != nil { @@ -213,7 +213,7 @@ func TestAddIncomingWebmentionNotOverwritingWebmention(t *testing.T) { repo.HttpClient = &MockHttpClient{} repo.Parser = &MockHtmlParser{} user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) post.PersistIncomingWebmention(owl.WebmentionIn{ Source: "https://example.com", @@ -237,7 +237,7 @@ func TestEnrichAddsTitle(t *testing.T) { repo.HttpClient = &MockHttpClient{} repo.Parser = &MockHtmlParser{} user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) post.AddIncomingWebmention("https://example.com") post.EnrichWebmention(owl.WebmentionIn{Source: "https://example.com"}) @@ -255,7 +255,7 @@ func TestEnrichAddsTitle(t *testing.T) { func TestApprovedIncomingWebmentions(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) webmention := owl.WebmentionIn{ Source: "http://example.com/source", ApprovalStatus: "approved", @@ -298,7 +298,7 @@ func TestApprovedIncomingWebmentions(t *testing.T) { func TestScanningForLinks(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: test\n" @@ -321,7 +321,7 @@ func TestScanningForLinks(t *testing.T) { func TestScanningForLinksDoesNotAddDuplicates(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: test\n" @@ -347,7 +347,7 @@ func TestScanningForLinksDoesNotAddDuplicates(t *testing.T) { func TestScanningForLinksDoesAddReplyUrl(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: test\n" @@ -374,7 +374,7 @@ func TestCanSendWebmention(t *testing.T) { repo.HttpClient = &MockHttpClient{} repo.Parser = &MockHtmlParser{} user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) webmention := owl.WebmentionOut{ Target: "http://example.com", @@ -405,7 +405,7 @@ func TestSendWebmentionOnlyScansOncePerWeek(t *testing.T) { repo.HttpClient = &MockHttpClient{} repo.Parser = &MockHtmlParser{} user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) webmention := owl.WebmentionOut{ Target: "http://example.com", @@ -437,7 +437,7 @@ func TestSendingMultipleWebmentions(t *testing.T) { repo.HttpClient = &MockHttpClient{} repo.Parser = &MockHtmlParser{} user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) wg := sync.WaitGroup{} wg.Add(20) @@ -466,7 +466,7 @@ func TestReceivingMultipleWebmentions(t *testing.T) { repo.HttpClient = &MockHttpClient{} repo.Parser = &MockHtmlParser{} user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) wg := sync.WaitGroup{} wg.Add(20) @@ -493,7 +493,7 @@ func TestSendingAndReceivingMultipleWebmentions(t *testing.T) { repo.HttpClient = &MockHttpClient{} repo.Parser = &MockHtmlParser{} user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) wg := sync.WaitGroup{} wg.Add(40) @@ -538,7 +538,7 @@ func TestComplexParallelWebmentions(t *testing.T) { }, } user, _ := repo.CreateUser("testuser") - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) wg := sync.WaitGroup{} wg.Add(60) @@ -588,7 +588,7 @@ func TestComplexParallelWebmentions(t *testing.T) { // }, // } // user, _ := repo.CreateUser("testuser") -// post, _ := user.CreateNewPost("testpost") +// post, _ := user.CreateNewPost("testpost", false) // wg := sync.WaitGroup{} // wg.Add(40) diff --git a/renderer_test.go b/renderer_test.go index 10714d3..20b5e83 100644 --- a/renderer_test.go +++ b/renderer_test.go @@ -11,7 +11,7 @@ import ( func TestCanRenderPost(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, err := owl.RenderPost(&post) if err != nil { @@ -30,7 +30,7 @@ func TestRenderTwitterHandle(t *testing.T) { config, _ := user.Config() config.TwitterHandle = "testhandle" user.SetConfig(config) - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, err := owl.RenderPost(&post) if err != nil { @@ -49,7 +49,7 @@ func TestRenderGitHubHandle(t *testing.T) { config, _ := user.Config() config.GitHubHandle = "testhandle" user.SetConfig(config) - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, err := owl.RenderPost(&post) if err != nil { @@ -65,7 +65,7 @@ func TestRenderGitHubHandle(t *testing.T) { func TestRenderPostHEntry(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, _ := owl.RenderPost(&post) if !strings.Contains(result, "class=\"h-entry\"") { t.Error("h-entry container not rendered. Got: " + result) @@ -81,7 +81,7 @@ func TestRenderPostHEntry(t *testing.T) { func TestRendererUsesBaseTemplate(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, err := owl.RenderPost(&post) if err != nil { @@ -96,8 +96,8 @@ func TestRendererUsesBaseTemplate(t *testing.T) { func TestCanRenderIndexPage(t *testing.T) { user := getTestUser() - user.CreateNewPost("testpost1") - user.CreateNewPost("testpost2") + user.CreateNewPost("testpost1", false) + user.CreateNewPost("testpost2", false) result, _ := owl.RenderIndexPage(user) if !strings.Contains(result, "testpost1") { t.Error("Post title not rendered. Got: " + result) @@ -109,7 +109,7 @@ func TestCanRenderIndexPage(t *testing.T) { func TestIndexPageContainsHFeedContainer(t *testing.T) { user := getTestUser() - user.CreateNewPost("testpost1") + user.CreateNewPost("testpost1", false) result, _ := owl.RenderIndexPage(user) if !strings.Contains(result, "
") { @@ -119,7 +119,7 @@ func TestIndexPageContainsHFeedContainer(t *testing.T) { func TestIndexPageContainsHEntryAndUUrl(t *testing.T) { user := getTestUser() - user.CreateNewPost("testpost1") + user.CreateNewPost("testpost1", false) result, _ := owl.RenderIndexPage(user) if !strings.Contains(result, "class=\"h-entry\"") { @@ -133,8 +133,8 @@ func TestIndexPageContainsHEntryAndUUrl(t *testing.T) { func TestRenderIndexPageWithBrokenBaseTemplate(t *testing.T) { user := getTestUser() - user.CreateNewPost("testpost1") - user.CreateNewPost("testpost2") + user.CreateNewPost("testpost1", false) + user.CreateNewPost("testpost2", false) os.WriteFile(path.Join(user.Dir(), "meta/base.html"), []byte("{{content}}"), 0644) @@ -169,7 +169,7 @@ func TestRendersHeaderTitle(t *testing.T) { SubTitle: "Test SubTitle", HeaderColor: "#ff1337", }) - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, _ := owl.RenderPost(&post) if !strings.Contains(result, "Test Title") { @@ -185,7 +185,7 @@ func TestRendersHeaderTitle(t *testing.T) { func TestRenderPostIncludesRelToWebMention(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, _ := owl.RenderPost(&post) if !strings.Contains(result, "rel=\"webmention\"") { @@ -199,7 +199,7 @@ func TestRenderPostIncludesRelToWebMention(t *testing.T) { func TestRenderPostAddsLinksToApprovedWebmention(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) webmention := owl.WebmentionIn{ Source: "http://example.com/source3", Title: "Test Title", @@ -229,7 +229,7 @@ func TestRenderPostAddsLinksToApprovedWebmention(t *testing.T) { func TestRenderPostNotMentioningWebmentionsIfNoAvail(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, _ := owl.RenderPost(&post) if strings.Contains(result, "Webmention") { @@ -240,7 +240,7 @@ func TestRenderPostNotMentioningWebmentionsIfNoAvail(t *testing.T) { func TestRenderIncludesFullUrl(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, _ := owl.RenderPost(&post) if !strings.Contains(result, "class=\"u-url\"") { @@ -270,7 +270,7 @@ func TestAuthorNameInPost(t *testing.T) { HeaderColor: "#ff1337", AuthorName: "Test Author", }) - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) result, _ := owl.RenderPost(&post) if !strings.Contains(result, "Test Author") { @@ -281,7 +281,7 @@ func TestAuthorNameInPost(t *testing.T) { func TestRenderReplyWithoutText(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: test\n" @@ -302,7 +302,7 @@ func TestRenderReplyWithoutText(t *testing.T) { func TestRenderReplyWithText(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: test\n" diff --git a/repository_test.go b/repository_test.go index 01ca4e9..e50632c 100644 --- a/repository_test.go +++ b/repository_test.go @@ -241,7 +241,7 @@ func TestSingleUserRepoUserUrlPathIsSimple(t *testing.T) { func TestCanGetMapWithAllPostAliases(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) - post, _ := user.CreateNewPost("test-1") + post, _ := user.CreateNewPost("test-1", false) content := "---\n" content += "title: Test\n" @@ -278,8 +278,8 @@ func TestCanGetMapWithAllPostAliases(t *testing.T) { func TestAliasesHaveCorrectPost(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) - post1, _ := user.CreateNewPost("test-1") - post2, _ := user.CreateNewPost("test-2") + post1, _ := user.CreateNewPost("test-1", false) + post2, _ := user.CreateNewPost("test-2", false) content := "---\n" content += "title: Test\n" diff --git a/rss_test.go b/rss_test.go index fa86cd2..c049753 100644 --- a/rss_test.go +++ b/rss_test.go @@ -51,7 +51,7 @@ func TestRenderRSSFeedUserData(t *testing.T) { func TestRenderRSSFeedPostData(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: Test Post\n" @@ -78,7 +78,7 @@ func TestRenderRSSFeedPostData(t *testing.T) { func TestRenderRSSFeedPostDataWithoutDate(t *testing.T) { user := getTestUser() - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: Test Post\n" diff --git a/user.go b/user.go index 39497a8..a125832 100644 --- a/user.go +++ b/user.go @@ -141,7 +141,7 @@ func (user User) GetPost(id string) (Post, error) { return post, nil } -func (user User) CreateNewPost(title string) (Post, error) { +func (user User) CreateNewPost(title string, draft bool) (Post, error) { timestamp := time.Now().UTC().Unix() folder_name := fmt.Sprintf("%d-%s", timestamp, title) post_dir := path.Join(user.Dir(), "public", folder_name) @@ -162,7 +162,7 @@ func (user User) CreateNewPost(title string) (Post, error) { Title: title, Date: time.Now(), Aliases: []string{}, - Draft: false, + Draft: draft, } initial_content := "" diff --git a/user_test.go b/user_test.go index 0906f0b..6b4e1a0 100644 --- a/user_test.go +++ b/user_test.go @@ -14,7 +14,7 @@ func TestCreateNewPostCreatesEntryInPublic(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) // Create a new post - user.CreateNewPost("testpost") + user.CreateNewPost("testpost", false) files, err := ioutil.ReadDir(path.Join(user.Dir(), "public")) if err != nil { t.Error("Error reading directory") @@ -29,7 +29,7 @@ func TestCreateNewPostCreatesMediaDir(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) // Create a new post - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) if _, err := os.Stat(post.MediaDir()); os.IsNotExist(err) { t.Error("Media directory not created") } @@ -38,7 +38,7 @@ func TestCreateNewPostCreatesMediaDir(t *testing.T) { func TestCreateNewPostAddsDateToMetaBlock(t *testing.T) { user := getTestUser() // Create a new post - user.CreateNewPost("testpost") + user.CreateNewPost("testpost", false) posts, _ := user.Posts() post, _ := user.GetPost(posts[0].Id()) meta := post.Meta() @@ -52,9 +52,9 @@ func TestCreateNewPostMultipleCalls(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) // Create a new post - user.CreateNewPost("testpost") - user.CreateNewPost("testpost") - user.CreateNewPost("testpost") + user.CreateNewPost("testpost", false) + user.CreateNewPost("testpost", false) + user.CreateNewPost("testpost", false) files, err := ioutil.ReadDir(path.Join(user.Dir(), "public")) if err != nil { t.Error("Error reading directory") @@ -69,9 +69,9 @@ func TestCanListUserPosts(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) // Create a new post - user.CreateNewPost("testpost") - user.CreateNewPost("testpost") - user.CreateNewPost("testpost") + user.CreateNewPost("testpost", false) + user.CreateNewPost("testpost", false) + user.CreateNewPost("testpost", false) posts, err := user.Posts() if err != nil { t.Error("Error reading posts") @@ -86,7 +86,7 @@ func TestCannotListUserPostsInSubdirectories(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) // Create a new post - user.CreateNewPost("testpost") + user.CreateNewPost("testpost", false) os.Mkdir(path.Join(user.PostDir(), "foo"), 0755) os.Mkdir(path.Join(user.PostDir(), "foo/bar"), 0755) content := "" @@ -123,7 +123,7 @@ func TestCannotListUserPostsWithoutIndexMd(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) // Create a new post - user.CreateNewPost("testpost") + user.CreateNewPost("testpost", false) os.Mkdir(path.Join(user.PostDir(), "foo"), 0755) os.Mkdir(path.Join(user.PostDir(), "foo/bar"), 0755) content := "" @@ -152,7 +152,7 @@ func TestListUserPostsDoesNotIncludeDrafts(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) // Create a new post - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "" content += "---\n" content += "title: test\n" @@ -173,7 +173,7 @@ func TestListUsersDraftsExcludedRealWorld(t *testing.T) { repo := getTestRepo(owl.RepoConfig{}) user, _ := repo.CreateUser(randomUserName()) // Create a new post - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "" content += "---\n" content += "title: Articles September 2019\n" @@ -199,7 +199,7 @@ func TestListUsersDraftsExcludedRealWorld(t *testing.T) { func TestCanLoadPost(t *testing.T) { user := getTestUser() // Create a new post - user.CreateNewPost("testpost") + user.CreateNewPost("testpost", false) posts, _ := user.Posts() post, _ := user.GetPost(posts[0].Id()) @@ -225,8 +225,8 @@ func TestUserFullUrl(t *testing.T) { func TestPostsSortedByPublishingDateLatestFirst(t *testing.T) { user := getTestUser() // Create a new post - post1, _ := user.CreateNewPost("testpost") - post2, _ := user.CreateNewPost("testpost2") + post1, _ := user.CreateNewPost("testpost", false) + post2, _ := user.CreateNewPost("testpost2", false) content := "---\n" content += "title: Test Post\n" @@ -256,7 +256,7 @@ func TestPostsSortedByPublishingDateLatestFirst2(t *testing.T) { // Create a new post posts := []*owl.Post{} for i := 59; i >= 0; i-- { - post, _ := user.CreateNewPost("testpost") + post, _ := user.CreateNewPost("testpost", false) content := "---\n" content += "title: Test Post\n" content += fmt.Sprintf("date: Wed, 17 Aug 2022 10:%02d:02 +0000\n", i) @@ -277,8 +277,8 @@ func TestPostsSortedByPublishingDateLatestFirst2(t *testing.T) { func TestPostsSortedByPublishingDateBrokenAtBottom(t *testing.T) { user := getTestUser() // Create a new post - post1, _ := user.CreateNewPost("testpost") - post2, _ := user.CreateNewPost("testpost2") + post1, _ := user.CreateNewPost("testpost", false) + post2, _ := user.CreateNewPost("testpost2", false) content := "---\n" content += "title: Test Post\n"