jekyll-admin 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +50 -50
- data/lib/jekyll-admin.rb +46 -46
- data/lib/jekyll-admin/apiable.rb +163 -162
- data/lib/jekyll-admin/data_file.rb +103 -103
- data/lib/jekyll-admin/directory.rb +74 -73
- data/lib/jekyll-admin/file_helper.rb +77 -78
- data/lib/jekyll-admin/page_without_a_file.rb +7 -7
- data/lib/jekyll-admin/path_helper.rb +80 -78
- data/lib/jekyll-admin/public/{d7c639084f684d66a1bc66855d193ed8.svg → 24c601e721ebd8279d38e2cfa0d01bc6.svg} +684 -684
- data/lib/jekyll-admin/public/bundle.js +14 -77
- data/lib/jekyll-admin/public/bundle.js.map +1 -1
- data/lib/jekyll-admin/public/index.html +13 -12
- data/lib/jekyll-admin/public/styles.css +4 -4
- data/lib/jekyll-admin/public/styles.css.map +1 -1
- data/lib/jekyll-admin/server.rb +99 -101
- data/lib/jekyll-admin/server/collection.rb +82 -82
- data/lib/jekyll-admin/server/configuration.rb +57 -57
- data/lib/jekyll-admin/server/data.rb +82 -82
- data/lib/jekyll-admin/server/draft.rb +109 -110
- data/lib/jekyll-admin/server/page.rb +91 -90
- data/lib/jekyll-admin/server/static_file.rb +61 -61
- data/lib/jekyll-admin/static_server.rb +24 -24
- data/lib/jekyll-admin/urlable.rb +71 -67
- data/lib/jekyll-admin/version.rb +3 -3
- data/lib/jekyll/commands/serve.rb +28 -28
- metadata +24 -33
@@ -1,57 +1,57 @@
|
|
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
|
+
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,82 +1,82 @@
|
|
1
|
-
module JekyllAdmin
|
2
|
-
class Server < Sinatra::Base
|
3
|
-
# supported extensions, in order of preference, for now, no .csv
|
4
|
-
EXTENSIONS = %w(yml json).freeze
|
5
|
-
|
6
|
-
namespace "/data" do
|
7
|
-
get "/*?/?:path.:ext" do
|
8
|
-
ensure_requested_file
|
9
|
-
json requested_file.to_api(:include_content => true)
|
10
|
-
end
|
11
|
-
|
12
|
-
get "/?*" do
|
13
|
-
ensure_directory
|
14
|
-
json entries.map(&:to_api)
|
15
|
-
end
|
16
|
-
|
17
|
-
put "/*?/?:path.:ext" do
|
18
|
-
if renamed?
|
19
|
-
ensure_requested_file
|
20
|
-
delete_file_without_process path
|
21
|
-
end
|
22
|
-
|
23
|
-
write_file write_path, data_file_body
|
24
|
-
json written_file.to_api(:include_content => true)
|
25
|
-
end
|
26
|
-
|
27
|
-
delete "/*?/?:path.:ext" do
|
28
|
-
ensure_requested_file
|
29
|
-
delete_file path
|
30
|
-
content_type :json
|
31
|
-
status 200
|
32
|
-
halt
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
# returns relative path of root level directories that contain data files
|
38
|
-
def directory_paths
|
39
|
-
DataFile.all.map { |p| File.dirname(p.relative_path).split("/")[0] }.uniq
|
40
|
-
end
|
41
|
-
|
42
|
-
def directory_pages
|
43
|
-
DataFile.all.find_all do |p|
|
44
|
-
sanitized_path(File.dirname(p.path)) == directory_path
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def entries
|
49
|
-
args = {
|
50
|
-
:base => sanitized_path(DataFile.data_dir),
|
51
|
-
:content_type => "data",
|
52
|
-
:splat => splats.first,
|
53
|
-
}
|
54
|
-
# get all directories inside the requested directory
|
55
|
-
directory = JekyllAdmin::Directory.new(directory_path, args)
|
56
|
-
directories = directory.directories
|
57
|
-
|
58
|
-
# exclude root level directories which do not have data files
|
59
|
-
if splats.first.empty?
|
60
|
-
directories = directories.select do |d|
|
61
|
-
directory_paths.include? d.name.to_s
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# merge directories with the pages at the same level
|
66
|
-
directories.concat(directory_pages)
|
67
|
-
end
|
68
|
-
|
69
|
-
def data_file_body
|
70
|
-
if !request_payload["raw_content"].to_s.empty?
|
71
|
-
request_payload["raw_content"]
|
72
|
-
elsif !request_payload["content"].to_s.empty?
|
73
|
-
YAML.dump(request_payload["content"]).sub(%r!\A---\n!, "")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def splats
|
78
|
-
params["splat"] || ["/"]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
1
|
+
module JekyllAdmin
|
2
|
+
class Server < Sinatra::Base
|
3
|
+
# supported extensions, in order of preference, for now, no .csv
|
4
|
+
EXTENSIONS = %w(yml json).freeze
|
5
|
+
|
6
|
+
namespace "/data" do
|
7
|
+
get "/*?/?:path.:ext" do
|
8
|
+
ensure_requested_file
|
9
|
+
json requested_file.to_api(:include_content => true)
|
10
|
+
end
|
11
|
+
|
12
|
+
get "/?*" do
|
13
|
+
ensure_directory
|
14
|
+
json entries.map(&:to_api)
|
15
|
+
end
|
16
|
+
|
17
|
+
put "/*?/?:path.:ext" do
|
18
|
+
if renamed?
|
19
|
+
ensure_requested_file
|
20
|
+
delete_file_without_process path
|
21
|
+
end
|
22
|
+
|
23
|
+
write_file write_path, data_file_body
|
24
|
+
json written_file.to_api(:include_content => true)
|
25
|
+
end
|
26
|
+
|
27
|
+
delete "/*?/?:path.:ext" do
|
28
|
+
ensure_requested_file
|
29
|
+
delete_file path
|
30
|
+
content_type :json
|
31
|
+
status 200
|
32
|
+
halt
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# returns relative path of root level directories that contain data files
|
38
|
+
def directory_paths
|
39
|
+
DataFile.all.map { |p| File.dirname(p.relative_path).split("/")[0] }.uniq
|
40
|
+
end
|
41
|
+
|
42
|
+
def directory_pages
|
43
|
+
DataFile.all.find_all do |p|
|
44
|
+
sanitized_path(File.dirname(p.path)) == directory_path
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def entries
|
49
|
+
args = {
|
50
|
+
:base => sanitized_path(DataFile.data_dir),
|
51
|
+
:content_type => "data",
|
52
|
+
:splat => splats.first,
|
53
|
+
}
|
54
|
+
# get all directories inside the requested directory
|
55
|
+
directory = JekyllAdmin::Directory.new(directory_path, args)
|
56
|
+
directories = directory.directories
|
57
|
+
|
58
|
+
# exclude root level directories which do not have data files
|
59
|
+
if splats.first.empty?
|
60
|
+
directories = directories.select do |d|
|
61
|
+
directory_paths.include? d.name.to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# merge directories with the pages at the same level
|
66
|
+
directories.concat(directory_pages)
|
67
|
+
end
|
68
|
+
|
69
|
+
def data_file_body
|
70
|
+
if !request_payload["raw_content"].to_s.empty?
|
71
|
+
request_payload["raw_content"]
|
72
|
+
elsif !request_payload["content"].to_s.empty?
|
73
|
+
YAML.dump(request_payload["content"]).sub(%r!\A---\n!, "")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def splats
|
78
|
+
params["splat"] || ["/"]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -1,110 +1,109 @@
|
|
1
|
-
module JekyllAdmin
|
2
|
-
class Server < Sinatra::Base
|
3
|
-
namespace "/drafts" do
|
4
|
-
get "/*?/?:path.:ext" do
|
5
|
-
ensure_requested_file
|
6
|
-
json requested_file.to_api(:include_content => true)
|
7
|
-
end
|
8
|
-
|
9
|
-
get "/?*" do
|
10
|
-
ensure_directory
|
11
|
-
json entries.map(&:to_api)
|
12
|
-
end
|
13
|
-
|
14
|
-
put "/*?/?:path.:ext" do
|
15
|
-
ensure_html_content
|
16
|
-
|
17
|
-
if renamed?
|
18
|
-
ensure_requested_file
|
19
|
-
delete_file_without_process path
|
20
|
-
end
|
21
|
-
|
22
|
-
write_file write_path, document_body
|
23
|
-
json written_file.to_api(:include_content => true)
|
24
|
-
end
|
25
|
-
|
26
|
-
delete "/*?/?:path.:ext" do
|
27
|
-
ensure_requested_file
|
28
|
-
delete_file path
|
29
|
-
content_type :json
|
30
|
-
status 200
|
31
|
-
halt
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
# return all documents in the 'posts' collection that output to an html
|
37
|
-
# file but reside in a separate directory, `<source_dir>/_drafts/`
|
38
|
-
def drafts
|
39
|
-
posts = site.collections.find { |l, _c| l == "posts" }
|
40
|
-
if posts
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
:
|
81
|
-
:
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
site,
|
101
|
-
|
102
|
-
"
|
103
|
-
|
104
|
-
|
105
|
-
draft.
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
1
|
+
module JekyllAdmin
|
2
|
+
class Server < Sinatra::Base
|
3
|
+
namespace "/drafts" do
|
4
|
+
get "/*?/?:path.:ext" do
|
5
|
+
ensure_requested_file
|
6
|
+
json requested_file.to_api(:include_content => true)
|
7
|
+
end
|
8
|
+
|
9
|
+
get "/?*" do
|
10
|
+
ensure_directory
|
11
|
+
json entries.map(&:to_api)
|
12
|
+
end
|
13
|
+
|
14
|
+
put "/*?/?:path.:ext" do
|
15
|
+
ensure_html_content
|
16
|
+
|
17
|
+
if renamed?
|
18
|
+
ensure_requested_file
|
19
|
+
delete_file_without_process path
|
20
|
+
end
|
21
|
+
|
22
|
+
write_file write_path, document_body
|
23
|
+
json written_file.to_api(:include_content => true)
|
24
|
+
end
|
25
|
+
|
26
|
+
delete "/*?/?:path.:ext" do
|
27
|
+
ensure_requested_file
|
28
|
+
delete_file path
|
29
|
+
content_type :json
|
30
|
+
status 200
|
31
|
+
halt
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# return all documents in the 'posts' collection that output to an html
|
37
|
+
# file but reside in a separate directory, `<source_dir>/_drafts/`
|
38
|
+
def drafts
|
39
|
+
posts = site.collections.find { |l, _c| l == "posts" }
|
40
|
+
posts[1].docs.find_all { |d| d.output_ext == ".html" && d.draft? } if posts
|
41
|
+
end
|
42
|
+
|
43
|
+
# return drafts at the same level as directory
|
44
|
+
def directory_drafts
|
45
|
+
drafts.find_all { |d| File.dirname(d.path) == directory_path }
|
46
|
+
end
|
47
|
+
|
48
|
+
def reverse_sorted_drafts
|
49
|
+
directory_drafts.sort_by(&:date).reverse
|
50
|
+
end
|
51
|
+
|
52
|
+
# returns directories at the root of `/_drafts/` that contain drafts
|
53
|
+
def relevant_directory_paths
|
54
|
+
drafts.map { |doc| relative_draft_path(doc).split("/")[0] }.uniq
|
55
|
+
end
|
56
|
+
|
57
|
+
def relative_draft_path(document)
|
58
|
+
File.dirname(document.relative_path.sub("_drafts/", ""))
|
59
|
+
end
|
60
|
+
|
61
|
+
def ensure_directory
|
62
|
+
ensure_drafts
|
63
|
+
render_404 unless Dir.exist?(directory_path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def ensure_drafts
|
67
|
+
render_404 if drafts.nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
def ensure_html_content
|
71
|
+
return if html_content?
|
72
|
+
|
73
|
+
content_type :json
|
74
|
+
halt 422, json("error_message" => "Invalid file extension for drafts")
|
75
|
+
end
|
76
|
+
|
77
|
+
def entries
|
78
|
+
args = {
|
79
|
+
:base => site.source,
|
80
|
+
:content_type => "drafts",
|
81
|
+
:splat => params["splat"].first,
|
82
|
+
}
|
83
|
+
# get the directories inside the requested directory
|
84
|
+
directory = JekyllAdmin::Directory.new(directory_path, args)
|
85
|
+
directories = directory.directories
|
86
|
+
|
87
|
+
# exclude root level directories which do not have drafts
|
88
|
+
if params["splat"].first.empty?
|
89
|
+
directories = directories.select do |d|
|
90
|
+
relevant_directory_paths.include? d.name.to_s
|
91
|
+
end
|
92
|
+
end
|
93
|
+
# merge directories with the drafts at the same level
|
94
|
+
directories.concat(reverse_sorted_drafts)
|
95
|
+
end
|
96
|
+
|
97
|
+
def html_content?
|
98
|
+
draft = JekyllAdmin::PageWithoutAFile.new(
|
99
|
+
site,
|
100
|
+
site.source,
|
101
|
+
"_drafts",
|
102
|
+
request_payload["path"] || filename
|
103
|
+
)
|
104
|
+
draft.data = request_payload["front_matter"]
|
105
|
+
draft.html?
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|