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,108 +1,108 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class Server < Sinatra::Base
5
- ROUTES = %w(collections configuration data drafts pages static_files).freeze
6
- include JekyllAdmin::PathHelper
7
- include JekyllAdmin::FileHelper
8
-
9
- register Sinatra::Namespace
10
-
11
- configure :development do
12
- register Sinatra::Reloader
13
- enable :logging
14
- end
15
-
16
- configure :development, :test do
17
- require "sinatra/cross_origin"
18
- register Sinatra::CrossOrigin
19
- enable :cross_origin
20
- disable :allow_credentials
21
- set :allow_methods, [:delete, :get, :options, :post, :put]
22
- end
23
-
24
- get "/" do
25
- json ROUTES.map { |r| ["#{r}_api", URI.join(base_url, "/_api/", r)] }.to_h
26
- end
27
-
28
- # CORS preflight
29
- options "*" do
30
- render_404 unless settings.development? || settings.test?
31
- status 204
32
- end
33
-
34
- private
35
-
36
- def json(object, options = {})
37
- content_type :json
38
- JSON.pretty_generate(object, options)
39
- end
40
-
41
- def site
42
- JekyllAdmin.site
43
- end
44
-
45
- def render_404
46
- status 404
47
- content_type :json
48
- halt
49
- end
50
-
51
- def request_payload
52
- @request_payload ||= if request_body.to_s.empty?
53
- {}
54
- else
55
- JSON.parse(request_body)
56
- end
57
- end
58
-
59
- def base_url
60
- "#{request.scheme}://#{request.host_with_port}"
61
- end
62
-
63
- def front_matter
64
- request_payload["front_matter"]
65
- end
66
-
67
- def document_body
68
- body = +""
69
- body << if front_matter && !front_matter.empty?
70
- YAML.dump(restored_front_matter).strip
71
- .gsub(": 'null'", ": null") # restore null values
72
- else
73
- "---"
74
- end
75
- body << "\n---\n\n"
76
- body << request_payload["raw_content"].to_s
77
- body << "\n" unless body.end_with?("\n")
78
- body
79
- end
80
- alias_method :page_body, :document_body
81
-
82
- def request_body
83
- @request_body ||= begin
84
- request.body.rewind
85
- request.body.read
86
- end
87
- end
88
-
89
- def namespace
90
- namespace = request.path_info.split("/")[1].to_s.downcase
91
- namespace if ROUTES.include?(namespace)
92
- end
93
-
94
- # verbose 'null' values in front matter
95
- def restored_front_matter
96
- front_matter.map do |key, value|
97
- value = "null" if value.nil?
98
- [key, value]
99
- end.to_h
100
- end
101
- end
102
- end
103
-
104
- # load individual route configurations
105
- JekyllAdmin::Server::ROUTES.each { |name| require_relative File.join("server", name) }
106
-
107
- # load namespaces outside route configurations
108
- require_relative "server/site_meta"
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ ROUTES = %w(collections configuration data drafts pages static_files).freeze
6
+ include JekyllAdmin::PathHelper
7
+ include JekyllAdmin::FileHelper
8
+
9
+ register Sinatra::Namespace
10
+
11
+ configure :development do
12
+ register Sinatra::Reloader
13
+ enable :logging
14
+ end
15
+
16
+ configure :development, :test do
17
+ require "sinatra/cross_origin"
18
+ register Sinatra::CrossOrigin
19
+ enable :cross_origin
20
+ disable :allow_credentials
21
+ set :allow_methods, [:delete, :get, :options, :post, :put]
22
+ end
23
+
24
+ get "/" do
25
+ json ROUTES.map { |r| ["#{r}_api", URI.join(base_url, "/_api/", r)] }.to_h
26
+ end
27
+
28
+ # CORS preflight
29
+ options "*" do
30
+ render_404 unless settings.development? || settings.test?
31
+ status 204
32
+ end
33
+
34
+ private
35
+
36
+ def json(object, options = {})
37
+ content_type :json
38
+ JSON.pretty_generate(object, options)
39
+ end
40
+
41
+ def site
42
+ JekyllAdmin.site
43
+ end
44
+
45
+ def render_404
46
+ status 404
47
+ content_type :json
48
+ halt
49
+ end
50
+
51
+ def request_payload
52
+ @request_payload ||= if request_body.to_s.empty?
53
+ {}
54
+ else
55
+ JSON.parse(request_body)
56
+ end
57
+ end
58
+
59
+ def base_url
60
+ "#{request.scheme}://#{request.host_with_port}"
61
+ end
62
+
63
+ def front_matter
64
+ request_payload["front_matter"]
65
+ end
66
+
67
+ def document_body
68
+ body = +""
69
+ body << if front_matter && !front_matter.empty?
70
+ YAML.dump(restored_front_matter).strip
71
+ .gsub(": 'null'", ": null") # restore null values
72
+ else
73
+ "---"
74
+ end
75
+ body << "\n---\n\n"
76
+ body << request_payload["raw_content"].to_s
77
+ body << "\n" unless body.end_with?("\n")
78
+ body
79
+ end
80
+ alias_method :page_body, :document_body
81
+
82
+ def request_body
83
+ @request_body ||= begin
84
+ request.body.rewind
85
+ request.body.read
86
+ end
87
+ end
88
+
89
+ def namespace
90
+ namespace = request.path_info.split("/")[1].to_s.downcase
91
+ namespace if ROUTES.include?(namespace)
92
+ end
93
+
94
+ # verbose 'null' values in front matter
95
+ def restored_front_matter
96
+ front_matter.map do |key, value|
97
+ value = "null" if value.nil?
98
+ [key, value]
99
+ end.to_h
100
+ end
101
+ end
102
+ end
103
+
104
+ # load individual route configurations
105
+ JekyllAdmin::Server::ROUTES.each { |name| require_relative File.join("server", name) }
106
+
107
+ # load namespaces outside route configurations
108
+ require_relative "server/site_meta"
@@ -1,89 +1,89 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class Server < Sinatra::Base
5
- namespace "/collections" do
6
- get do
7
- json(site.collections.map { |c| c[1].to_api })
8
- end
9
-
10
- get "/:collection_id" do
11
- ensure_collection
12
- json collection.to_api
13
- end
14
-
15
- get "/:collection_id/*?/?:path.:ext" do
16
- ensure_requested_file
17
- json requested_file.to_api(:include_content => true)
18
- end
19
-
20
- get "/:collection_id/entries/?*" do
21
- ensure_directory
22
- json entries.map(&:to_api)
23
- end
24
-
25
- put "/:collection_id/*?/?:path.:ext" do
26
- ensure_collection
27
-
28
- if new?
29
- ensure_not_overwriting_existing_file
30
- elsif renamed?
31
- ensure_requested_file
32
- ensure_not_overwriting_existing_file
33
- delete_file_without_process path
34
- end
35
-
36
- write_file write_path, document_body
37
- json written_file.to_api(:include_content => true)
38
- end
39
-
40
- delete "/:collection_id/*?/?:path.:ext" do
41
- ensure_requested_file
42
- delete_file path
43
- content_type :json
44
- status 200
45
- halt
46
- end
47
-
48
- private
49
-
50
- def collection
51
- collection = site.collections.find { |l, _c| l == params["collection_id"] }
52
- collection[1] if collection
53
- end
54
-
55
- def document_id
56
- path = "#{params["splat"].first}/#{filename}"
57
- path.gsub(%r!(\d{4})/(\d{2})/(\d{2})/(.*)!, '\1-\2-\3-\4')
58
- end
59
-
60
- def directory_docs
61
- collection.docs.find_all { |d| File.dirname(d.path) == directory_path }
62
- end
63
-
64
- def ensure_collection
65
- render_404 if collection.nil?
66
- end
67
-
68
- def ensure_directory
69
- ensure_collection
70
- render_404 unless Dir.exist?(directory_path)
71
- end
72
-
73
- def entries
74
- collections_dir = site.config["collections_dir"]
75
- collection_id, splats = params.values_at("collection_id", "splat")
76
- args = {
77
- :base => site.in_source_dir(collections_dir, "_#{collection_id}"),
78
- :content_type => collection_id,
79
- :splat => splats&.first,
80
- }
81
- # get the directories inside the requested directory
82
- directory = JekyllAdmin::Directory.new(directory_path, args)
83
- directories = directory.directories
84
- # merge directories with the documents at the same level
85
- directories.concat(directory_docs.sort_by(&:date).reverse)
86
- end
87
- end
88
- end
89
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ namespace "/collections" do
6
+ get do
7
+ json(site.collections.map { |c| c[1].to_api })
8
+ end
9
+
10
+ get "/:collection_id" do
11
+ ensure_collection
12
+ json collection.to_api
13
+ end
14
+
15
+ get "/:collection_id/*?/?:path.:ext" do
16
+ ensure_requested_file
17
+ json requested_file.to_api(:include_content => true)
18
+ end
19
+
20
+ get "/:collection_id/entries/?*" do
21
+ ensure_directory
22
+ json entries.map(&:to_api)
23
+ end
24
+
25
+ put "/:collection_id/*?/?:path.:ext" do
26
+ ensure_collection
27
+
28
+ if new?
29
+ ensure_not_overwriting_existing_file
30
+ elsif renamed?
31
+ ensure_requested_file
32
+ ensure_not_overwriting_existing_file
33
+ delete_file_without_process path
34
+ end
35
+
36
+ write_file write_path, document_body
37
+ json written_file.to_api(:include_content => true)
38
+ end
39
+
40
+ delete "/:collection_id/*?/?:path.:ext" do
41
+ ensure_requested_file
42
+ delete_file path
43
+ content_type :json
44
+ status 200
45
+ halt
46
+ end
47
+
48
+ private
49
+
50
+ def collection
51
+ collection = site.collections.find { |l, _c| l == params["collection_id"] }
52
+ collection[1] if collection
53
+ end
54
+
55
+ def document_id
56
+ path = "#{params["splat"].first}/#{filename}"
57
+ path.gsub(%r!(\d{4})/(\d{2})/(\d{2})/(.*)!, '\1-\2-\3-\4')
58
+ end
59
+
60
+ def directory_docs
61
+ collection.docs.find_all { |d| File.dirname(d.path) == directory_path }
62
+ end
63
+
64
+ def ensure_collection
65
+ render_404 if collection.nil?
66
+ end
67
+
68
+ def ensure_directory
69
+ ensure_collection
70
+ render_404 unless Dir.exist?(directory_path)
71
+ end
72
+
73
+ def entries
74
+ collections_dir = site.config["collections_dir"]
75
+ collection_id, splats = params.values_at("collection_id", "splat")
76
+ args = {
77
+ :base => site.in_source_dir(collections_dir, "_#{collection_id}"),
78
+ :content_type => collection_id,
79
+ :splat => splats&.first,
80
+ }
81
+ # get the directories inside the requested directory
82
+ directory = JekyllAdmin::Directory.new(directory_path, **args)
83
+ directories = directory.directories
84
+ # merge directories with the documents at the same level
85
+ directories.concat(directory_docs.sort_by(&:date).reverse)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -1,60 +1,60 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class Server < Sinatra::Base
5
- namespace "/configuration" do
6
- get do
7
- json(
8
- :content => parsed_configuration,
9
- :raw_content => raw_configuration
10
- )
11
- end
12
-
13
- put do
14
- write_file(configuration_path, configuration_body)
15
- json request_payload
16
- end
17
-
18
- private
19
-
20
- def overrides
21
- @overrides ||= {
22
- "source" => sanitized_path("/"),
23
- }
24
- end
25
-
26
- # Computed configuration, with updates and defaults
27
- # Returns an instance of Jekyll::Configuration
28
- def configuration
29
- @configuration ||= site.config.merge(overrides)
30
- end
31
-
32
- # Configuration data, as read by Jekyll
33
- def parsed_configuration
34
- configuration.read_config_file(configuration_path)
35
- end
36
-
37
- # Raw configuration content, as it sits on disk
38
- def raw_configuration
39
- File.read(
40
- configuration_path,
41
- Jekyll::Utils.merged_file_read_opts(site, {})
42
- )
43
- end
44
-
45
- # Returns the path to the *first* config file discovered
46
- def configuration_path
47
- sanitized_path configuration.config_files(overrides).first
48
- end
49
-
50
- # The user's uploaded configuration for updates
51
- # Instead of extracting `raw_content` directly from the `request_payload`,
52
- # assign the data to a new variable and then extract the `raw_content`
53
- # from it to circumvent CORS violation in `development` mode.
54
- def configuration_body
55
- payload = request_payload
56
- payload["raw_content"]
57
- end
58
- end
59
- end
60
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ namespace "/configuration" do
6
+ get do
7
+ json(
8
+ :content => parsed_configuration,
9
+ :raw_content => raw_configuration
10
+ )
11
+ end
12
+
13
+ put do
14
+ write_file(configuration_path, configuration_body)
15
+ json request_payload
16
+ end
17
+
18
+ private
19
+
20
+ def overrides
21
+ @overrides ||= {
22
+ "source" => sanitized_path("/"),
23
+ }
24
+ end
25
+
26
+ # Computed configuration, with updates and defaults
27
+ # Returns an instance of Jekyll::Configuration
28
+ def configuration
29
+ @configuration ||= site.config.merge(overrides)
30
+ end
31
+
32
+ # Configuration data, as read by Jekyll
33
+ def parsed_configuration
34
+ configuration.read_config_file(configuration_path)
35
+ end
36
+
37
+ # Raw configuration content, as it sits on disk
38
+ def raw_configuration
39
+ File.read(
40
+ configuration_path,
41
+ **Jekyll::Utils.merged_file_read_opts(site, {})
42
+ )
43
+ end
44
+
45
+ # Returns the path to the *first* config file discovered
46
+ def configuration_path
47
+ sanitized_path configuration.config_files(overrides).first
48
+ end
49
+
50
+ # The user's uploaded configuration for updates
51
+ # Instead of extracting `raw_content` directly from the `request_payload`,
52
+ # assign the data to a new variable and then extract the `raw_content`
53
+ # from it to circumvent CORS violation in `development` mode.
54
+ def configuration_body
55
+ payload = request_payload
56
+ payload["raw_content"]
57
+ end
58
+ end
59
+ end
60
+ end