-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import site metadata into admin interface (#543)
To allow selecting existing categories, layouts and tags via the interface. The idea is to fetch the *data* related to above every time a page / draft / document is created / edited so that the `Metafields` component always reflects the latest status (i.e. a category added to one post will be available for the next post being edited).
- Loading branch information
Showing
7 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module JekyllAdmin | ||
class Server < Sinatra::Base | ||
# Jekyll::Site instance method names that return a Hash. | ||
META_KEYS = [:categories, :layouts, :tags].freeze | ||
private_constant :META_KEYS | ||
|
||
namespace "/site_meta" do | ||
get "/?" do | ||
json site_meta | ||
end | ||
|
||
private | ||
|
||
# Stash a Hash generated with pre-determined keys. | ||
def site_meta | ||
@site_meta ||= META_KEYS.zip(META_KEYS.map { |k| site.send(k).keys }).to_h | ||
end | ||
|
||
# Reset memoization of `#site_meta` when the site regenerates | ||
Jekyll::Hooks.register(:site, :after_reset) { @site_meta = nil } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { getSiteMetaUrl } from '../constants/api'; | ||
import { get } from '../utils/fetch'; | ||
|
||
// Action Types | ||
export const FETCH_SITE_META_REQUEST = 'FETCH_SITE_META_REQUEST'; | ||
export const FETCH_SITE_META_SUCCESS = 'FETCH_SITE_META_SUCCESS'; | ||
export const FETCH_SITE_META_FAILURE = 'FETCH_SITE_META_FAILURE'; | ||
|
||
// Actions | ||
export const fetchSiteMeta = () => dispatch => { | ||
dispatch({ type: FETCH_SITE_META_REQUEST }); | ||
return get( | ||
getSiteMetaUrl(), | ||
{ type: FETCH_SITE_META_SUCCESS, name: 'site' }, | ||
{ type: FETCH_SITE_META_FAILURE, name: 'error' }, | ||
dispatch | ||
); | ||
}; | ||
|
||
// Reducer | ||
export default function siteMeta( | ||
state = { | ||
site: {}, | ||
isFetching: false, | ||
}, | ||
action | ||
) { | ||
switch (action.type) { | ||
case FETCH_SITE_META_REQUEST: | ||
return { | ||
...state, | ||
isFetching: true, | ||
}; | ||
case FETCH_SITE_META_SUCCESS: | ||
return { | ||
...state, | ||
site: action.site, | ||
isFetching: false, | ||
}; | ||
case FETCH_SITE_META_FAILURE: | ||
return { | ||
...state, | ||
isFetching: false, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |