jekyll-admin 0.10.0 → 0.10.1
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.
- checksums.yaml +5 -5
- data/LICENSE +21 -21
- data/README.md +94 -94
- data/lib/jekyll-admin.rb +47 -47
- data/lib/jekyll-admin/apiable.rb +224 -224
- data/lib/jekyll-admin/data_file.rb +106 -106
- data/lib/jekyll-admin/directory.rb +72 -72
- data/lib/jekyll-admin/file_helper.rb +91 -91
- data/lib/jekyll-admin/path_helper.rb +87 -87
- data/lib/jekyll-admin/public/asset-manifest.json +27 -0
- data/lib/jekyll-admin/public/index.html +1 -13
- data/lib/jekyll-admin/public/precache-manifest.52de67482747a1012d0d27a209b930d0.js +78 -0
- data/lib/jekyll-admin/public/service-worker.js +39 -0
- data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css +2 -0
- data/lib/jekyll-admin/public/static/css/2.b74256fb.chunk.css.map +1 -0
- data/lib/jekyll-admin/public/static/css/main.223e267c.chunk.css +5 -0
- data/lib/jekyll-admin/public/static/css/main.223e267c.chunk.css.map +1 -0
- data/lib/jekyll-admin/public/static/js/2.49911da2.chunk.js +3 -0
- data/lib/jekyll-admin/public/static/js/2.49911da2.chunk.js.LICENSE.txt +67 -0
- data/lib/jekyll-admin/public/static/js/2.49911da2.chunk.js.map +1 -0
- data/lib/jekyll-admin/public/static/js/main.dd81e877.chunk.js +2 -0
- data/lib/jekyll-admin/public/static/js/main.dd81e877.chunk.js.map +1 -0
- data/lib/jekyll-admin/public/static/js/runtime-main.95f94e60.js +2 -0
- data/lib/jekyll-admin/public/static/js/runtime-main.95f94e60.js.map +1 -0
- data/lib/jekyll-admin/public/{1dc35d25e61d819a9c357074014867ab.ttf → static/media/fontawesome-webfont.1dc35d25.ttf} +0 -0
- data/lib/jekyll-admin/public/{25a32416abee198dd821b0b17a198a8f.eot → static/media/fontawesome-webfont.25a32416.eot} +0 -0
- data/lib/jekyll-admin/public/{c8ddf1e5e5bf3682bc7bebf30f394148.woff → static/media/fontawesome-webfont.c8ddf1e5.woff} +0 -0
- data/lib/jekyll-admin/public/{24c601e721ebd8279d38e2cfa0d01bc6.svg → static/media/fontawesome-webfont.d7c63908.svg} +684 -684
- data/lib/jekyll-admin/public/{e6cf7c6ec7c2d6f670ae9d762604cb0b.woff2 → static/media/fontawesome-webfont.e6cf7c6e.woff2} +0 -0
- data/lib/jekyll-admin/public/{55131026930a0cd4539d1e2fdb92722d.ttf → static/media/lato-bold.55131026.ttf} +0 -0
- data/lib/jekyll-admin/public/{059514c92565e4045da1a69525dd9ec0.ttf → static/media/lato-regular.059514c9.ttf} +0 -0
- data/lib/jekyll-admin/public/{a770b6797b68e3f8920e473eb824bac0.gif → static/media/loader-big.a770b679.gif} +0 -0
- data/lib/jekyll-admin/public/{12f0820c451bdc75f4d1ef97732bf6e8.woff → static/media/rw-widgets.12f0820c.woff} +0 -0
- data/lib/jekyll-admin/public/{792dcd18baf5f544aabcad1883d673c2.svg → static/media/rw-widgets.792dcd18.svg} +0 -0
- data/lib/jekyll-admin/public/{bc7c4a59f924cf037aad6e1f9edba366.eot → static/media/rw-widgets.bc7c4a59.eot} +0 -0
- data/lib/jekyll-admin/public/{eceddf474df95d8d4a7e316668c3be85.ttf → static/media/rw-widgets.eceddf47.ttf} +0 -0
- data/lib/jekyll-admin/server.rb +108 -108
- data/lib/jekyll-admin/server/collections.rb +89 -89
- data/lib/jekyll-admin/server/configuration.rb +60 -60
- data/lib/jekyll-admin/server/data.rb +84 -84
- data/lib/jekyll-admin/server/drafts.rb +114 -114
- data/lib/jekyll-admin/server/pages.rb +109 -109
- data/lib/jekyll-admin/server/site_meta.rb +25 -25
- data/lib/jekyll-admin/server/static_files.rb +83 -83
- data/lib/jekyll-admin/static_server.rb +26 -26
- data/lib/jekyll-admin/urlable.rb +75 -75
- data/lib/jekyll-admin/version.rb +5 -5
- data/lib/jekyll/commands/serve.rb +30 -30
- metadata +30 -22
- data/lib/jekyll-admin/public/33a752211d05af6684e26ec63c2ed965.gif +0 -0
- data/lib/jekyll-admin/public/8b4968b70019a0551a72940c5a2020d3.png +0 -0
- data/lib/jekyll-admin/public/8ea28ca3bfdf27145068e81dd07a34c6.png +0 -0
- data/lib/jekyll-admin/public/bundle.js +0 -64
- data/lib/jekyll-admin/public/bundle.js.map +0 -1
- data/lib/jekyll-admin/public/styles.css +0 -106
- data/lib/jekyll-admin/public/styles.css.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
|