jekyll-admin 0.8.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +21 -21
  3. data/README.md +94 -54
  4. data/lib/jekyll-admin.rb +47 -46
  5. data/lib/jekyll-admin/apiable.rb +224 -162
  6. data/lib/jekyll-admin/data_file.rb +106 -103
  7. data/lib/jekyll-admin/directory.rb +72 -73
  8. data/lib/jekyll-admin/file_helper.rb +91 -78
  9. data/lib/jekyll-admin/path_helper.rb +87 -78
  10. data/lib/jekyll-admin/public/asset-manifest.json +27 -0
  11. data/lib/jekyll-admin/public/index.html +1 -12
  12. data/lib/jekyll-admin/public/precache-manifest.5e08ed7edb8d446719b76ae6ead9e3fe.js +78 -0
  13. data/lib/jekyll-admin/public/service-worker.js +39 -0
  14. data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css +2 -0
  15. data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css.map +1 -0
  16. data/lib/jekyll-admin/public/static/css/main.7e0a6705.chunk.css +5 -0
  17. data/lib/jekyll-admin/public/static/css/main.7e0a6705.chunk.css.map +1 -0
  18. data/lib/jekyll-admin/public/static/js/2.a50fa19f.chunk.js +3 -0
  19. data/lib/jekyll-admin/public/static/js/2.a50fa19f.chunk.js.LICENSE.txt +67 -0
  20. data/lib/jekyll-admin/public/static/js/2.a50fa19f.chunk.js.map +1 -0
  21. data/lib/jekyll-admin/public/static/js/main.f3346e4e.chunk.js +2 -0
  22. data/lib/jekyll-admin/public/static/js/main.f3346e4e.chunk.js.map +1 -0
  23. data/lib/jekyll-admin/public/static/js/runtime-main.95f94e60.js +2 -0
  24. data/lib/jekyll-admin/public/static/js/runtime-main.95f94e60.js.map +1 -0
  25. data/lib/jekyll-admin/public/{1dc35d25e61d819a9c357074014867ab.ttf → static/media/fontawesome-webfont.1dc35d25.ttf} +0 -0
  26. data/lib/jekyll-admin/public/{d7c639084f684d66a1bc66855d193ed8.svg → static/media/fontawesome-webfont.24c601e7.svg} +684 -684
  27. data/lib/jekyll-admin/public/{25a32416abee198dd821b0b17a198a8f.eot → static/media/fontawesome-webfont.25a32416.eot} +0 -0
  28. data/lib/jekyll-admin/public/{c8ddf1e5e5bf3682bc7bebf30f394148.woff → static/media/fontawesome-webfont.c8ddf1e5.woff} +0 -0
  29. data/lib/jekyll-admin/public/{e6cf7c6ec7c2d6f670ae9d762604cb0b.woff2 → static/media/fontawesome-webfont.e6cf7c6e.woff2} +0 -0
  30. data/lib/jekyll-admin/public/{55131026930a0cd4539d1e2fdb92722d.ttf → static/media/lato-bold.55131026.ttf} +0 -0
  31. data/lib/jekyll-admin/public/{059514c92565e4045da1a69525dd9ec0.ttf → static/media/lato-regular.059514c9.ttf} +0 -0
  32. data/lib/jekyll-admin/public/{a770b6797b68e3f8920e473eb824bac0.gif → static/media/loader-big.a770b679.gif} +0 -0
  33. data/lib/jekyll-admin/public/static/media/rw-widgets.12f0820c.woff +0 -0
  34. data/lib/jekyll-admin/public/{03945ac4fc7fdefc44bc110bf1ba2393.svg → static/media/rw-widgets.792dcd18.svg} +14 -8
  35. data/lib/jekyll-admin/public/{e44520ab9079ea7633bfa874bed5d21d.eot → static/media/rw-widgets.bc7c4a59.eot} +0 -0
  36. data/lib/jekyll-admin/public/{bfc14ac982326f7d0b1340e20d3e0c37.ttf → static/media/rw-widgets.eceddf47.ttf} +0 -0
  37. data/lib/jekyll-admin/server.rb +108 -101
  38. data/lib/jekyll-admin/server/{collection.rb → collections.rb} +89 -82
  39. data/lib/jekyll-admin/server/configuration.rb +60 -57
  40. data/lib/jekyll-admin/server/data.rb +84 -82
  41. data/lib/jekyll-admin/server/{draft.rb → drafts.rb} +114 -110
  42. data/lib/jekyll-admin/server/{page.rb → pages.rb} +109 -90
  43. data/lib/jekyll-admin/server/site_meta.rb +25 -0
  44. data/lib/jekyll-admin/server/static_files.rb +83 -0
  45. data/lib/jekyll-admin/static_server.rb +26 -24
  46. data/lib/jekyll-admin/urlable.rb +75 -67
  47. data/lib/jekyll-admin/version.rb +5 -3
  48. data/lib/jekyll/commands/serve.rb +30 -24
  49. metadata +57 -59
  50. data/lib/jekyll-admin/page_without_a_file.rb +0 -7
  51. data/lib/jekyll-admin/public/33a752211d05af6684e26ec63c2ed965.gif +0 -0
  52. data/lib/jekyll-admin/public/8b4968b70019a0551a72940c5a2020d3.png +0 -0
  53. data/lib/jekyll-admin/public/8ea28ca3bfdf27145068e81dd07a34c6.png +0 -0
  54. data/lib/jekyll-admin/public/99adb54b0f30c0758bb4cb9ed5b80aa8.woff +0 -0
  55. data/lib/jekyll-admin/public/bundle.js +0 -117
  56. data/lib/jekyll-admin/public/bundle.js.map +0 -1
  57. data/lib/jekyll-admin/public/styles.css +0 -5
  58. data/lib/jekyll-admin/public/styles.css.map +0 -1
  59. data/lib/jekyll-admin/server/static_file.rb +0 -61
@@ -1,18 +1,24 @@
1
1
  <?xml version="1.0" standalone="no"?>
2
2
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
3
  <svg xmlns="http://www.w3.org/2000/svg">
4
- <metadata>Copyright (C) 2015 by original authors @ fontello.com</metadata>
4
+ <metadata>Copyright (C) 2017 by original authors @ fontello.com</metadata>
5
5
  <defs>
6
6
  <font id="rw-widgets" horiz-adv-x="1000" >
7
7
  <font-face font-family="rw-widgets" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
8
8
  <missing-glyph horiz-adv-x="1000" />
9
- <glyph glyph-name="up-dir" unicode="&#xe800;" d="m571 171q0-14-10-25t-25-10h-500q-15 0-25 10t-11 25 11 26l250 250q10 10 25 10t25-10l250-250q10-11 10-26z" horiz-adv-x="571.4" />
10
- <glyph glyph-name="left-dir" unicode="&#xe801;" d="m357 600v-500q0-14-10-25t-26-11-25 11l-250 250q-10 11-10 25t10 25l250 250q11 11 25 11t26-11 10-25z" horiz-adv-x="357.1" />
11
- <glyph glyph-name="right-dir" unicode="&#xe802;" d="m321 350q0-14-10-25l-250-250q-11-11-25-11t-25 11-11 25v500q0 15 11 25t25 11 25-11l250-250q10-10 10-25z" horiz-adv-x="357.1" />
12
- <glyph glyph-name="down-dir" unicode="&#xe803;" d="m571 457q0-14-10-25l-250-250q-11-11-25-11t-25 11l-250 250q-11 11-11 25t11 25 25 11h500q14 0 25-11t10-25z" horiz-adv-x="571.4" />
13
- <glyph glyph-name="calendar" unicode="&#xe804;" d="m71-79h161v161h-161v-161z m197 0h178v161h-178v-161z m-197 197h161v178h-161v-178z m197 0h178v178h-178v-178z m-197 214h161v161h-161v-161z m411-411h179v161h-179v-161z m-214 411h178v161h-178v-161z m428-411h161v161h-161v-161z m-214 197h179v178h-179v-178z m-196 482v161q0 7-6 12t-12 6h-36q-7 0-12-6t-6-12v-161q0-7 6-13t12-5h36q7 0 12 5t6 13z m410-482h161v178h-161v-178z m-214 214h179v161h-179v-161z m214 0h161v161h-161v-161z m18 268v161q0 7-5 12t-13 6h-35q-8 0-13-6t-5-12v-161q0-7 5-13t13-5h35q8 0 13 5t5 13z m215 36v-715q0-29-22-50t-50-21h-786q-29 0-50 21t-21 50v715q0 29 21 50t50 21h72v54q0 36 26 63t63 26h36q37 0 63-26t26-63v-54h214v54q0 36 27 63t63 26h35q37 0 63-26t27-63v-54h71q29 0 50-21t22-50z" horiz-adv-x="928.6" />
14
- <glyph glyph-name="clock" unicode="&#xe805;" d="m500 546v-250q0-7-5-12t-13-5h-178q-8 0-13 5t-5 12v36q0 8 5 13t13 5h125v196q0 8 5 13t12 5h36q8 0 13-5t5-13z m232-196q0 83-41 152t-110 111-152 41-153-41-110-111-41-152 41-152 110-111 153-41 152 41 110 111 41 152z m125 0q0-117-57-215t-156-156-215-58-216 58-155 156-58 215 58 215 155 156 216 58 215-58 156-156 57-215z" horiz-adv-x="857.1" />
15
- <glyph glyph-name="search" unicode="&#xe806;" d="m643 386q0 103-74 176t-176 74-177-74-73-176 73-177 177-73 176 73 74 177z m286-465q0-29-22-50t-50-21q-30 0-50 21l-191 191q-100-69-223-69-80 0-153 31t-125 84-84 125-31 153 31 152 84 126 125 84 153 31 152-31 126-84 84-126 31-152q0-123-69-223l191-191q21-21 21-51z" horiz-adv-x="928.6" />
9
+ <glyph glyph-name="up-dir" unicode="&#xe800;" d="M571 171q0-14-10-25t-25-10h-500q-15 0-25 10t-11 25 11 26l250 250q10 10 25 10t25-10l250-250q10-11 10-26z" horiz-adv-x="571.4" />
10
+
11
+ <glyph glyph-name="search" unicode="&#xe801;" d="M643 386q0 103-73 176t-177 74-177-74-73-176 73-177 177-73 177 73 73 177z m286-465q0-29-22-50t-50-21q-30 0-50 21l-191 191q-100-69-223-69-80 0-153 31t-125 84-84 125-31 153 31 152 84 126 125 84 153 31 153-31 125-84 84-126 31-152q0-123-69-223l191-191q21-21 21-51z" horiz-adv-x="928.6" />
12
+
13
+ <glyph glyph-name="down-dir" unicode="&#xe803;" d="M571 457q0-14-10-25l-250-250q-11-11-25-11t-25 11l-250 250q-11 11-11 25t11 25 25 11h500q14 0 25-11t10-25z" horiz-adv-x="571.4" />
14
+
15
+ <glyph glyph-name="calendar" unicode="&#xe804;" d="M71-79h161v161h-161v-161z m197 0h178v161h-178v-161z m-197 197h161v178h-161v-178z m197 0h178v178h-178v-178z m-197 214h161v161h-161v-161z m411-411h179v161h-179v-161z m-214 411h178v161h-178v-161z m428-411h161v161h-161v-161z m-214 197h179v178h-179v-178z m-196 482v161q0 7-6 12t-12 6h-36q-7 0-12-6t-6-12v-161q0-7 6-13t12-5h36q7 0 12 5t6 13z m410-482h161v178h-161v-178z m-214 214h179v161h-179v-161z m214 0h161v161h-161v-161z m18 268v161q0 7-5 12t-13 6h-35q-7 0-13-6t-5-12v-161q0-7 5-13t13-5h35q8 0 13 5t5 13z m215 36v-715q0-29-22-50t-50-21h-786q-29 0-50 21t-21 50v715q0 29 21 50t50 21h72v54q0 37 26 63t63 26h36q37 0 63-26t26-63v-54h214v54q0 37 27 63t63 26h35q37 0 64-26t26-63v-54h71q29 0 50-21t22-50z" horiz-adv-x="928.6" />
16
+
17
+ <glyph glyph-name="clock" unicode="&#xe805;" d="M500 546v-250q0-7-5-12t-13-5h-178q-8 0-13 5t-5 12v36q0 8 5 13t13 5h125v196q0 8 5 13t12 5h36q8 0 13-5t5-13z m232-196q0 83-41 152t-110 111-152 41-153-41-110-111-41-152 41-152 110-111 153-41 152 41 110 111 41 152z m125 0q0-117-57-215t-156-156-215-58-216 58-155 156-58 215 58 215 155 156 216 58 215-58 156-156 57-215z" horiz-adv-x="857.1" />
18
+
19
+ <glyph glyph-name="angle-left" unicode="&#xf104;" d="M350 546q0-7-6-12l-219-220 219-219q6-6 6-13t-6-13l-28-28q-5-5-12-5t-13 5l-260 261q-6 5-6 12t6 13l260 260q5 6 13 6t12-6l28-28q6-5 6-13z" horiz-adv-x="357.1" />
20
+
21
+ <glyph glyph-name="angle-right" unicode="&#xf105;" d="M332 314q0-7-5-12l-261-261q-5-5-12-5t-13 5l-28 28q-6 6-6 13t6 13l219 219-219 220q-6 5-6 12t6 13l28 28q5 6 13 6t12-6l261-260q5-5 5-13z" horiz-adv-x="357.1" />
16
22
  </font>
17
23
  </defs>
18
24
  </svg>
@@ -1,101 +1,108 @@
1
- module JekyllAdmin
2
- class Server < Sinatra::Base
3
- ROUTES = %w(collections configuration data drafts pages static_files).freeze
4
- include JekyllAdmin::PathHelper
5
- include JekyllAdmin::FileHelper
6
-
7
- register Sinatra::Namespace
8
-
9
- configure :development do
10
- register Sinatra::Reloader
11
- enable :logging
12
- end
13
-
14
- configure :development, :test do
15
- require "sinatra/cross_origin"
16
- register Sinatra::CrossOrigin
17
- enable :cross_origin
18
- disable :allow_credentials
19
- set :allow_methods, %i[delete get options post put]
20
- end
21
-
22
- get "/" do
23
- json ROUTES.map { |r| ["#{r}_api", URI.join(base_url, "/_api/", r)] }.to_h
24
- end
25
-
26
- # CORS preflight
27
- options "*" do
28
- render_404 unless settings.development? || settings.test?
29
- status 204
30
- end
31
-
32
- private
33
-
34
- def site
35
- JekyllAdmin.site
36
- end
37
-
38
- def render_404
39
- status 404
40
- content_type :json
41
- halt
42
- end
43
-
44
- def request_payload
45
- @request_payload ||= if request_body.to_s.empty?
46
- {}
47
- else
48
- JSON.parse(request_body)
49
- end
50
- end
51
-
52
- def base_url
53
- "#{request.scheme}://#{request.host_with_port}"
54
- end
55
-
56
- def front_matter
57
- request_payload["front_matter"]
58
- end
59
-
60
- def document_body
61
- body = if front_matter && !front_matter.empty?
62
- YAML.dump(restored_front_matter).strip
63
- .gsub(": 'null'", ": null") # restore null values
64
- else
65
- "---"
66
- end
67
- body << "\n---\n\n"
68
- body << request_payload["raw_content"].to_s
69
- end
70
- alias page_body document_body
71
-
72
- private
73
-
74
- def request_body
75
- @request_body ||= begin
76
- request.body.rewind
77
- request.body.read
78
- end
79
- end
80
-
81
- def namespace
82
- namespace = request.path_info.split("/")[1].to_s.downcase
83
- namespace if ROUTES.include?(namespace)
84
- end
85
-
86
- # verbose 'null' values in front matter
87
- def restored_front_matter
88
- front_matter.map do |key, value|
89
- value = "null" if value.nil?
90
- [key, value]
91
- end.to_h
92
- end
93
- end
94
- end
95
-
96
- require "jekyll-admin/server/collection"
97
- require "jekyll-admin/server/configuration"
98
- require "jekyll-admin/server/data"
99
- require "jekyll-admin/server/draft"
100
- require "jekyll-admin/server/page"
101
- require "jekyll-admin/server/static_file"
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,82 +1,89 @@
1
- module JekyllAdmin
2
- class Server < Sinatra::Base
3
- namespace "/collections" do
4
- get do
5
- json(site.collections.map { |c| c[1].to_api })
6
- end
7
-
8
- get "/:collection_id" do
9
- ensure_collection
10
- json collection.to_api
11
- end
12
-
13
- get "/:collection_id/*?/?:path.:ext" do
14
- ensure_requested_file
15
- json requested_file.to_api(:include_content => true)
16
- end
17
-
18
- get "/:collection_id/entries/?*" do
19
- ensure_directory
20
- json entries.map(&:to_api)
21
- end
22
-
23
- put "/:collection_id/*?/?:path.:ext" do
24
- ensure_collection
25
-
26
- if renamed?
27
- ensure_requested_file
28
- delete_file_without_process path
29
- end
30
-
31
- write_file write_path, document_body
32
- json written_file.to_api(:include_content => true)
33
- end
34
-
35
- delete "/:collection_id/*?/?:path.:ext" do
36
- ensure_requested_file
37
- delete_file path
38
- content_type :json
39
- status 200
40
- halt
41
- end
42
-
43
- private
44
-
45
- def collection
46
- collection = site.collections.find { |l, _c| l == params["collection_id"] }
47
- collection[1] if collection
48
- end
49
-
50
- def document_id
51
- path = "#{params["splat"].first}/#{filename}"
52
- path.gsub(%r!(\d{4})/(\d{2})/(\d{2})/(.*)!, '\1-\2-\3-\4')
53
- end
54
-
55
- def directory_docs
56
- collection.docs.find_all { |d| File.dirname(d.path) == directory_path }
57
- end
58
-
59
- def ensure_collection
60
- render_404 if collection.nil?
61
- end
62
-
63
- def ensure_directory
64
- ensure_collection
65
- render_404 unless Dir.exist?(directory_path)
66
- end
67
-
68
- def entries
69
- args = {
70
- :base => site.source,
71
- :content_type => params["collection_id"],
72
- :splat => params["splat"].first,
73
- }
74
- # get the directories inside the requested directory
75
- directory = JekyllAdmin::Directory.new(directory_path, args)
76
- directories = directory.directories
77
- # merge directories with the documents at the same level
78
- directories.concat(directory_docs.sort_by(&:date).reverse)
79
- end
80
- end
81
- end
82
- 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,57 +1,60 @@
1
- module JekyllAdmin
2
- class Server < Sinatra::Base
3
- namespace "/configuration" do
4
- get do
5
- json({
6
- :content => parsed_configuration,
7
- :raw_content => raw_configuration,
8
- })
9
- end
10
-
11
- put do
12
- write_file(configuration_path, configuration_body)
13
- json request_payload
14
- end
15
-
16
- private
17
-
18
- def overrides
19
- {
20
- "source" => sanitized_path("/"),
21
- }
22
- end
23
-
24
- # Computed configuration, with updates and defaults
25
- def configuration
26
- @configuration ||= Jekyll.configuration(overrides)
27
- end
28
-
29
- # Configuration data, as read by Jekyll
30
- def parsed_configuration
31
- configuration.read_config_file(configuration_path)
32
- end
33
-
34
- # Raw configuration content, as it sits on disk
35
- def raw_configuration
36
- File.read(
37
- configuration_path,
38
- Jekyll::Utils.merged_file_read_opts(site, {})
39
- )
40
- end
41
-
42
- # Returns the path to the *first* config file discovered
43
- def configuration_path
44
- sanitized_path configuration.config_files(overrides).first
45
- end
46
-
47
- # The user's uploaded configuration for updates
48
- # Instead of extracting `raw_content` directly from the `request_payload`,
49
- # assign the data to a new variable and then extract the `raw_content`
50
- # from it to circumvent CORS violation in `development` mode.
51
- def configuration_body
52
- payload = request_payload
53
- payload["raw_content"]
54
- end
55
- end
56
- end
57
- 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