jekyll-admin 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +93 -94
  4. data/lib/jekyll-admin.rb +47 -47
  5. data/lib/jekyll-admin/apiable.rb +224 -224
  6. data/lib/jekyll-admin/data_file.rb +106 -106
  7. data/lib/jekyll-admin/directory.rb +72 -72
  8. data/lib/jekyll-admin/file_helper.rb +91 -91
  9. data/lib/jekyll-admin/path_helper.rb +87 -87
  10. data/lib/jekyll-admin/public/asset-manifest.json +17 -17
  11. data/lib/jekyll-admin/public/index.html +1 -1
  12. data/lib/jekyll-admin/public/{precache-manifest.5e08ed7edb8d446719b76ae6ead9e3fe.js → precache-manifest.64226b0470ae7a98d28d6c8a80943541.js} +17 -17
  13. data/lib/jekyll-admin/public/service-worker.js +1 -1
  14. data/lib/jekyll-admin/public/static/css/2.9311179f.chunk.css +2 -0
  15. data/lib/jekyll-admin/public/static/css/2.9311179f.chunk.css.map +1 -0
  16. data/lib/jekyll-admin/public/static/css/main.51bccafc.chunk.css +5 -0
  17. data/lib/jekyll-admin/public/static/css/main.51bccafc.chunk.css.map +1 -0
  18. data/lib/jekyll-admin/public/static/js/2.c4e847cc.chunk.js +3 -0
  19. data/lib/jekyll-admin/public/static/js/{2.a50fa19f.chunk.js.LICENSE.txt → 2.c4e847cc.chunk.js.LICENSE.txt} +3 -1
  20. data/lib/jekyll-admin/public/static/js/2.c4e847cc.chunk.js.map +1 -0
  21. data/lib/jekyll-admin/public/static/js/main.2ce220f0.chunk.js +2 -0
  22. data/lib/jekyll-admin/public/static/js/main.2ce220f0.chunk.js.map +1 -0
  23. data/lib/jekyll-admin/public/static/js/{runtime-main.95f94e60.js → runtime-main.e35fac22.js} +1 -1
  24. data/lib/jekyll-admin/public/static/js/{runtime-main.95f94e60.js.map → runtime-main.e35fac22.js.map} +1 -1
  25. data/lib/jekyll-admin/public/static/media/{fontawesome-webfont.24c601e7.svg → fontawesome-webfont.d7c63908.svg} +684 -684
  26. data/lib/jekyll-admin/server.rb +108 -108
  27. data/lib/jekyll-admin/server/collections.rb +89 -89
  28. data/lib/jekyll-admin/server/configuration.rb +60 -60
  29. data/lib/jekyll-admin/server/data.rb +84 -84
  30. data/lib/jekyll-admin/server/drafts.rb +114 -114
  31. data/lib/jekyll-admin/server/pages.rb +109 -109
  32. data/lib/jekyll-admin/server/site_meta.rb +25 -25
  33. data/lib/jekyll-admin/server/static_files.rb +83 -83
  34. data/lib/jekyll-admin/static_server.rb +26 -26
  35. data/lib/jekyll-admin/urlable.rb +75 -75
  36. data/lib/jekyll-admin/version.rb +5 -5
  37. data/lib/jekyll/commands/serve.rb +30 -30
  38. metadata +19 -19
  39. data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css +0 -2
  40. data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css.map +0 -1
  41. data/lib/jekyll-admin/public/static/css/main.7e0a6705.chunk.css +0 -5
  42. data/lib/jekyll-admin/public/static/css/main.7e0a6705.chunk.css.map +0 -1
  43. data/lib/jekyll-admin/public/static/js/2.a50fa19f.chunk.js +0 -3
  44. data/lib/jekyll-admin/public/static/js/2.a50fa19f.chunk.js.map +0 -1
  45. data/lib/jekyll-admin/public/static/js/main.f3346e4e.chunk.js +0 -2
  46. data/lib/jekyll-admin/public/static/js/main.f3346e4e.chunk.js.map +0 -1
@@ -1,25 +1,25 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class Server < Sinatra::Base
5
- # Jekyll::Site instance method names that return a Hash.
6
- META_KEYS = [:categories, :layouts, :tags].freeze
7
- private_constant :META_KEYS
8
-
9
- namespace "/site_meta" do
10
- get "/?" do
11
- json site_meta
12
- end
13
-
14
- private
15
-
16
- # Stash a Hash generated with pre-determined keys.
17
- def site_meta
18
- @site_meta ||= META_KEYS.zip(META_KEYS.map { |k| site.send(k).keys }).to_h
19
- end
20
-
21
- # Reset memoization of `#site_meta` when the site regenerates
22
- Jekyll::Hooks.register(:site, :after_reset) { @site_meta = nil }
23
- end
24
- end
25
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ # Jekyll::Site instance method names that return a Hash.
6
+ META_KEYS = [:categories, :layouts, :tags].freeze
7
+ private_constant :META_KEYS
8
+
9
+ namespace "/site_meta" do
10
+ get "/?" do
11
+ json site_meta
12
+ end
13
+
14
+ private
15
+
16
+ # Stash a Hash generated with pre-determined keys.
17
+ def site_meta
18
+ @site_meta ||= META_KEYS.zip(META_KEYS.map { |k| site.send(k).keys }).to_h
19
+ end
20
+
21
+ # Reset memoization of `#site_meta` when the site regenerates
22
+ Jekyll::Hooks.register(:site, :after_reset) { @site_meta = nil }
23
+ end
24
+ end
25
+ end
@@ -1,83 +1,83 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class Server < Sinatra::Base
5
- namespace "/static_files" do
6
- # End-point to retrieve all static-files in site
7
- get "/index" do
8
- json site.static_files.map(&:to_api)
9
- end
10
-
11
- # End-point to retrieve individual directories that contain static-files
12
- get "/?*" do
13
- render_404 unless File.exist?(path)
14
-
15
- if requested_file
16
- json requested_file.to_api(:include_content => true)
17
- else
18
- json entries.map(&:to_api)
19
- end
20
- end
21
-
22
- put "/*" do
23
- if renamed?
24
- ensure_requested_file
25
- delete_file_without_process path
26
- end
27
-
28
- write_file(write_path, static_file_body)
29
- json written_file.to_api(:include_content => true)
30
- end
31
-
32
- delete "/*" do
33
- ensure_requested_file
34
- delete_file path
35
- content_type :json
36
- status 200
37
- halt
38
- end
39
-
40
- private
41
-
42
- # returns relative path of root level directories that contain static files
43
- def dirs_at_root
44
- static_files.map do |file|
45
- File.dirname(file.path.sub("#{site.source}/", "")).split("/")[0]
46
- end.uniq
47
- end
48
-
49
- def directory_files
50
- static_files.find_all do |file|
51
- sanitized_path(File.dirname(file.path)) == directory_path
52
- end
53
- end
54
-
55
- def entries
56
- splat = params["splat"].first
57
- args = {
58
- :base => site.source,
59
- :content_type => "static_files",
60
- :splat => splat,
61
- }
62
- # get all directories inside the requested directory
63
- directory = JekyllAdmin::Directory.new(directory_path, args)
64
- directories = directory.directories
65
-
66
- # exclude root level directories which do not have static files
67
- directories = directories.select { |d| dirs_at_root.include? d.name.to_s } if splat.empty?
68
- directories.concat(directory_files)
69
- end
70
-
71
- def static_file_body
72
- raw_content = request_payload["raw_content"]
73
- return raw_content if raw_content.is_a?(String) && raw_content != ""
74
-
75
- Base64.decode64 request_payload["encoded_content"].to_s
76
- end
77
-
78
- def static_files
79
- site.static_files.select { |f| f.path.start_with? site.source }
80
- end
81
- end
82
- end
83
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ namespace "/static_files" do
6
+ # End-point to retrieve all static-files in site
7
+ get "/index" do
8
+ json site.static_files.map(&:to_api)
9
+ end
10
+
11
+ # End-point to retrieve individual directories that contain static-files
12
+ get "/?*" do
13
+ render_404 unless File.exist?(path)
14
+
15
+ if requested_file
16
+ json requested_file.to_api(:include_content => true)
17
+ else
18
+ json entries.map(&:to_api)
19
+ end
20
+ end
21
+
22
+ put "/*" do
23
+ if renamed?
24
+ ensure_requested_file
25
+ delete_file_without_process path
26
+ end
27
+
28
+ write_file(write_path, static_file_body)
29
+ json written_file.to_api(:include_content => true)
30
+ end
31
+
32
+ delete "/*" do
33
+ ensure_requested_file
34
+ delete_file path
35
+ content_type :json
36
+ status 200
37
+ halt
38
+ end
39
+
40
+ private
41
+
42
+ # returns relative path of root level directories that contain static files
43
+ def dirs_at_root
44
+ static_files.map do |file|
45
+ File.dirname(file.path.sub("#{site.source}/", "")).split("/")[0]
46
+ end.uniq
47
+ end
48
+
49
+ def directory_files
50
+ static_files.find_all do |file|
51
+ sanitized_path(File.dirname(file.path)) == directory_path
52
+ end
53
+ end
54
+
55
+ def entries
56
+ splat = params["splat"].first
57
+ args = {
58
+ :base => site.source,
59
+ :content_type => "static_files",
60
+ :splat => splat,
61
+ }
62
+ # get all directories inside the requested directory
63
+ directory = JekyllAdmin::Directory.new(directory_path, **args)
64
+ directories = directory.directories
65
+
66
+ # exclude root level directories which do not have static files
67
+ directories = directories.select { |d| dirs_at_root.include? d.name.to_s } if splat.empty?
68
+ directories.concat(directory_files)
69
+ end
70
+
71
+ def static_file_body
72
+ raw_content = request_payload["raw_content"]
73
+ return raw_content if raw_content.is_a?(String) && raw_content != ""
74
+
75
+ Base64.decode64 request_payload["encoded_content"].to_s
76
+ end
77
+
78
+ def static_files
79
+ site.static_files.select { |f| f.path.start_with? site.source }
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,26 +1,26 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class StaticServer < Sinatra::Base
5
- set :public_dir, File.expand_path("./public", File.dirname(__FILE__))
6
-
7
- MUST_BUILD_MESSAGE = "Front end not yet built. Run `script/build` to build."
8
-
9
- # Allow `/admin` and `/admin/`, and `/admin/*` to serve `/public/dist/index.html`
10
- get "/*" do
11
- send_file index_path
12
- end
13
-
14
- # Provide a descriptive error message in dev. if frontend is not build
15
- not_found do
16
- status 404
17
- MUST_BUILD_MESSAGE if settings.development? || settings.test?
18
- end
19
-
20
- private
21
-
22
- def index_path
23
- @index_path ||= File.join(settings.public_folder, "index.html")
24
- end
25
- end
26
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class StaticServer < Sinatra::Base
5
+ set :public_dir, File.expand_path("./public", File.dirname(__FILE__))
6
+
7
+ MUST_BUILD_MESSAGE = "Front end not yet built. Run `script/build` to build."
8
+
9
+ # Allow `/admin` and `/admin/`, and `/admin/*` to serve `/public/dist/index.html`
10
+ get "/*" do
11
+ send_file index_path
12
+ end
13
+
14
+ # Provide a descriptive error message in dev. if frontend is not build
15
+ not_found do
16
+ status 404
17
+ MUST_BUILD_MESSAGE if settings.development? || settings.test?
18
+ end
19
+
20
+ private
21
+
22
+ def index_path
23
+ @index_path ||= File.join(settings.public_folder, "index.html")
24
+ end
25
+ end
26
+ end
@@ -1,75 +1,75 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- # Abstract module to be included in Convertible and Document to provide
5
- # additional, URL-specific functionality without duplicating logic
6
- module URLable
7
- # Absolute URL to the HTTP(S) rendered/served representation of this resource
8
- def http_url
9
- return if is_a?(Jekyll::Collection) || is_a?(JekyllAdmin::DataFile)
10
- return if is_a?(Jekyll::Document) && !collection.write?
11
-
12
- @http_url ||= Addressable::URI.new(
13
- :scheme => scheme, :host => host, :port => port,
14
- :path => path_with_base(JekyllAdmin.site.config["baseurl"], url)
15
- ).normalize.to_s
16
- end
17
-
18
- # Absolute URL to the API representation of this resource
19
- def api_url
20
- @api_url ||= Addressable::URI.new(
21
- :scheme => scheme, :host => host, :port => port,
22
- :path => path_with_base("/_api", resource_path)
23
- ).normalize.to_s
24
- end
25
-
26
- def entries_url
27
- return unless is_a?(Jekyll::Collection)
28
-
29
- "#{api_url}/entries"
30
- end
31
-
32
- private
33
-
34
- # URL path relative to `_api/` to retreive the given resource via the API
35
- # Note: we can't use a case statement here, because === doesn't like includes
36
- #
37
- # rubocop:disable Metrics/CyclomaticComplexity
38
- # rubocop:disable Metrics/PerceivedComplexity
39
- def resource_path
40
- if is_a?(Jekyll::Document) && draft?
41
- "/#{relative_path.sub(%r!\A_!, "")}"
42
- elsif is_a?(Jekyll::Document)
43
- "/collections/#{relative_path.sub(%r!\A_!, "")}"
44
- elsif is_a?(Jekyll::Collection)
45
- "/collections/#{label}"
46
- elsif is_a?(JekyllAdmin::DataFile)
47
- "/data/#{relative_path}"
48
- elsif is_a?(Jekyll::StaticFile)
49
- "/static_files/#{relative_path}"
50
- elsif is_a?(Jekyll::Page)
51
- "/pages/#{relative_path}"
52
- end
53
- end
54
- # rubocop:enable Metrics/PerceivedComplexity
55
- # rubocop:enable Metrics/CyclomaticComplexity
56
-
57
- # URI.join doesn't like joining two relative paths, and File.join may join
58
- # with `\` rather than with `/` on windows
59
- def path_with_base(base, path)
60
- [base, path].join("/").squeeze("/")
61
- end
62
-
63
- def scheme
64
- JekyllAdmin.site.config["scheme"] || "http"
65
- end
66
-
67
- def host
68
- JekyllAdmin.site.config["host"].sub("127.0.0.1", "localhost")
69
- end
70
-
71
- def port
72
- JekyllAdmin.site.config["port"]
73
- end
74
- end
75
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ # Abstract module to be included in Convertible and Document to provide
5
+ # additional, URL-specific functionality without duplicating logic
6
+ module URLable
7
+ # Absolute URL to the HTTP(S) rendered/served representation of this resource
8
+ def http_url
9
+ return if is_a?(Jekyll::Collection) || is_a?(JekyllAdmin::DataFile)
10
+ return if is_a?(Jekyll::Document) && !collection.write?
11
+
12
+ @http_url ||= Addressable::URI.new(
13
+ :scheme => scheme, :host => host, :port => port,
14
+ :path => path_with_base(JekyllAdmin.site.config["baseurl"], url)
15
+ ).normalize.to_s
16
+ end
17
+
18
+ # Absolute URL to the API representation of this resource
19
+ def api_url
20
+ @api_url ||= Addressable::URI.new(
21
+ :scheme => scheme, :host => host, :port => port,
22
+ :path => path_with_base("/_api", resource_path)
23
+ ).normalize.to_s
24
+ end
25
+
26
+ def entries_url
27
+ return unless is_a?(Jekyll::Collection)
28
+
29
+ "#{api_url}/entries"
30
+ end
31
+
32
+ private
33
+
34
+ # URL path relative to `_api/` to retreive the given resource via the API
35
+ # Note: we can't use a case statement here, because === doesn't like includes
36
+ #
37
+ # rubocop:disable Metrics/CyclomaticComplexity
38
+ # rubocop:disable Metrics/PerceivedComplexity
39
+ def resource_path
40
+ if is_a?(Jekyll::Document) && draft?
41
+ "/#{relative_path.sub(%r!\A_!, "")}"
42
+ elsif is_a?(Jekyll::Document)
43
+ "/collections/#{relative_path.sub(%r!\A_!, "")}"
44
+ elsif is_a?(Jekyll::Collection)
45
+ "/collections/#{label}"
46
+ elsif is_a?(JekyllAdmin::DataFile)
47
+ "/data/#{relative_path}"
48
+ elsif is_a?(Jekyll::StaticFile)
49
+ "/static_files/#{relative_path}"
50
+ elsif is_a?(Jekyll::Page)
51
+ "/pages/#{relative_path}"
52
+ end
53
+ end
54
+ # rubocop:enable Metrics/PerceivedComplexity
55
+ # rubocop:enable Metrics/CyclomaticComplexity
56
+
57
+ # URI.join doesn't like joining two relative paths, and File.join may join
58
+ # with `\` rather than with `/` on windows
59
+ def path_with_base(base, path)
60
+ [base, path].join("/").squeeze("/")
61
+ end
62
+
63
+ def scheme
64
+ JekyllAdmin.site.config["scheme"] || "http"
65
+ end
66
+
67
+ def host
68
+ JekyllAdmin.site.config["host"].sub("127.0.0.1", "localhost")
69
+ end
70
+
71
+ def port
72
+ JekyllAdmin.site.config["port"]
73
+ end
74
+ end
75
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- VERSION = "0.10.2"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ VERSION = "0.11.0"
5
+ end
@@ -1,30 +1,30 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Commands
5
- class Serve < Command
6
- class << self
7
- private
8
-
9
- def start_up_webrick(opts, destination)
10
- @reload_reactor.start(opts) if opts["livereload"]
11
-
12
- @server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
13
- @server.mount(opts["baseurl"].to_s, Servlet, destination, file_handler_opts)
14
-
15
- jekyll_admin_monkey_patch
16
-
17
- Jekyll.logger.info "Server address:", server_address(@server, opts)
18
- launch_browser @server, opts if opts["open_url"]
19
- boot_or_detach @server, opts
20
- end
21
-
22
- def jekyll_admin_monkey_patch
23
- @server.mount "/admin", Rack::Handler::WEBrick, JekyllAdmin::StaticServer
24
- @server.mount "/_api", Rack::Handler::WEBrick, JekyllAdmin::Server
25
- Jekyll.logger.info "JekyllAdmin mode:", ENV["RACK_ENV"] || "production"
26
- end
27
- end
28
- end
29
- end
30
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Commands
5
+ class Serve < Command
6
+ class << self
7
+ private
8
+
9
+ def start_up_webrick(opts, destination)
10
+ @reload_reactor.start(opts) if opts["livereload"]
11
+
12
+ @server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
13
+ @server.mount(opts["baseurl"].to_s, Servlet, destination, file_handler_opts)
14
+
15
+ jekyll_admin_monkey_patch
16
+
17
+ Jekyll.logger.info "Server address:", server_address(@server, opts)
18
+ launch_browser @server, opts if opts["open_url"]
19
+ boot_or_detach @server, opts
20
+ end
21
+
22
+ def jekyll_admin_monkey_patch
23
+ @server.mount "/admin", Rack::Handler::WEBrick, JekyllAdmin::StaticServer
24
+ @server.mount "/_api", Rack::Handler::WEBrick, JekyllAdmin::Server
25
+ Jekyll.logger.info "JekyllAdmin mode:", ENV["RACK_ENV"] || "production"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end