diff --git a/README.md b/README.md index a24a90ec0..7cf74d6c9 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,7 @@ Refer to the [installing plugins](https://jekyllrb.com/docs/plugins/installation ## Options -Jekyll Admin related options can be specified in `_config.yml` -under a key called `jekyll_admin`. Currently it has only one option `hidden_links` -which is for hiding unwanted links on the sidebar. The following keys under `hidden_links` can be used in order to hide default links; +Jekyll Admin related options can be specified in `_config.yml` under a key called `jekyll_admin`. ```yaml jekyll_admin: @@ -40,6 +38,7 @@ jekyll_admin: - staticfiles - datafiles - configuration + homepage: "pages" ``` ### Customizing collection label in Sidebar diff --git a/docs/configs.md b/docs/configs.md index 777b78ae2..db636c3e1 100644 --- a/docs/configs.md +++ b/docs/configs.md @@ -23,3 +23,15 @@ jekyll_admin: - datafiles - configuration ``` + +#### `homepage` + +Web page set as the default or start-up page for Jekyll Admin. + +Valid values for `homepage`: `pages` (default), `posts`, ``, +`datafiles`, `staticfiles` ,`drafts` and `configuration` + +```yaml +jekyll_admin: + homepage: "posts" +``` diff --git a/spec/fixtures/site/_config.yml b/spec/fixtures/site/_config.yml index 072677b00..17aa0e5f6 100644 --- a/spec/fixtures/site/_config.yml +++ b/spec/fixtures/site/_config.yml @@ -96,3 +96,6 @@ collections: puppies: foo: bar output: false + +jekyll_admin: + homepage: "posts" diff --git a/src/containers/App.js b/src/containers/App.js index 5c32dbac1..4243a8c05 100644 --- a/src/containers/App.js +++ b/src/containers/App.js @@ -7,6 +7,7 @@ import DocumentTitle from 'react-document-title'; import { fetchConfig } from '../ducks/config'; import keyboardShortcuts from '../constants/keyboardShortcuts'; +import { ADMIN_PREFIX } from '../constants'; // Components import Sidebar from './Sidebar'; @@ -26,6 +27,41 @@ class App extends Component { } } + componentDidUpdate(prevProps) { + if (prevProps.isFetching && !this.props.isFetching) { + const { + config: { + content: { + jekyll_admin: { homepage }, + collections, + }, + }, + router, + } = this.props; + + const currentPathname = router.getCurrentLocation().pathname; + + if (homepage && currentPathname === ADMIN_PREFIX) { + let url = `${ADMIN_PREFIX}/pages`; + + const collectionNames = Object.keys(collections).concat('posts'); + if (collectionNames.includes(homepage)) { + url = `${ADMIN_PREFIX}/collections/${homepage}`; + } + + if ( + ['drafts', 'datafiles', 'staticfiles', 'configuration'].includes( + homepage + ) + ) { + url = `${ADMIN_PREFIX}/${homepage}`; + } + + router.replace(url); + } + } + } + render() { const { config, isFetching } = this.props;