├── .eslintrc.js ├── .gitignore ├── .prettierrc ├── LICENSE ├── NOTICE ├── README.md ├── gatsby-browser.d.ts ├── gatsby-browser.js ├── gatsby-ssr.d.ts ├── gatsby-ssr.js ├── index.js ├── package.json ├── src ├── gatsby-browser.tsx └── gatsby-ssr.tsx ├── tsconfig.json └── yarn.lock /.eslintrc.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | module.exports = { 3 | root: true, 4 | parser: '@typescript-eslint/parser', // Specifies the ESLint parser 5 | plugins: [ 6 | '@typescript-eslint', 7 | 'import', 8 | ], 9 | extends: [ 10 | 'eslint:recommended', 11 | 'plugin:@typescript-eslint/eslint-recommended', 12 | 'plugin:@typescript-eslint/recommended', 13 | 'plugin:import/recommended', 14 | 'plugin:import/typescript', 15 | 'plugin:prettier/recommended', 16 | 'plugin:react/recommended', 17 | 'prettier', // enables eslint-plugin-prettier and eslint-config-prettier 18 | ], 19 | env: { 20 | browser: true, 21 | es2020: true, 22 | node: true, 23 | }, 24 | parserOptions: { 25 | ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features 26 | sourceType: 'module', // Allows for the use of imports 27 | ecmaFeatures: { 28 | jsx: true, // Allows for the parsing of JSX 29 | }, 30 | project: path.resolve(__dirname, './tsconfig.json'), 31 | tsconfigRootDir: __dirname, 32 | }, 33 | rules: { 34 | // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs 35 | '@typescript-eslint/explicit-function-return-type': 'off', 36 | '@typescript-eslint/no-non-null-assertion': 'warn', 37 | '@typescript-eslint/no-empty-function': 'warn', 38 | '@typescript-eslint/no-var-requires': 'warn', 39 | 'react/prop-types': 'off', 40 | '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], 41 | 'react/no-unescaped-entities': 'warn', 42 | '@typescript-eslint/ban-types': 'warn', 43 | '@typescript-eslint/explicit-module-boundary-types': 'off', 44 | 45 | // Imports 46 | 'import/no-duplicates': 'error', 47 | 'import/no-named-as-default': 'off', 48 | 'import/no-named-as-default-member': 'off', 49 | 50 | 'prettier/prettier': 'warn', 51 | }, 52 | settings: { 53 | react: { 54 | version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use 55 | }, 56 | 'import/resolver': { 57 | typescript: { 58 | alwaysTryTypes: true, 59 | project: 'tsconfig.json', 60 | }, 61 | node: { 62 | extensions: ['.ts', '.tsx'], 63 | }, 64 | }, 65 | }, 66 | }; 67 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/node,vim,visualstudiocode,webstorm,linux,macos,windows 2 | # Edit at https://www.gitignore.io/?templates=node,vim,visualstudiocode,webstorm,linux,macos,windows 3 | 4 | ################################################################################ 5 | ### Code 6 | ################################################################################ 7 | 8 | ### Node ### 9 | # Logs 10 | logs 11 | *.log 12 | npm-debug.log* 13 | yarn-debug.log* 14 | yarn-error.log* 15 | lerna-debug.log* 16 | 17 | # Diagnostic reports (https://nodejs.org/api/report.html) 18 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 19 | 20 | # Runtime data 21 | pids 22 | *.pid 23 | *.seed 24 | *.pid.lock 25 | 26 | # Directory for instrumented libs generated by jscoverage/JSCover 27 | lib-cov 28 | 29 | # Coverage directory used by tools like istanbul 30 | coverage 31 | *.lcov 32 | 33 | # nyc test coverage 34 | .nyc_output 35 | 36 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 37 | .grunt 38 | 39 | # Bower dependency directory (https://bower.io/) 40 | bower_components 41 | 42 | # node-waf configuration 43 | .lock-wscript 44 | 45 | # Compiled binary addons (https://nodejs.org/api/addons.html) 46 | build/Release 47 | 48 | # Dependency directories 49 | node_modules/ 50 | jspm_packages/ 51 | 52 | # TypeScript v1 declaration files 53 | typings/ 54 | 55 | # TypeScript cache 56 | *.tsbuildinfo 57 | 58 | # Optional npm cache directory 59 | .npm 60 | 61 | # Optional eslint cache 62 | .eslintcache 63 | 64 | # Optional REPL history 65 | .node_repl_history 66 | 67 | # Output of 'npm pack' 68 | *.tgz 69 | 70 | # Yarn Integrity file 71 | .yarn-integrity 72 | 73 | # dotenv environment variables file 74 | .env 75 | .env.test 76 | 77 | # parcel-bundler cache (https://parceljs.org/) 78 | .cache 79 | 80 | # next.js build output 81 | .next 82 | 83 | # nuxt.js build output 84 | .nuxt 85 | 86 | # react / gatsby 87 | public/ 88 | 89 | # vuepress build output 90 | .vuepress/dist 91 | 92 | # Serverless directories 93 | .serverless/ 94 | 95 | # FuseBox cache 96 | .fusebox/ 97 | 98 | # DynamoDB Local files 99 | .dynamodb/ 100 | 101 | ################################################################################ 102 | ### Development Environments 103 | ################################################################################ 104 | 105 | ### Vim ### 106 | # Swap 107 | [._]*.s[a-v][a-z] 108 | [._]*.sw[a-p] 109 | [._]s[a-rt-v][a-z] 110 | [._]ss[a-gi-z] 111 | [._]sw[a-p] 112 | 113 | # Session 114 | Session.vim 115 | Sessionx.vim 116 | 117 | # Temporary 118 | .netrwhist 119 | # Auto-generated tag files 120 | tags 121 | # Persistent undo 122 | [._]*.un~ 123 | 124 | ### VisualStudioCode ### 125 | .vscode/* 126 | !.vscode/settings.json 127 | !.vscode/tasks.json 128 | !.vscode/launch.json 129 | !.vscode/extensions.json 130 | 131 | ### VisualStudioCode Patch ### 132 | # Ignore all local history of files 133 | .history 134 | 135 | ### WebStorm ### 136 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 137 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 138 | 139 | # User-specific stuff 140 | .idea/**/workspace.xml 141 | .idea/**/tasks.xml 142 | .idea/**/usage.statistics.xml 143 | .idea/**/dictionaries 144 | .idea/**/shelf 145 | 146 | # Generated files 147 | .idea/**/contentModel.xml 148 | 149 | # Sensitive or high-churn files 150 | .idea/**/dataSources/ 151 | .idea/**/dataSources.ids 152 | .idea/**/dataSources.local.xml 153 | .idea/**/sqlDataSources.xml 154 | .idea/**/dynamic.xml 155 | .idea/**/uiDesigner.xml 156 | .idea/**/dbnavigator.xml 157 | 158 | # Gradle 159 | .idea/**/gradle.xml 160 | .idea/**/libraries 161 | 162 | # Gradle and Maven with auto-import 163 | # When using Gradle or Maven with auto-import, you should exclude module files, 164 | # since they will be recreated, and may cause churn. Uncomment if using 165 | # auto-import. 166 | # .idea/modules.xml 167 | # .idea/*.iml 168 | # .idea/modules 169 | # *.iml 170 | # *.ipr 171 | 172 | # CMake 173 | cmake-build-*/ 174 | 175 | # Mongo Explorer plugin 176 | .idea/**/mongoSettings.xml 177 | 178 | # File-based project format 179 | *.iws 180 | 181 | # IntelliJ 182 | out/ 183 | 184 | # mpeltonen/sbt-idea plugin 185 | .idea_modules/ 186 | 187 | # JIRA plugin 188 | atlassian-ide-plugin.xml 189 | 190 | # Cursive Clojure plugin 191 | .idea/replstate.xml 192 | 193 | # Crashlytics plugin (for Android Studio and IntelliJ) 194 | com_crashlytics_export_strings.xml 195 | crashlytics.properties 196 | crashlytics-build.properties 197 | fabric.properties 198 | 199 | # Editor-based Rest Client 200 | .idea/httpRequests 201 | 202 | # Android studio 3.1+ serialized cache file 203 | .idea/caches/build_file_checksums.ser 204 | 205 | ### WebStorm Patch ### 206 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 207 | 208 | # *.iml 209 | # modules.xml 210 | # .idea/misc.xml 211 | # *.ipr 212 | 213 | # Sonarlint plugin 214 | .idea/**/sonarlint/ 215 | 216 | # SonarQube Plugin 217 | .idea/**/sonarIssues.xml 218 | 219 | # Markdown Navigator plugin 220 | .idea/**/markdown-navigator.xml 221 | .idea/**/markdown-navigator/ 222 | 223 | ################################################################################ 224 | ### Operating Systems 225 | ################################################################################ 226 | 227 | ### Linux ### 228 | *~ 229 | 230 | # temporary files which can be created if a process still has a handle open of a deleted file 231 | .fuse_hidden* 232 | 233 | # KDE directory preferences 234 | .directory 235 | 236 | # Linux trash folder which might appear on any partition or disk 237 | .Trash-* 238 | 239 | # .nfs files are created when an open file is removed but is still being accessed 240 | .nfs* 241 | 242 | ### macOS ### 243 | # General 244 | .DS_Store 245 | .AppleDouble 246 | .LSOverride 247 | 248 | # Icon must end with two \r 249 | Icon 250 | 251 | # Thumbnails 252 | ._* 253 | 254 | # Files that might appear in the root of a volume 255 | .DocumentRevisions-V100 256 | .fseventsd 257 | .Spotlight-V100 258 | .TemporaryItems 259 | .Trashes 260 | .VolumeIcon.icns 261 | .com.apple.timemachine.donotpresent 262 | 263 | # Directories potentially created on remote AFP share 264 | .AppleDB 265 | .AppleDesktop 266 | Network Trash Folder 267 | Temporary Items 268 | .apdisk 269 | 270 | ### Windows ### 271 | # Windows thumbnail cache files 272 | Thumbs.db 273 | Thumbs.db:encryptable 274 | ehthumbs.db 275 | ehthumbs_vista.db 276 | 277 | # Dump file 278 | *.stackdump 279 | 280 | # Folder config file 281 | [Dd]esktop.ini 282 | 283 | # Recycle Bin used on file shares 284 | $RECYCLE.BIN/ 285 | 286 | # Windows Installer files 287 | *.cab 288 | *.msi 289 | *.msix 290 | *.msm 291 | *.msp 292 | 293 | # Windows shortcuts 294 | *.lnk 295 | 296 | # End of https://www.gitignore.io/api/node,vim,visualstudiocode,webstorm,linux,macos,windows 297 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "singleQuote": true, 4 | "tabWidth": 4, 5 | "trailingComma": "none", 6 | "useTabs": false, 7 | "bracketSpacing": true, 8 | "arrowParens": "avoid" 9 | } 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Martin Rosenberg 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this any files in this repository except in compliance 5 | with the License. You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![NPM package downloads](https://img.shields.io/npm/dt/gatsby-plugin-react-helmet-async)](https://www.npmjs.com/package/gatsby-plugin-react-helmet-async) 2 | [![Depfu](https://img.shields.io/depfu/Me4502/gatsby-plugin-react-helmet-async)](https://depfu.com/repos/github/Me4502/gatsby-plugin-react-helmet-async) 3 | ![Code size](https://img.shields.io/github/languages/code-size/Me4502/gatsby-plugin-react-helmet-async) 4 | ![Repo size](https://img.shields.io/github/repo-size/Me4502/gatsby-plugin-react-helmet-async) 5 | 6 | # gatsby-plugin-react-helmet-async 7 | 8 | ## Description 9 | 10 | Provides drop-in support for server rendering data added with [React Helmet Async](https://github.com/staylor/react-helmet-async). 11 | 12 | React Helmet Async is a component which lets you control your document head using their React component. 13 | 14 | With this plugin, attributes you add in their component, e.g. title, meta attributes, etc. will get added to the static HTML pages Gatsby builds. 15 | 16 | This is important not just for site viewers, but also for SEO — title and description metadata stored in the document head is a key component used by Google in determining placement in search results. 17 | 18 | ## How to install 19 | 20 | Replace `yarn add` with `npm i` if you're using npm, or `pnpm add` for pnpm: 21 | 22 | ```bash 23 | yarn add react-helmet-async gatsby-plugin-react-helmet-async 24 | ``` 25 | 26 | `react-helmet-async` requires your `react` and `react-dom` to be at least `16.6.0`. If they're older than that, you'll need to upgrade them: 27 | 28 | ```bash 29 | yarn add react@^16.6.0 react-dom@^16.6.0 30 | ``` 31 | 32 | ### Using TypeScript 33 | 34 | This package includes its own types, as do `gatsby` and `react-helmet-async`. To get types for the other packages, you'll need to install them separately: 35 | 36 | ```bash 37 | yarn add -D @types/react @types/react-dom 38 | ``` 39 | 40 | ## How to use 41 | 42 | Just add the plugin to the plugins array in your `gatsby-config.js`: 43 | 44 | ```js 45 | module.exports = { 46 | plugins: [`gatsby-plugin-react-helmet-async`] 47 | }; 48 | ``` 49 | -------------------------------------------------------------------------------- /gatsby-browser.d.ts: -------------------------------------------------------------------------------- 1 | import { GatsbyBrowser } from 'gatsby'; 2 | export declare const wrapRootElement: GatsbyBrowser['wrapRootElement']; 3 | -------------------------------------------------------------------------------- /gatsby-browser.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.wrapRootElement = void 0; 7 | var react_1 = __importDefault(require("react")); 8 | var react_helmet_async_1 = require("react-helmet-async"); 9 | var wrapRootElement = function (_a) { 10 | var element = _a.element; 11 | return (react_1.default.createElement(react_helmet_async_1.HelmetProvider, null, element)); 12 | }; 13 | exports.wrapRootElement = wrapRootElement; 14 | -------------------------------------------------------------------------------- /gatsby-ssr.d.ts: -------------------------------------------------------------------------------- 1 | import { GatsbySSR } from 'gatsby'; 2 | export declare const onRenderBody: GatsbySSR['onRenderBody']; 3 | export declare const wrapRootElement: GatsbySSR['wrapRootElement']; 4 | -------------------------------------------------------------------------------- /gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { 3 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { 4 | if (ar || !(i in from)) { 5 | if (!ar) ar = Array.prototype.slice.call(from, 0, i); 6 | ar[i] = from[i]; 7 | } 8 | } 9 | return to.concat(ar || Array.prototype.slice.call(from)); 10 | }; 11 | var __importDefault = (this && this.__importDefault) || function (mod) { 12 | return (mod && mod.__esModule) ? mod : { "default": mod }; 13 | }; 14 | Object.defineProperty(exports, "__esModule", { value: true }); 15 | exports.wrapRootElement = exports.onRenderBody = void 0; 16 | var react_1 = __importDefault(require("react")); 17 | var react_helmet_async_1 = require("react-helmet-async"); 18 | var context = {}; 19 | var onRenderBody = function (_a) { 20 | var _b; 21 | var setHeadComponents = _a.setHeadComponents, setHtmlAttributes = _a.setHtmlAttributes, setBodyAttributes = _a.setBodyAttributes; 22 | var helmet = context.helmet; 23 | if (helmet) { 24 | var baseComponent = helmet.base.toComponent(); 25 | var titleComponent = helmet.title.toComponent(); 26 | var components = [ 27 | helmet.priority.toComponent(), 28 | helmet.meta.toComponent(), 29 | helmet.link.toComponent(), 30 | helmet.style.toComponent(), 31 | helmet.script.toComponent(), 32 | helmet.noscript.toComponent() 33 | ]; 34 | setHeadComponents(((_b = titleComponent[0]) === null || _b === void 0 ? void 0 : _b.props.children) 35 | ? __spreadArray([baseComponent, titleComponent], components, true) : __spreadArray([baseComponent], components, true)); 36 | setHtmlAttributes(helmet.htmlAttributes.toComponent()); 37 | setBodyAttributes(helmet.bodyAttributes.toComponent()); 38 | } 39 | }; 40 | exports.onRenderBody = onRenderBody; 41 | var wrapRootElement = function (_a) { 42 | var element = _a.element; 43 | return (react_1.default.createElement(react_helmet_async_1.HelmetProvider, { context: context }, element)); 44 | }; 45 | exports.wrapRootElement = wrapRootElement; 46 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // noop 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gatsby-plugin-react-helmet-async", 3 | "version": "1.2.3", 4 | "description": "Use react-helmet-async with Gatsby", 5 | "keywords": [ 6 | "gatsby", 7 | "gatsby-plugin", 8 | "react", 9 | "react-helmet", 10 | "react-helmet-async" 11 | ], 12 | "homepage": "https://github.com/Me4502/gatsby-plugin-react-helmet-async#readme", 13 | "bugs": { 14 | "url": "https://github.com/Me4502/gatsby-plugin-react-helmet-async/issues" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/Me4502/gatsby-plugin-react-helmet-async.git" 19 | }, 20 | "license": "Apache-2.0", 21 | "author": "Martin Rosenberg (https://martinbrosenberg.com)", 22 | "main": "index.js", 23 | "scripts": { 24 | "prepublish": "yarn build", 25 | "build": "tsc --build", 26 | "clean": "rm gatsby-browser.d.ts gatsby-browser.js gatsby-ssr.d.ts gatsby-ssr.js", 27 | "lint": "eslint src --ext ts,tsx --fix", 28 | "test": "echo \"Error: no tests specified\" && exit 1" 29 | }, 30 | "devDependencies": { 31 | "@types/react": "^17", 32 | "@types/react-dom": "^17", 33 | "@typescript-eslint/eslint-plugin": "^5.42.1", 34 | "@typescript-eslint/parser": "^5.42.1", 35 | "eslint": "^8.27.0", 36 | "eslint-config-prettier": "^8.5.0", 37 | "eslint-config-standard-react": "^12.0.0", 38 | "eslint-config-standard-with-typescript": "^23.0.0", 39 | "eslint-import-resolver-typescript": "^3.5.2", 40 | "eslint-plugin-import": "^2.26.0", 41 | "eslint-plugin-node": "^11.1.0", 42 | "eslint-plugin-prettier": "^4.2.1", 43 | "eslint-plugin-promise": "^6.1.1", 44 | "eslint-plugin-react": "^7.31.10", 45 | "gatsby": "^3.8.0", 46 | "prettier": "^2.7.1", 47 | "prettier-eslint": "^15.0.1", 48 | "react": "^17.0.2", 49 | "react-dom": "^17.0.2", 50 | "react-helmet-async": "^1.3.0", 51 | "typescript": "^4.8.4" 52 | }, 53 | "peerDependencies": { 54 | "gatsby": ">=2", 55 | "react": "^16.6.0 || ^17 || ^18", 56 | "react-dom": "^16.6.0 || ^17 || ^18", 57 | "react-helmet-async": "1.x" 58 | }, 59 | "resolutions": { 60 | "@types/react": "^17", 61 | "@types/react-dom": "^17" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/gatsby-browser.tsx: -------------------------------------------------------------------------------- 1 | import { GatsbyBrowser, WrapRootElementBrowserArgs } from 'gatsby'; 2 | import React from 'react'; 3 | import { HelmetProvider } from 'react-helmet-async'; 4 | 5 | export const wrapRootElement: GatsbyBrowser['wrapRootElement'] = ({ 6 | element 7 | }: WrapRootElementBrowserArgs): React.ReactElement => ( 8 | {element} 9 | ); 10 | -------------------------------------------------------------------------------- /src/gatsby-ssr.tsx: -------------------------------------------------------------------------------- 1 | import { GatsbySSR, RenderBodyArgs, WrapRootElementNodeArgs } from 'gatsby'; 2 | import React from 'react'; 3 | import { HelmetProvider, HelmetServerState } from 'react-helmet-async'; 4 | 5 | const context: { helmet?: HelmetServerState } = {}; 6 | 7 | export const onRenderBody: GatsbySSR['onRenderBody'] = ({ 8 | setHeadComponents, 9 | setHtmlAttributes, 10 | setBodyAttributes 11 | }: RenderBodyArgs): void => { 12 | const { helmet } = context; 13 | 14 | if (helmet) { 15 | const baseComponent = helmet.base.toComponent(); 16 | const titleComponent = helmet.title.toComponent() as unknown as any[]; 17 | const components = [ 18 | helmet.priority.toComponent(), 19 | helmet.meta.toComponent(), 20 | helmet.link.toComponent(), 21 | helmet.style.toComponent(), 22 | helmet.script.toComponent(), 23 | helmet.noscript.toComponent() 24 | ]; 25 | 26 | setHeadComponents( 27 | titleComponent[0]?.props.children 28 | ? [baseComponent, titleComponent, ...components] 29 | : [baseComponent, ...components] 30 | ); 31 | 32 | setHtmlAttributes(helmet.htmlAttributes.toComponent()); 33 | setBodyAttributes(helmet.bodyAttributes.toComponent()); 34 | } 35 | }; 36 | 37 | export const wrapRootElement: GatsbySSR['wrapRootElement'] = ({ 38 | element 39 | }: WrapRootElementNodeArgs): React.ReactElement => ( 40 | {element} 41 | ); 42 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | // "incremental": true, /* Enable incremental compilation */ 5 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ 6 | // "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 7 | "lib": ["dom", "es6"], /* Specify library files to be included in the compilation. */ 8 | // "allowJs": true, /* Allow javascript files to be compiled. */ 9 | // "checkJs": true, /* Report errors in .js files. */ 10 | "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 11 | "declaration": true, /* Generates corresponding '.d.ts' file. */ 12 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 13 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 14 | // "outFile": "./", /* Concatenate and emit output to single file. */ 15 | "outDir": "./", /* Redirect output structure to the directory. */ 16 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 17 | // "composite": true, /* Enable project compilation */ 18 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 19 | // "removeComments": true, /* Do not emit comments to output. */ 20 | "noEmit": false, /* Do not emit outputs. */ 21 | "noEmitOnError": true, /* Do not emit outputs if any errors were reported. */ 22 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 23 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 24 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 25 | "skipLibCheck": true, /* Skip type checking of all declaration files (*.d.ts). */ 26 | 27 | /* Strict Type-Checking Options */ 28 | "strict": true, /* Enable all strict type-checking options. */ 29 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 30 | // "strictNullChecks": true, /* Enable strict null checks. */ 31 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 32 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 33 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 34 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 35 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 36 | 37 | /* Additional Checks */ 38 | "noUnusedLocals": true, /* Report errors on unused locals. */ 39 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 40 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 41 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 42 | 43 | /* Module Resolution Options */ 44 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 45 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 46 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 47 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 48 | "typeRoots": ["./node_modules/@types"], /* List of folders to include type definitions from. */ 49 | "types": ["node"], /* Type declaration files to be included in compilation. */ 50 | "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 51 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 52 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 53 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 54 | 55 | /* Source Map Options */ 56 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 58 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 59 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 60 | 61 | /* Experimental Options */ 62 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 63 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 64 | 65 | /* Advanced Options */ 66 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ 67 | }, 68 | "include": ["./src/**/*"], 69 | "exclude": ["./node_modules/*"] 70 | } 71 | --------------------------------------------------------------------------------