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,84 +1,84 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class Server < Sinatra::Base
5
- # supported extensions, in order of preference, for now, no .csv
6
- EXTENSIONS = %w(yml json).freeze
7
-
8
- namespace "/data" do
9
- get "/*?/?:path.:ext" do
10
- ensure_requested_file
11
- json requested_file.to_api(:include_content => true)
12
- end
13
-
14
- get "/?*" do
15
- ensure_directory
16
- json entries.map(&:to_api)
17
- end
18
-
19
- put "/*?/?:path.:ext" do
20
- if renamed?
21
- ensure_requested_file
22
- delete_file_without_process path
23
- end
24
-
25
- write_file write_path, data_file_body
26
- json written_file.to_api(:include_content => true)
27
- end
28
-
29
- delete "/*?/?:path.:ext" do
30
- ensure_requested_file
31
- delete_file path
32
- content_type :json
33
- status 200
34
- halt
35
- end
36
-
37
- private
38
-
39
- # returns relative path of root level directories that contain data files
40
- def directory_paths
41
- DataFile.all.map { |p| File.dirname(p.relative_path).split("/")[0] }.uniq
42
- end
43
-
44
- def directory_pages
45
- DataFile.all.find_all do |p|
46
- sanitized_path(File.dirname(p.path)) == directory_path
47
- end
48
- end
49
-
50
- def entries
51
- args = {
52
- :base => site.in_source_dir(DataFile.data_dir),
53
- :content_type => "data",
54
- :splat => splats.first,
55
- }
56
- # get all directories inside the requested directory
57
- directory = JekyllAdmin::Directory.new(directory_path, args)
58
- directories = directory.directories
59
-
60
- # exclude root level directories which do not have data files
61
- if splats.first.empty?
62
- directories = directories.select do |d|
63
- directory_paths.include? d.name.to_s
64
- end
65
- end
66
-
67
- # merge directories with the pages at the same level
68
- directories.concat(directory_pages)
69
- end
70
-
71
- def data_file_body
72
- if !request_payload["raw_content"].to_s.empty?
73
- request_payload["raw_content"]
74
- elsif !request_payload["content"].to_s.empty?
75
- YAML.dump(request_payload["content"]).sub(%r!\A---\n!, "")
76
- end
77
- end
78
-
79
- def splats
80
- params["splat"] || ["/"]
81
- end
82
- end
83
- end
84
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ # supported extensions, in order of preference, for now, no .csv
6
+ EXTENSIONS = %w(yml json).freeze
7
+
8
+ namespace "/data" do
9
+ get "/*?/?:path.:ext" do
10
+ ensure_requested_file
11
+ json requested_file.to_api(:include_content => true)
12
+ end
13
+
14
+ get "/?*" do
15
+ ensure_directory
16
+ json entries.map(&:to_api)
17
+ end
18
+
19
+ put "/*?/?:path.:ext" do
20
+ if renamed?
21
+ ensure_requested_file
22
+ delete_file_without_process path
23
+ end
24
+
25
+ write_file write_path, data_file_body
26
+ json written_file.to_api(:include_content => true)
27
+ end
28
+
29
+ delete "/*?/?:path.:ext" do
30
+ ensure_requested_file
31
+ delete_file path
32
+ content_type :json
33
+ status 200
34
+ halt
35
+ end
36
+
37
+ private
38
+
39
+ # returns relative path of root level directories that contain data files
40
+ def directory_paths
41
+ DataFile.all.map { |p| File.dirname(p.relative_path).split("/")[0] }.uniq
42
+ end
43
+
44
+ def directory_pages
45
+ DataFile.all.find_all do |p|
46
+ sanitized_path(File.dirname(p.path)) == directory_path
47
+ end
48
+ end
49
+
50
+ def entries
51
+ args = {
52
+ :base => site.in_source_dir(DataFile.data_dir),
53
+ :content_type => "data",
54
+ :splat => splats.first,
55
+ }
56
+ # get all directories inside the requested directory
57
+ directory = JekyllAdmin::Directory.new(directory_path, **args)
58
+ directories = directory.directories
59
+
60
+ # exclude root level directories which do not have data files
61
+ if splats.first.empty?
62
+ directories = directories.select do |d|
63
+ directory_paths.include? d.name.to_s
64
+ end
65
+ end
66
+
67
+ # merge directories with the pages at the same level
68
+ directories.concat(directory_pages)
69
+ end
70
+
71
+ def data_file_body
72
+ if !request_payload["raw_content"].to_s.empty?
73
+ request_payload["raw_content"]
74
+ elsif !request_payload["content"].to_s.empty?
75
+ YAML.dump(request_payload["content"]).sub(%r!\A---\n!, "")
76
+ end
77
+ end
78
+
79
+ def splats
80
+ params["splat"] || ["/"]
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,114 +1,114 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class Server < Sinatra::Base
5
- namespace "/drafts" do
6
- get "/*?/?:path.:ext" do
7
- ensure_requested_file
8
- json requested_file.to_api(:include_content => true)
9
- end
10
-
11
- get "/?*" do
12
- ensure_directory
13
- json entries.map(&:to_api)
14
- end
15
-
16
- put "/*?/?:path.:ext" do
17
- ensure_html_content
18
-
19
- if new?
20
- ensure_not_overwriting_existing_file
21
- elsif renamed?
22
- ensure_requested_file
23
- ensure_not_overwriting_existing_file
24
- delete_file_without_process path
25
- end
26
-
27
- write_file write_path, document_body
28
- json written_file.to_api(:include_content => true)
29
- end
30
-
31
- delete "/*?/?:path.:ext" do
32
- ensure_requested_file
33
- delete_file path
34
- content_type :json
35
- status 200
36
- halt
37
- end
38
-
39
- private
40
-
41
- # return all documents in the 'posts' collection that output to an html
42
- # file but reside in a separate directory, `<source_dir>/_drafts/`
43
- def drafts
44
- posts = site.collections.find { |l, _c| l == "posts" }
45
- posts[1].docs.find_all { |d| d.output_ext == ".html" && d.draft? } if posts
46
- end
47
-
48
- # return drafts at the same level as directory
49
- def directory_drafts
50
- drafts.find_all { |d| File.dirname(d.path) == directory_path }
51
- end
52
-
53
- def reverse_sorted_drafts
54
- directory_drafts.sort_by(&:date).reverse
55
- end
56
-
57
- # returns directories at the root of `/_drafts/` that contain drafts
58
- def relevant_directory_paths
59
- drafts.map { |doc| relative_draft_path(doc).split("/")[0] }.uniq
60
- end
61
-
62
- def relative_draft_path(document)
63
- File.dirname(document.relative_path.sub("_drafts/", ""))
64
- end
65
-
66
- def ensure_directory
67
- ensure_drafts
68
- render_404 unless Dir.exist?(directory_path)
69
- end
70
-
71
- def ensure_drafts
72
- render_404 if drafts.nil?
73
- end
74
-
75
- def ensure_html_content
76
- return if html_content?
77
-
78
- content_type :json
79
- halt 422, json("error_message" => "Invalid file extension for drafts")
80
- end
81
-
82
- def entries
83
- args = {
84
- :base => site.in_source_dir("_drafts"),
85
- :content_type => "drafts",
86
- :splat => params["splat"].first,
87
- }
88
- # get the directories inside the requested directory
89
- directory = JekyllAdmin::Directory.new(directory_path, args)
90
- directories = directory.directories
91
-
92
- # exclude root level directories which do not have drafts
93
- if params["splat"].first.empty?
94
- directories = directories.select do |d|
95
- relevant_directory_paths.include? d.name.to_s
96
- end
97
- end
98
- # merge directories with the drafts at the same level
99
- directories.concat(reverse_sorted_drafts)
100
- end
101
-
102
- def html_content?
103
- draft = Jekyll::PageWithoutAFile.new(
104
- site,
105
- site.source,
106
- "_drafts",
107
- request_payload["path"] || filename
108
- )
109
- draft.data = request_payload["front_matter"]
110
- draft.html?
111
- end
112
- end
113
- end
114
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ namespace "/drafts" do
6
+ get "/*?/?:path.:ext" do
7
+ ensure_requested_file
8
+ json requested_file.to_api(:include_content => true)
9
+ end
10
+
11
+ get "/?*" do
12
+ ensure_directory
13
+ json entries.map(&:to_api)
14
+ end
15
+
16
+ put "/*?/?:path.:ext" do
17
+ ensure_html_content
18
+
19
+ if new?
20
+ ensure_not_overwriting_existing_file
21
+ elsif renamed?
22
+ ensure_requested_file
23
+ ensure_not_overwriting_existing_file
24
+ delete_file_without_process path
25
+ end
26
+
27
+ write_file write_path, document_body
28
+ json written_file.to_api(:include_content => true)
29
+ end
30
+
31
+ delete "/*?/?:path.:ext" do
32
+ ensure_requested_file
33
+ delete_file path
34
+ content_type :json
35
+ status 200
36
+ halt
37
+ end
38
+
39
+ private
40
+
41
+ # return all documents in the 'posts' collection that output to an html
42
+ # file but reside in a separate directory, `<source_dir>/_drafts/`
43
+ def drafts
44
+ posts = site.collections.find { |l, _c| l == "posts" }
45
+ posts[1].docs.find_all { |d| d.output_ext == ".html" && d.draft? } if posts
46
+ end
47
+
48
+ # return drafts at the same level as directory
49
+ def directory_drafts
50
+ drafts.find_all { |d| File.dirname(d.path) == directory_path }
51
+ end
52
+
53
+ def reverse_sorted_drafts
54
+ directory_drafts.sort_by(&:date).reverse
55
+ end
56
+
57
+ # returns directories at the root of `/_drafts/` that contain drafts
58
+ def relevant_directory_paths
59
+ drafts.map { |doc| relative_draft_path(doc).split("/")[0] }.uniq
60
+ end
61
+
62
+ def relative_draft_path(document)
63
+ File.dirname(document.relative_path.sub("_drafts/", ""))
64
+ end
65
+
66
+ def ensure_directory
67
+ ensure_drafts
68
+ render_404 unless Dir.exist?(directory_path)
69
+ end
70
+
71
+ def ensure_drafts
72
+ render_404 if drafts.nil?
73
+ end
74
+
75
+ def ensure_html_content
76
+ return if html_content?
77
+
78
+ content_type :json
79
+ halt 422, json("error_message" => "Invalid file extension for drafts")
80
+ end
81
+
82
+ def entries
83
+ args = {
84
+ :base => site.in_source_dir("_drafts"),
85
+ :content_type => "drafts",
86
+ :splat => params["splat"].first,
87
+ }
88
+ # get the directories inside the requested directory
89
+ directory = JekyllAdmin::Directory.new(directory_path, **args)
90
+ directories = directory.directories
91
+
92
+ # exclude root level directories which do not have drafts
93
+ if params["splat"].first.empty?
94
+ directories = directories.select do |d|
95
+ relevant_directory_paths.include? d.name.to_s
96
+ end
97
+ end
98
+ # merge directories with the drafts at the same level
99
+ directories.concat(reverse_sorted_drafts)
100
+ end
101
+
102
+ def html_content?
103
+ draft = Jekyll::PageWithoutAFile.new(
104
+ site,
105
+ site.source,
106
+ "_drafts",
107
+ request_payload["path"] || filename
108
+ )
109
+ draft.data = request_payload["front_matter"]
110
+ draft.html?
111
+ end
112
+ end
113
+ end
114
+ end
@@ -1,109 +1,109 @@
1
- # frozen_string_literal: true
2
-
3
- module JekyllAdmin
4
- class Server < Sinatra::Base
5
- namespace "/pages" do
6
- get "/*?/?:path.:ext" do
7
- ensure_requested_file
8
- json requested_file.to_api(:include_content => true)
9
- end
10
-
11
- get "/?*" do
12
- ensure_directory
13
- json entries.map(&:to_api)
14
- end
15
-
16
- put "/*?/?:path.:ext" do
17
- ensure_html_content
18
-
19
- if new?
20
- ensure_not_overwriting_existing_file
21
- elsif renamed?
22
- ensure_requested_file
23
- ensure_not_overwriting_existing_file
24
- delete_file_without_process path
25
- end
26
-
27
- write_file write_path, page_body
28
- json written_file.to_api(:include_content => true)
29
- end
30
-
31
- delete "/*?/?:path.:ext" do
32
- ensure_requested_file
33
- delete_file path
34
- content_type :json
35
- status 200
36
- halt
37
- end
38
-
39
- private
40
-
41
- def ensure_html_content
42
- return if html_content?
43
-
44
- content_type :json
45
- halt 422, json("error_message" => "Invalid file extension for pages")
46
- end
47
-
48
- def html_content?
49
- page = Jekyll::PageWithoutAFile.new(
50
- site,
51
- site.source,
52
- "",
53
- request_payload["path"] || filename
54
- )
55
- page.data = request_payload["front_matter"]
56
- page.html?
57
- end
58
-
59
- def pages
60
- site.pages.select { |p| html_page_at_source?(p) }
61
- end
62
-
63
- # Test if a given page is *physically located* within the source directory and outputs
64
- # to an HTML file.
65
- # We don't want *virtual pages* that are generated via plugins.
66
- def html_page_at_source?(page)
67
- return false unless page.html?
68
-
69
- # If page is not an instance of a `Jekyll::Page` subclass, then it needs additional
70
- # inspection.
71
- # Can't use `is_a?(Jekyll::Page)` here because it returns true for subclass instances
72
- return true if page.class == Jekyll::Page
73
-
74
- File.exist?(site.in_source_dir(page.relative_path))
75
- end
76
-
77
- def directory_pages
78
- pages.find_all do |p|
79
- sanitized_path(File.dirname(p.path)) == directory_path
80
- end
81
- end
82
-
83
- # returns relative path of root level directories that contain pages
84
- def directory_paths
85
- pages.map { |p| File.dirname(p.path).split("/")[0] }.uniq
86
- end
87
-
88
- def entries
89
- args = {
90
- :base => site.source,
91
- :content_type => "pages",
92
- :splat => params["splat"].first,
93
- }
94
- # get all directories inside the requested directory
95
- directory = JekyllAdmin::Directory.new(directory_path, args)
96
- directories = directory.directories
97
-
98
- # exclude root level directories which do not have pages
99
- if params["splat"].first.empty?
100
- directories = directories.select do |d|
101
- directory_paths.include? d.name.to_s
102
- end
103
- end
104
- # merge directories with the pages at the same level
105
- directories.concat(directory_pages)
106
- end
107
- end
108
- end
109
- end
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllAdmin
4
+ class Server < Sinatra::Base
5
+ namespace "/pages" do
6
+ get "/*?/?:path.:ext" do
7
+ ensure_requested_file
8
+ json requested_file.to_api(:include_content => true)
9
+ end
10
+
11
+ get "/?*" do
12
+ ensure_directory
13
+ json entries.map(&:to_api)
14
+ end
15
+
16
+ put "/*?/?:path.:ext" do
17
+ ensure_html_content
18
+
19
+ if new?
20
+ ensure_not_overwriting_existing_file
21
+ elsif renamed?
22
+ ensure_requested_file
23
+ ensure_not_overwriting_existing_file
24
+ delete_file_without_process path
25
+ end
26
+
27
+ write_file write_path, page_body
28
+ json written_file.to_api(:include_content => true)
29
+ end
30
+
31
+ delete "/*?/?:path.:ext" do
32
+ ensure_requested_file
33
+ delete_file path
34
+ content_type :json
35
+ status 200
36
+ halt
37
+ end
38
+
39
+ private
40
+
41
+ def ensure_html_content
42
+ return if html_content?
43
+
44
+ content_type :json
45
+ halt 422, json("error_message" => "Invalid file extension for pages")
46
+ end
47
+
48
+ def html_content?
49
+ page = Jekyll::PageWithoutAFile.new(
50
+ site,
51
+ site.source,
52
+ "",
53
+ request_payload["path"] || filename
54
+ )
55
+ page.data = request_payload["front_matter"]
56
+ page.html?
57
+ end
58
+
59
+ def pages
60
+ site.pages.select { |p| html_page_at_source?(p) }
61
+ end
62
+
63
+ # Test if a given page is *physically located* within the source directory and outputs
64
+ # to an HTML file.
65
+ # We don't want *virtual pages* that are generated via plugins.
66
+ def html_page_at_source?(page)
67
+ return false unless page.html?
68
+
69
+ # If page is not an instance of a `Jekyll::Page` subclass, then it needs additional
70
+ # inspection.
71
+ # Can't use `is_a?(Jekyll::Page)` here because it returns true for subclass instances
72
+ return true if page.class == Jekyll::Page
73
+
74
+ File.exist?(site.in_source_dir(page.relative_path))
75
+ end
76
+
77
+ def directory_pages
78
+ pages.find_all do |p|
79
+ sanitized_path(File.dirname(p.path)) == directory_path
80
+ end
81
+ end
82
+
83
+ # returns relative path of root level directories that contain pages
84
+ def directory_paths
85
+ pages.map { |p| File.dirname(p.path).split("/")[0] }.uniq
86
+ end
87
+
88
+ def entries
89
+ args = {
90
+ :base => site.source,
91
+ :content_type => "pages",
92
+ :splat => params["splat"].first,
93
+ }
94
+ # get all directories inside the requested directory
95
+ directory = JekyllAdmin::Directory.new(directory_path, **args)
96
+ directories = directory.directories
97
+
98
+ # exclude root level directories which do not have pages
99
+ if params["splat"].first.empty?
100
+ directories = directories.select do |d|
101
+ directory_paths.include? d.name.to_s
102
+ end
103
+ end
104
+ # merge directories with the pages at the same level
105
+ directories.concat(directory_pages)
106
+ end
107
+ end
108
+ end
109
+ end