jekyll-admin 0.8.1 → 0.9.0
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 +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,90 +1,91 @@
|
|
1
|
-
module JekyllAdmin
|
2
|
-
class Server < Sinatra::Base
|
3
|
-
namespace "/pages" 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, page_body
|
23
|
-
|
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
|
-
def ensure_html_content
|
38
|
-
return if html_content?
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
site
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
page.
|
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
|
-
directories
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
1
|
+
module JekyllAdmin
|
2
|
+
class Server < Sinatra::Base
|
3
|
+
namespace "/pages" 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, page_body
|
23
|
+
|
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
|
+
def ensure_html_content
|
38
|
+
return if html_content?
|
39
|
+
|
40
|
+
content_type :json
|
41
|
+
halt 422, json("error_message" => "Invalid file extension for pages")
|
42
|
+
end
|
43
|
+
|
44
|
+
def html_content?
|
45
|
+
page = JekyllAdmin::PageWithoutAFile.new(
|
46
|
+
site,
|
47
|
+
site.source,
|
48
|
+
"",
|
49
|
+
request_payload["path"] || filename
|
50
|
+
)
|
51
|
+
page.data = request_payload["front_matter"]
|
52
|
+
page.html?
|
53
|
+
end
|
54
|
+
|
55
|
+
def pages
|
56
|
+
site.pages.select(&:html?)
|
57
|
+
end
|
58
|
+
|
59
|
+
def directory_pages
|
60
|
+
pages.find_all do |p|
|
61
|
+
sanitized_path(File.dirname(p.path)) == directory_path
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# returns relative path of root level directories that contain pages
|
66
|
+
def directory_paths
|
67
|
+
pages.map { |p| File.dirname(p.path).split("/")[0] }.uniq
|
68
|
+
end
|
69
|
+
|
70
|
+
def entries
|
71
|
+
args = {
|
72
|
+
:base => site.source,
|
73
|
+
:content_type => "pages",
|
74
|
+
:splat => params["splat"].first,
|
75
|
+
}
|
76
|
+
# get all directories inside the requested directory
|
77
|
+
directory = JekyllAdmin::Directory.new(directory_path, args)
|
78
|
+
directories = directory.directories
|
79
|
+
|
80
|
+
# exclude root level directories which do not have pages
|
81
|
+
if params["splat"].first.empty?
|
82
|
+
directories = directories.select do |d|
|
83
|
+
directory_paths.include? d.name.to_s
|
84
|
+
end
|
85
|
+
end
|
86
|
+
# merge directories with the pages at the same level
|
87
|
+
directories.concat(directory_pages)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,61 +1,61 @@
|
|
1
|
-
module JekyllAdmin
|
2
|
-
class Server < Sinatra::Base
|
3
|
-
namespace "/static_files" do
|
4
|
-
get do
|
5
|
-
json static_files.map(&:to_api)
|
6
|
-
end
|
7
|
-
|
8
|
-
get "/*" do
|
9
|
-
if requested_file
|
10
|
-
json requested_file.to_api(:include_content => true)
|
11
|
-
elsif !static_files_for_path.empty?
|
12
|
-
json static_files_for_path.map(&:to_api)
|
13
|
-
else
|
14
|
-
render_404
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
put "/*" do
|
19
|
-
if renamed?
|
20
|
-
ensure_requested_file
|
21
|
-
delete_file_without_process path
|
22
|
-
end
|
23
|
-
|
24
|
-
write_file(write_path, static_file_body)
|
25
|
-
json written_file.to_api(:include_content => true)
|
26
|
-
end
|
27
|
-
|
28
|
-
delete "/*" do
|
29
|
-
ensure_requested_file
|
30
|
-
delete_file path
|
31
|
-
content_type :json
|
32
|
-
status 200
|
33
|
-
halt
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def static_file_body
|
39
|
-
if !request_payload["raw_content"].to_s.empty?
|
40
|
-
request_payload["raw_content"].to_s
|
41
|
-
else
|
42
|
-
Base64.decode64 request_payload["encoded_content"].to_s
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def static_files
|
47
|
-
site.static_files
|
48
|
-
end
|
49
|
-
|
50
|
-
def file_list_dir(path) end
|
51
|
-
|
52
|
-
def static_files_for_path
|
53
|
-
# Joined with / to ensure user can't do partial paths
|
54
|
-
base_path = File.join(path, "/")
|
55
|
-
static_files.select do |f|
|
56
|
-
f.path.start_with? base_path
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
1
|
+
module JekyllAdmin
|
2
|
+
class Server < Sinatra::Base
|
3
|
+
namespace "/static_files" do
|
4
|
+
get do
|
5
|
+
json static_files.map(&:to_api)
|
6
|
+
end
|
7
|
+
|
8
|
+
get "/*" do
|
9
|
+
if requested_file
|
10
|
+
json requested_file.to_api(:include_content => true)
|
11
|
+
elsif !static_files_for_path.empty?
|
12
|
+
json static_files_for_path.map(&:to_api)
|
13
|
+
else
|
14
|
+
render_404
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
put "/*" do
|
19
|
+
if renamed?
|
20
|
+
ensure_requested_file
|
21
|
+
delete_file_without_process path
|
22
|
+
end
|
23
|
+
|
24
|
+
write_file(write_path, static_file_body)
|
25
|
+
json written_file.to_api(:include_content => true)
|
26
|
+
end
|
27
|
+
|
28
|
+
delete "/*" do
|
29
|
+
ensure_requested_file
|
30
|
+
delete_file path
|
31
|
+
content_type :json
|
32
|
+
status 200
|
33
|
+
halt
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def static_file_body
|
39
|
+
if !request_payload["raw_content"].to_s.empty?
|
40
|
+
request_payload["raw_content"].to_s
|
41
|
+
else
|
42
|
+
Base64.decode64 request_payload["encoded_content"].to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def static_files
|
47
|
+
site.static_files
|
48
|
+
end
|
49
|
+
|
50
|
+
def file_list_dir(path) end
|
51
|
+
|
52
|
+
def static_files_for_path
|
53
|
+
# Joined with / to ensure user can't do partial paths
|
54
|
+
base_path = File.join(path, "/")
|
55
|
+
static_files.select do |f|
|
56
|
+
f.path.start_with? base_path
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
module JekyllAdmin
|
2
|
-
class StaticServer < Sinatra::Base
|
3
|
-
set :public_dir, File.expand_path("./public", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
MUST_BUILD_MESSAGE = "Front end not yet built. Run `script/build` to build.".freeze
|
6
|
-
|
7
|
-
# Allow `/admin` and `/admin/`, and `/admin/*` to serve `/public/dist/index.html`
|
8
|
-
get "/*" do
|
9
|
-
send_file index_path
|
10
|
-
end
|
11
|
-
|
12
|
-
# Provide a descriptive error message in dev. if frontend is not build
|
13
|
-
not_found do
|
14
|
-
status 404
|
15
|
-
MUST_BUILD_MESSAGE if settings.development? || settings.test?
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def index_path
|
21
|
-
@index_path ||= File.join(settings.public_folder, "index.html")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
module JekyllAdmin
|
2
|
+
class StaticServer < Sinatra::Base
|
3
|
+
set :public_dir, File.expand_path("./public", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
MUST_BUILD_MESSAGE = "Front end not yet built. Run `script/build` to build.".freeze
|
6
|
+
|
7
|
+
# Allow `/admin` and `/admin/`, and `/admin/*` to serve `/public/dist/index.html`
|
8
|
+
get "/*" do
|
9
|
+
send_file index_path
|
10
|
+
end
|
11
|
+
|
12
|
+
# Provide a descriptive error message in dev. if frontend is not build
|
13
|
+
not_found do
|
14
|
+
status 404
|
15
|
+
MUST_BUILD_MESSAGE if settings.development? || settings.test?
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def index_path
|
21
|
+
@index_path ||= File.join(settings.public_folder, "index.html")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/jekyll-admin/urlable.rb
CHANGED
@@ -1,67 +1,71 @@
|
|
1
|
-
module JekyllAdmin
|
2
|
-
# Abstract module to be included in Convertible and Document to provide
|
3
|
-
# additional, URL-specific functionality without duplicating logic
|
4
|
-
module URLable
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
return if is_a?(Jekyll::
|
9
|
-
|
10
|
-
@http_url ||= Addressable::URI.new(
|
11
|
-
:scheme => scheme, :host => host, :port => port,
|
12
|
-
:path => path_with_base(JekyllAdmin.site.config["baseurl"], url)
|
13
|
-
).normalize.to_s
|
14
|
-
end
|
15
|
-
|
16
|
-
# Absolute URL to the API representation of this resource
|
17
|
-
def api_url
|
18
|
-
@api_url ||= Addressable::URI.new(
|
19
|
-
:scheme => scheme, :host => host, :port => port,
|
20
|
-
:path => path_with_base("/_api", resource_path)
|
21
|
-
).normalize.to_s
|
22
|
-
end
|
23
|
-
|
24
|
-
def entries_url
|
25
|
-
return unless is_a?(Jekyll::Collection)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
def
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
def
|
60
|
-
JekyllAdmin.site.config["
|
61
|
-
end
|
62
|
-
|
63
|
-
def
|
64
|
-
JekyllAdmin.site.config["
|
65
|
-
end
|
66
|
-
|
67
|
-
|
1
|
+
module JekyllAdmin
|
2
|
+
# Abstract module to be included in Convertible and Document to provide
|
3
|
+
# additional, URL-specific functionality without duplicating logic
|
4
|
+
module URLable
|
5
|
+
# Absolute URL to the HTTP(S) rendered/served representation of this resource
|
6
|
+
def http_url
|
7
|
+
return if is_a?(Jekyll::Collection) || is_a?(JekyllAdmin::DataFile)
|
8
|
+
return if is_a?(Jekyll::Document) && !collection.write?
|
9
|
+
|
10
|
+
@http_url ||= Addressable::URI.new(
|
11
|
+
:scheme => scheme, :host => host, :port => port,
|
12
|
+
:path => path_with_base(JekyllAdmin.site.config["baseurl"], url)
|
13
|
+
).normalize.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
# Absolute URL to the API representation of this resource
|
17
|
+
def api_url
|
18
|
+
@api_url ||= Addressable::URI.new(
|
19
|
+
:scheme => scheme, :host => host, :port => port,
|
20
|
+
:path => path_with_base("/_api", resource_path)
|
21
|
+
).normalize.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def entries_url
|
25
|
+
return unless is_a?(Jekyll::Collection)
|
26
|
+
|
27
|
+
"#{api_url}/entries"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# URL path relative to `_api/` to retreive the given resource via the API
|
33
|
+
# Note: we can't use a case statement here, because === doesn't like includes
|
34
|
+
#
|
35
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
36
|
+
def resource_path
|
37
|
+
if is_a?(Jekyll::Document) && draft?
|
38
|
+
"/#{relative_path.sub(%r!\A_!, "")}"
|
39
|
+
elsif is_a?(Jekyll::Document)
|
40
|
+
"/collections/#{relative_path.sub(%r!\A_!, "")}"
|
41
|
+
elsif is_a?(Jekyll::Collection)
|
42
|
+
"/collections/#{label}"
|
43
|
+
elsif is_a?(JekyllAdmin::DataFile)
|
44
|
+
"/data/#{relative_path}"
|
45
|
+
elsif is_a?(Jekyll::StaticFile)
|
46
|
+
"/static_files/#{relative_path}"
|
47
|
+
elsif is_a?(Jekyll::Page)
|
48
|
+
"/pages/#{relative_path}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
52
|
+
|
53
|
+
# URI.join doesn't like joining two relative paths, and File.join may join
|
54
|
+
# with `\` rather than with `/` on windows
|
55
|
+
def path_with_base(base, path)
|
56
|
+
[base, path].join("/").squeeze("/")
|
57
|
+
end
|
58
|
+
|
59
|
+
def scheme
|
60
|
+
JekyllAdmin.site.config["scheme"] || "http"
|
61
|
+
end
|
62
|
+
|
63
|
+
def host
|
64
|
+
JekyllAdmin.site.config["host"].sub("127.0.0.1", "localhost")
|
65
|
+
end
|
66
|
+
|
67
|
+
def port
|
68
|
+
JekyllAdmin.site.config["port"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|