File tree 2 files changed +46
-1
lines changed
2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1
1
module JekyllAdmin
2
2
class Server < Sinatra ::Base
3
- ROUTES = %w( collections configuration data pages static_files ) . freeze
3
+ ROUTES = %w( collections configuration dashboard data pages static_files ) . freeze
4
4
include JekyllAdmin ::PathHelper
5
5
include JekyllAdmin ::FileHelper
6
6
@@ -86,6 +86,7 @@ def namespace
86
86
87
87
require "jekyll-admin/server/collection"
88
88
require "jekyll-admin/server/configuration"
89
+ require "jekyll-admin/server/dashboard"
89
90
require "jekyll-admin/server/data"
90
91
require "jekyll-admin/server/page"
91
92
require "jekyll-admin/server/static_file"
Original file line number Diff line number Diff line change
1
+ module JekyllAdmin
2
+ class Server < Sinatra ::Base
3
+ namespace "/dashboard" do
4
+ get do
5
+ json site . site_payload . to_h . merge ( {
6
+ "site" => dashboard_site_payload ,
7
+ } )
8
+ end
9
+
10
+ private
11
+
12
+ def dashboard_site_payload
13
+ output = site . site_payload [ "site" ] . to_h . merge ( {
14
+ "data_files" => data_files ,
15
+ "html_pages" => named_html_pages ,
16
+ "pages" => recent_pages . map { |page | page . to_api [ "path" ] } ,
17
+ "posts" => paths_to_posts ,
18
+ "collections" => site . collections . map { |c | c [ 0 ] } ,
19
+ } )
20
+
21
+ output . delete ( "documents" )
22
+ output . delete ( "data" )
23
+
24
+ output
25
+ end
26
+
27
+ def named_html_pages
28
+ site . pages . select ( &:html? ) . map { |page | page . to_api [ "name" ] }
29
+ end
30
+
31
+ def recent_pages
32
+ site . pages . sort_by! { |page | page . to_api [ "modified_at" ] } . reverse
33
+ end
34
+
35
+ def paths_to_posts
36
+ site . posts . docs . map { |post | post . relative_path . sub ( "_posts/" , "" ) }
37
+ end
38
+
39
+ def data_files
40
+ DataFile . all . map { |d | d . to_api [ "relative_path" ] . sub ( "/_data/" , "" ) }
41
+ end
42
+ end
43
+ end
44
+ end
You can’t perform that action at this time.
0 commit comments