Skip to content

Commit

Permalink
Add option to change homepage (#617)
Browse files Browse the repository at this point in the history
* Add option to change homepage

* Fix typo

* Add other routes for homepage as well
  • Loading branch information
mertkahyaoglu committed Dec 6, 2020
1 parent 26700ea commit 3580e32
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -40,6 +38,7 @@ jekyll_admin:
- staticfiles
- datafiles
- configuration
homepage: "pages"
```

### Customizing collection label in Sidebar
Expand Down
12 changes: 12 additions & 0 deletions docs/configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`, `<collection_name>`,
`datafiles`, `staticfiles` ,`drafts` and `configuration`

```yaml
jekyll_admin:
homepage: "posts"
```
3 changes: 3 additions & 0 deletions spec/fixtures/site/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ collections:
puppies:
foo: bar
output: false

jekyll_admin:
homepage: "posts"
36 changes: 36 additions & 0 deletions src/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;

Expand Down

0 comments on commit 3580e32

Please sign in to comment.