Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
Fixed: front matter route can use / to define the homepage (#721
Browse files Browse the repository at this point in the history
)

* Define root index of the project via `route` parameter

Fix #673

* Add tests

* Add changelog notes for #721

[skip ci]
  • Loading branch information
thangngoc89 authored and MoOx committed Sep 5, 2016
1 parent 5d28889 commit 99dba52
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,10 @@
([ref #433](https://github.com/MoOx/phenomic/issues/433) - @MoOx)
- Changed: error messages for bad configuration are now more readable
([#672](https://github.com/MoOx/phenomic/issues/672) - @MoOx)
- Fixed: front matter ``route`` can use ``/`` to define the homepage
([#721](https://github.com/MoOx/phenomic/pull/721) - @thangngoc89)
single string is passed as a child.
(@MoOx)
- Added: 🚀 Hard source Webpack plugin to improve performance by more than 300%
You can enable this **experimental** feature by add
``"webpackHardCache": true`` in your ``package.json`` ``phenomic`` section.
Expand Down
5 changes: 4 additions & 1 deletion src/components/PageContainer/component.js
Expand Up @@ -27,7 +27,10 @@ type Context = {

// react-router does not return leading and trailing slashes
// so we need to normalize according to collection data
const splatToUrl = (string) => ("/" + urlify(string))
const splatToUrl = (string) => {
const url = "/" + urlify(string)
return (url === "//") ? "/" : url
}

const isDevelopment = (): boolean => process.env.NODE_ENV !== "production"
const isClient = (): boolean => typeof window !== "undefined"
Expand Down
@@ -0,0 +1,4 @@
---
title: custom route root index
route: /
---
13 changes: 12 additions & 1 deletion src/phenomic-loader/__tests__/index.js
Expand Up @@ -86,6 +86,17 @@ test.cb("phenomic loader", (t) => {
"should create a proper json for custom route with an extension"
)

const customRouteRootIndex = stats.compilation.assets[
// fixtures/custom-route-root-index.md
// -> fixtures/index.html
"index.html" +
".8817d2a1fab9dfb9b4b52cd6ee7529ab.json"
]
t.truthy(
customRouteRootIndex && customRouteRootIndex._value,
"should create a proper json for custom route with an extension"
)

t.end()
}
)
Expand Down Expand Up @@ -140,7 +151,7 @@ test.cb("phenomic loader can be used with plugins", (t) => {
"dumb"
)
})
t.plan(2+4) // 2, err, warn, 4 => array
t.plan(2+5) // 2, err, warn, 5 => array
t.end()
}
)
Expand Down
4 changes: 3 additions & 1 deletion src/phenomic-loader/index.js
Expand Up @@ -52,13 +52,15 @@ module.exports = function(input: string) {
})
}, {})

const tmpUrl = urlify(
let tmpUrl = urlify(
pluginsResult.head && pluginsResult.head.route
// custom route
? pluginsResult.head.route
// default route
: relativePath
)
tmpUrl = (tmpUrl.substring(0, 1) === "/") ? tmpUrl.slice(1) : tmpUrl

const url = urlify(tmpUrl)
const resourceUrl = urlify(tmpUrl, true)
const contentHash = loaderUtils.getHashDigest(input)
Expand Down

0 comments on commit 99dba52

Please sign in to comment.