From 5001861b7e1d85727f5ea3f9376f975cab8429fc Mon Sep 17 00:00:00 2001 From: Corey Gillen Date: Mon, 16 May 2022 11:10:17 -0700 Subject: [PATCH 1/6] Add option to set admin specific scheme/host/port --- lib/jekyll-admin/urlable.rb | 10 +++++++--- spec/jekyll-admin/urlable_spec.rb | 33 +++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/jekyll-admin/urlable.rb b/lib/jekyll-admin/urlable.rb index b311dde82..16c4e6e8d 100644 --- a/lib/jekyll-admin/urlable.rb +++ b/lib/jekyll-admin/urlable.rb @@ -61,15 +61,19 @@ def path_with_base(base, path) end def scheme - JekyllAdmin.site.config["scheme"] || "http" + JekyllAdmin.site.config["jekyll_admin"]["scheme"] || + JekyllAdmin.site.config["scheme"] || + "http" end def host - JekyllAdmin.site.config["host"].sub("127.0.0.1", "localhost") + JekyllAdmin.site.config["jekyll_admin"]["host"] || + JekyllAdmin.site.config["host"].sub("127.0.0.1", "localhost") end def port - JekyllAdmin.site.config["port"] + JekyllAdmin.site.config["jekyll_admin"]["port"] || + JekyllAdmin.site.config["port"] end end end diff --git a/spec/jekyll-admin/urlable_spec.rb b/spec/jekyll-admin/urlable_spec.rb index 83074a68b..8939d5069 100644 --- a/spec/jekyll-admin/urlable_spec.rb +++ b/spec/jekyll-admin/urlable_spec.rb @@ -8,16 +8,33 @@ let(:prefix) { "_api" } let(:url_base) { "#{scheme}://#{host}:#{port}" } - it "knows the host" do - expect(subject.send(:host)).to eql("localhost") - end + context do + it "knows the jekyll_admin host" do + JekyllAdmin.site.config["jekyll_admin"]["host"] = "foo" + expect(subject.send(:host)).to eql("foo") + JekyllAdmin.site.config["jekyll_admin"]["host"] = nil + end + it "knows the base host" do + expect(subject.send(:host)).to eql("localhost") + end - it "knows the port" do - expect(subject.send(:port)).to eql("4000") - end + it "knows the jekyll_admin port" do + JekyllAdmin.site.config["jekyll_admin"]["port"] = 1000 + expect(subject.send(:port)).to eql(1000) + JekyllAdmin.site.config["jekyll_admin"]["port"] = nil + end + it "knows the port" do + expect(subject.send(:port)).to eql("4000") + end - it "knows the scheme" do - expect(subject.send(:scheme)).to eql("http") + it "knows the jekyll_admin scheme" do + JekyllAdmin.site.config["jekyll_admin"]["scheme"] = "baz" + expect(subject.send(:scheme)).to eql("baz") + JekyllAdmin.site.config["jekyll_admin"]["scheme"] = nil + end + it "knows the scheme" do + expect(subject.send(:scheme)).to eql("http") + end end context "pages" do From f61bc1234be9e8e64089c0303c1b7eb16020cc4b Mon Sep 17 00:00:00 2001 From: Corey Gillen Date: Mon, 16 May 2022 12:17:02 -0700 Subject: [PATCH 2/6] Replace jekyll_admin arrary access with dig --- lib/jekyll-admin/urlable.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/jekyll-admin/urlable.rb b/lib/jekyll-admin/urlable.rb index 16c4e6e8d..a248f170f 100644 --- a/lib/jekyll-admin/urlable.rb +++ b/lib/jekyll-admin/urlable.rb @@ -61,18 +61,18 @@ def path_with_base(base, path) end def scheme - JekyllAdmin.site.config["jekyll_admin"]["scheme"] || + JekyllAdmin.site.config.dig("jekyll_admin", "scheme") || JekyllAdmin.site.config["scheme"] || "http" end def host - JekyllAdmin.site.config["jekyll_admin"]["host"] || + JekyllAdmin.site.config.dig("jekyll_admin", "host") || JekyllAdmin.site.config["host"].sub("127.0.0.1", "localhost") end def port - JekyllAdmin.site.config["jekyll_admin"]["port"] || + JekyllAdmin.site.config.dig("jekyll_admin", "port") || JekyllAdmin.site.config["port"] end end From e7690b1dff0de42d20dabf9de6c0ab7304e4f25a Mon Sep 17 00:00:00 2001 From: Corey Gillen Date: Mon, 16 May 2022 12:47:52 -0700 Subject: [PATCH 3/6] Update config docs --- docs/configs.md | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/configs.md b/docs/configs.md index db636c3e1..91711197e 100644 --- a/docs/configs.md +++ b/docs/configs.md @@ -1,7 +1,7 @@ --- title: Configuration Options permalink: /configs/ ---- +--- Jekyll Admin related options can be specified in `_config.yml` under a key called `jekyll_admin`. @@ -10,7 +10,7 @@ under a key called `jekyll_admin`. #### `hidden_links` -For hiding unwanted links on the sidebar. +For hiding unwanted links on the sidebar. The following keys under `hidden_links` can be used in order to hide default links: @@ -35,3 +35,39 @@ Valid values for `homepage`: `pages` (default), `posts`, ``, jekyll_admin: homepage: "posts" ``` + +#### `host` + +For overriding `host` from the Jekyll installation. + +This can be useful if Jekyll Admin is behind a reverse proxy. + +```yaml +host: "mydomain.com" +jekyll_admin: + host: "admin.mydomain.com" +``` + +#### `port` + +For overriding `port` from the Jekyll installation. + +This can be useful if Jekyll Admin is behind a reverse proxy. + +```yaml +port: 4000 +jekyll_admin: + port: 4001 +``` + +#### `scheme` + +For overriding `scheme` from the Jekyll installation. + +This can be useful if Jekyll Admin is behind a reverse proxy. + +```yaml +scheme: "https" +jekyll_admin: + scheme: "http" +``` From adc8faa03b5640e1af55f88a9d6c3463e11817f0 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 31 Oct 2022 12:35:39 +0530 Subject: [PATCH 4/6] Undo unrelated changes to whitespace --- docs/configs.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configs.md b/docs/configs.md index 91711197e..9caa98aee 100644 --- a/docs/configs.md +++ b/docs/configs.md @@ -1,7 +1,7 @@ --- title: Configuration Options permalink: /configs/ ---- +--- Jekyll Admin related options can be specified in `_config.yml` under a key called `jekyll_admin`. @@ -10,7 +10,7 @@ under a key called `jekyll_admin`. #### `hidden_links` -For hiding unwanted links on the sidebar. +For hiding unwanted links on the sidebar. The following keys under `hidden_links` can be used in order to hide default links: From bcc4c849a01b898e6a574fc1dbce96acc54d88c2 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 31 Oct 2022 12:37:45 +0530 Subject: [PATCH 5/6] Add newlines between test expectations --- spec/jekyll-admin/urlable_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/jekyll-admin/urlable_spec.rb b/spec/jekyll-admin/urlable_spec.rb index 8939d5069..d6405768d 100644 --- a/spec/jekyll-admin/urlable_spec.rb +++ b/spec/jekyll-admin/urlable_spec.rb @@ -14,6 +14,7 @@ expect(subject.send(:host)).to eql("foo") JekyllAdmin.site.config["jekyll_admin"]["host"] = nil end + it "knows the base host" do expect(subject.send(:host)).to eql("localhost") end @@ -23,6 +24,7 @@ expect(subject.send(:port)).to eql(1000) JekyllAdmin.site.config["jekyll_admin"]["port"] = nil end + it "knows the port" do expect(subject.send(:port)).to eql("4000") end @@ -32,6 +34,7 @@ expect(subject.send(:scheme)).to eql("baz") JekyllAdmin.site.config["jekyll_admin"]["scheme"] = nil end + it "knows the scheme" do expect(subject.send(:scheme)).to eql("http") end From 548a0827035ea1a31f1b25af4211a59faf37fd13 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 31 Oct 2022 12:41:07 +0530 Subject: [PATCH 6/6] Add descriptive label for test context --- spec/jekyll-admin/urlable_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/jekyll-admin/urlable_spec.rb b/spec/jekyll-admin/urlable_spec.rb index d6405768d..e68f41721 100644 --- a/spec/jekyll-admin/urlable_spec.rb +++ b/spec/jekyll-admin/urlable_spec.rb @@ -8,7 +8,7 @@ let(:prefix) { "_api" } let(:url_base) { "#{scheme}://#{host}:#{port}" } - context do + context "with custom configuration" do it "knows the jekyll_admin host" do JekyllAdmin.site.config["jekyll_admin"]["host"] = "foo" expect(subject.send(:host)).to eql("foo")