Skip to content

Commit

Permalink
Merge branch 'master' into jmurzy-defaultTitle
Browse files Browse the repository at this point in the history
* master: (22 commits)
  Remove index.js file
  Remove babel-related dependencies
  Update README.md
  Consistent server-side test case
  Clarify comment
  Correct count in README
  Remove use of Set
  Revert iteration changes
  Remove Object.keys polyfill (supported since IE9)
  Remove Array.includes polyfill
  Remove Object.is polyfill
  Remove Map polyfill
  Bump eslint
  Use undefined for valueless attributes
  Add support for html attributes
  Add example in Readme
  Add tests for script.innerHTML
  Handle innerHTML attribute validation
  Fix eslint warnings / errors
  Update babel-eslint
  ...
  • Loading branch information
jmurzy committed Mar 24, 2016
2 parents 843a320 + 7759902 commit be8fb1a
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 124 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function Application () {
return (
<div className="application">
<Helmet
htmlAttributes={{"lang": "en", "amp": undefined}} // amp takes no value
title="My Title"
titleTemplate="MySite.com - %s"
base={{"target": "_blank", "href": "http://mysite.com/"}}
Expand All @@ -59,7 +60,8 @@ export default function Application () {
{"rel": "apple-touch-icon", "sizes": "72x72", "href": "http://mysite.com/img/apple-touch-icon-72x72.png"}
]}
script={[
{"src": "http://include.com/pathtojs.js", "type": "text/javascript"}
{"src": "http://include.com/pathtojs.js", "type": "text/javascript"},
{"type": "application/ld+json", innerHTML: `{ "@context": "http://schema.org" }`}
]}
onChangeClientState={(newState) => console.log(newState)}
/>
Expand Down Expand Up @@ -88,23 +90,30 @@ To use on the server, call `rewind()` after `ReactDOM.renderToString` or `ReactD
ReactDOM.renderToString(<Handler />);
let head = Helmet.rewind();

head.htmlAttributes
head.title
head.base
head.meta
head.link
head.script
```

`head` contains five possible properties, `title`, `base`, `meta`, `link`, `script`:
`head` contains six possible properties:
- `htmlAttributes`
- `title`
- `base`
- `meta`
- `link`
- `script`

- Each property contains `toComponent()` and `toString()` methods. Use whichever is appropriate for your environment. E.g:
Each property contains `toComponent()` and `toString()` methods. Use whichever is appropriate for your environment. For htmlAttributes, use the JSX spread operator on the object returned by `toComponent()`. E.g:

### As string output
```javascript
const html = `
<!doctype html>
<html>
<head>
<head ${head.htmlAttributes.toString()}>
${head.title.toString()}
${head.meta.toString()}
${head.link.toString()}
Expand All @@ -121,8 +130,10 @@ const html = `
### As React components
```javascript
function HTML () {
const attrs = head.htmlAttributes.toComponent();

return (
<html>
<html {...attrs}>
<head>
{head.title.toComponent()}
{head.meta.toComponent()}
Expand Down
1 change: 1 addition & 0 deletions config/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = function (gulp, config) {
if (data.message) {
return "(" + data.line + ":" + data.column + ") " + data.message;
}
return null;
}).join("\n");

var errorString = file.relative + " (" + file.eslint.messages.length + " errors)\n" + errors;
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-helmet",
"description": "A document head manager for React",
"version": "2.3.1",
"main": "./lib/index.js",
"main": "./lib/Helmet.js",
"author": "NFL <[email protected]>",
"contributors": [
"Chris Welch <[email protected]>"
Expand All @@ -25,27 +25,29 @@
"base"
],
"dependencies": {
"core-js": "2.0.3",
"deep-equal": "1.0.1",
"invariant": "2.2.0",
"object-assign": "^4.0.1",
"react-side-effect": "1.0.2",
"shallowequal": "0.2.2",
"warning": "2.1.0"
},
"devDependencies": {
"babel": "5.8.34",
"babel-eslint": "4.1.5",
"babel-eslint": "5.0.0",
"babel-loader": "5.4.0",
"chai": "3.4.1",
"chalk": "1.1.1",
"del": "2.2.0",
"eslint": "1.10.3",
"eslint-config-nfl": "4.0.2",
"eslint-plugin-react": "3.15.0",
"eslint": "2.4.0",
"eslint-config-nfl": "6.1.0",
"eslint-plugin-react": "4.2.2",
"estraverse": "^4.2.0",
"estraverse-fb": "^1.3.1",
"gulp": "3.9.0",
"gulp-cached": "1.1.0",
"gulp-debug": "2.1.2",
"gulp-eslint": "1.1.1",
"gulp-eslint": "2.0.0",
"gulp-if": "2.0.0",
"gulp-notify": "2.2.0",
"gulp-util": "3.0.7",
Expand Down
Loading

0 comments on commit be8fb1a

Please sign in to comment.