Skip to content

Commit 3580e32

Browse files
Add option to change homepage (#617)
* Add option to change homepage * Fix typo * Add other routes for homepage as well
1 parent 26700ea commit 3580e32

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ Refer to the [installing plugins](https://jekyllrb.com/docs/plugins/installation
2828

2929
## Options
3030

31-
Jekyll Admin related options can be specified in `_config.yml`
32-
under a key called `jekyll_admin`. Currently it has only one option `hidden_links`
33-
which is for hiding unwanted links on the sidebar. The following keys under `hidden_links` can be used in order to hide default links;
31+
Jekyll Admin related options can be specified in `_config.yml` under a key called `jekyll_admin`.
3432

3533
```yaml
3634
jekyll_admin:
@@ -40,6 +38,7 @@ jekyll_admin:
4038
- staticfiles
4139
- datafiles
4240
- configuration
41+
homepage: "pages"
4342
```
4443

4544
### Customizing collection label in Sidebar

docs/configs.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,15 @@ jekyll_admin:
2323
- datafiles
2424
- configuration
2525
```
26+
27+
#### `homepage`
28+
29+
Web page set as the default or start-up page for Jekyll Admin.
30+
31+
Valid values for `homepage`: `pages` (default), `posts`, `<collection_name>`,
32+
`datafiles`, `staticfiles` ,`drafts` and `configuration`
33+
34+
```yaml
35+
jekyll_admin:
36+
homepage: "posts"
37+
```

spec/fixtures/site/_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ collections:
9696
puppies:
9797
foo: bar
9898
output: false
99+
100+
jekyll_admin:
101+
homepage: "posts"

src/containers/App.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import DocumentTitle from 'react-document-title';
77

88
import { fetchConfig } from '../ducks/config';
99
import keyboardShortcuts from '../constants/keyboardShortcuts';
10+
import { ADMIN_PREFIX } from '../constants';
1011

1112
// Components
1213
import Sidebar from './Sidebar';
@@ -26,6 +27,41 @@ class App extends Component {
2627
}
2728
}
2829

30+
componentDidUpdate(prevProps) {
31+
if (prevProps.isFetching && !this.props.isFetching) {
32+
const {
33+
config: {
34+
content: {
35+
jekyll_admin: { homepage },
36+
collections,
37+
},
38+
},
39+
router,
40+
} = this.props;
41+
42+
const currentPathname = router.getCurrentLocation().pathname;
43+
44+
if (homepage && currentPathname === ADMIN_PREFIX) {
45+
let url = `${ADMIN_PREFIX}/pages`;
46+
47+
const collectionNames = Object.keys(collections).concat('posts');
48+
if (collectionNames.includes(homepage)) {
49+
url = `${ADMIN_PREFIX}/collections/${homepage}`;
50+
}
51+
52+
if (
53+
['drafts', 'datafiles', 'staticfiles', 'configuration'].includes(
54+
homepage
55+
)
56+
) {
57+
url = `${ADMIN_PREFIX}/${homepage}`;
58+
}
59+
60+
router.replace(url);
61+
}
62+
}
63+
}
64+
2965
render() {
3066
const { config, isFetching } = this.props;
3167

0 commit comments

Comments
 (0)