-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/configinlink #1146
Feat/configinlink #1146
Changes from 12 commits
4979c64
05348f6
7d9906b
adcc171
6ec83cd
e44c79f
d118c54
5c1cfb3
68518fa
a888f39
9d4a8a1
681f98d
4d2d3a9
3d7bd0b
c75061d
c738a82
6348f0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import yaml from "js-yaml"; | ||
import { Map, List, fromJS } from "immutable"; | ||
import { trimStart, flow, isBoolean } from "lodash"; | ||
import { trimStart, flow, isBoolean, get } from "lodash"; | ||
import { authenticateUser } from "Actions/auth"; | ||
import * as publishModes from "Constants/publishModes"; | ||
|
||
|
@@ -9,6 +9,13 @@ export const CONFIG_SUCCESS = "CONFIG_SUCCESS"; | |
export const CONFIG_FAILURE = "CONFIG_FAILURE"; | ||
export const CONFIG_MERGE = "CONFIG_MERGE"; | ||
|
||
const getConfigUrl = () => { | ||
const validTypes = { 'text/yaml': 'yaml', 'application/x-yaml': 'yaml' }; | ||
const configLink = document.querySelector('link[rel="cms-config-url"]'); | ||
const isValidType = link => link && validTypes[link.type]; | ||
return isValidType(configLink) ? get(configLink, 'href') : 'config.yml'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns an empty path for the default if the user supplies a link without an href. It really should return 'config.yml' on any invalid form of the link. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proposed:
|
||
} | ||
|
||
const defaults = { | ||
publish_mode: publishModes.SIMPLE, | ||
}; | ||
|
@@ -130,7 +137,9 @@ export function loadConfig() { | |
|
||
try { | ||
const preloadedConfig = getState().config; | ||
const loadedConfig = await getConfig('config.yml', preloadedConfig && preloadedConfig.size > 1); | ||
const configUrl = getConfigUrl(); | ||
console.log(`Netlify CMS using config file: "${configUrl}"`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should clarify this a little further. Also, maybe only show it if the link exists since the default behavior is already known. So, this console.log would move into the getConfigUrl function. That way when debugging we know the link was used rather than default. Not detrimental though, just a thought.
Probably don't need to specify Netilify CMS since we already print a version on page load showing Netlify CMS There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @talves Awesome! Made the changes! |
||
const loadedConfig = await getConfig(configUrl, preloadedConfig && preloadedConfig.size > 1); | ||
|
||
/** | ||
* Merge any existing configuration so the result can be validated. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we're going to crash if there's no matching link element by attempting to access property "type" of
null
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erquhart doesn't
link && validTypes[link.type]
short circuit to false whenlink
isnull
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️🤦♂️🤦♂️
Disregard!