diff --git a/lib/micropub/github.rb b/lib/micropub/github.rb index b490155..8510873 100644 --- a/lib/micropub/github.rb +++ b/lib/micropub/github.rb @@ -6,7 +6,8 @@ module Micropub USER = ENV["GITHUB_USER"] REPO = ENV["GITHUB_REPO"] - CONTENT_PATH = "/content/blog" + BLOG_PATH = "/content/blog" + PHOTOS_PATH = "/content/photos" def initialize @github = ::Github.new(oauth_token: TOKEN) @@ -30,7 +31,13 @@ module Micropub def posts @_posts ||= - github.repos.contents.get(USER, REPO, CONTENT_PATH). + github.repos.contents.get(USER, REPO, BLOG_PATH). + map(&:name) + end + + def photos + @_photos ||= + github.repos.contents.get(USER, REPO, PHOTOS_PATH). map(&:name) end diff --git a/lib/micropub/post.rb b/lib/micropub/post.rb index 14bd781..742f2f7 100644 --- a/lib/micropub/post.rb +++ b/lib/micropub/post.rb @@ -6,6 +6,8 @@ module Micropub class Post attr_accessor :params + BASE_PATH="/blog" + def initialize(params = {}) @params = params end @@ -23,7 +25,7 @@ module Micropub end def path - "/blog/#{published.strftime("%Y/%m/%d")}/#{id}" + "#{BASE_PATH}/#{published.strftime("%Y/%m/%d")}/#{id}" end def truncated_content diff --git a/lib/micropub/webserver.rb b/lib/micropub/webserver.rb index 9cffaa3..e838205 100644 --- a/lib/micropub/webserver.rb +++ b/lib/micropub/webserver.rb @@ -21,7 +21,8 @@ module Micropub get "/micropub/main" do json data: { - posts: github.posts + posts: github.posts, + photos: github.photos, } end diff --git a/test/lib/micropub/github_test.rb b/test/lib/micropub/github_test.rb index d3ec38b..d63e82c 100644 --- a/test/lib/micropub/github_test.rb +++ b/test/lib/micropub/github_test.rb @@ -23,7 +23,7 @@ describe Micropub::Github do Hello, World! CONTENT - :branch => "master", + :branch => "main", }).returns(true) repos = mock("repos") repos.stubs(:contents).returns(contents) diff --git a/test/requests/hello_world_test.rb b/test/requests/hello_world_test.rb index cd2293e..85a8177 100644 --- a/test/requests/hello_world_test.rb +++ b/test/requests/hello_world_test.rb @@ -9,7 +9,6 @@ class HelloWorldTest < MiniTest::Test def test_hello_world get '/' - assert last_response.ok? - assert_equal "Hello, World!", last_response.body + assert last_response.redirect? end end