diff --git a/docusaurus/docs/generating-dynamic-meta-tags-on-the-server.md b/docusaurus/docs/generating-dynamic-meta-tags-on-the-server.md new file mode 100644 index 00000000..e40c8f64 --- /dev/null +++ b/docusaurus/docs/generating-dynamic-meta-tags-on-the-server.md @@ -0,0 +1,18 @@ +--- +id: generating-dynamic-meta-tags-on-the-server +title: Generating Dynamic `` Tags on the Server +--- + +Since Create React App doesn’t support server rendering, you might be wondering how to make `` tags dynamic and reflect the current URL. To solve this, we recommend to add placeholders into the HTML, like this: + +```html + + +
+ + +``` + +Then, on the server, regardless of the backend you use, you can read `index.html` into memory and replace `__OG_TITLE__`, `__OG_DESCRIPTION__`, and any other placeholders with values depending on the current URL. Just make sure to sanitize and escape the interpolated values so that they are safe to embed into HTML! + +If you use a Node server, you can even share the route matching logic between the client and the server. However duplicating it also works fine in simple cases. diff --git a/docusaurus/docs/user-guide.md b/docusaurus/docs/user-guide.md index cded6bb9..75fa952d 100644 --- a/docusaurus/docs/user-guide.md +++ b/docusaurus/docs/user-guide.md @@ -11,7 +11,6 @@ You can find the most recent version of this guide [here](https://github.com/fac ## Table of Contents -- [Generating Dynamic `` Tags on the Server](#generating-dynamic-meta-tags-on-the-server) - [Pre-Rendering into Static HTML Files](#pre-rendering-into-static-html-files) - [Injecting Data from the Server into the Page](#injecting-data-from-the-server-into-the-page) - [Making a Progressive Web App](#making-a-progressive-web-app) @@ -21,22 +20,6 @@ You can find the most recent version of this guide [here](https://github.com/fac - [Advanced Configuration](#advanced-configuration) - [Alternatives to Ejecting](#alternatives-to-ejecting) -## Generating Dynamic `` Tags on the Server - -Since Create React App doesn’t support server rendering, you might be wondering how to make `` tags dynamic and reflect the current URL. To solve this, we recommend to add placeholders into the HTML, like this: - -```html - - - - - -``` - -Then, on the server, regardless of the backend you use, you can read `index.html` into memory and replace `__OG_TITLE__`, `__OG_DESCRIPTION__`, and any other placeholders with values depending on the current URL. Just make sure to sanitize and escape the interpolated values so that they are safe to embed into HTML! - -If you use a Node server, you can even share the route matching logic between the client and the server. However duplicating it also works fine in simple cases. - ## Pre-Rendering into Static HTML Files If you’re hosting your `build` with a static hosting provider you can use [react-snapshot](https://www.npmjs.com/package/react-snapshot) or [react-snap](https://github.com/stereobooster/react-snap) to generate HTML pages for each route, or relative link, in your application. These pages will then seamlessly become active, or “hydrated”, when the JavaScript bundle has loaded. diff --git a/docusaurus/website/sidebars.json b/docusaurus/website/sidebars.json index d42e6b44..999d90a1 100644 --- a/docusaurus/website/sidebars.json +++ b/docusaurus/website/sidebars.json @@ -35,7 +35,8 @@ "adding-custom-environment-variables", "fetching-data-with-ajax-requests", "integrating-with-an-api-backend", - "using-https-in-development" + "using-https-in-development", + "generating-dynamic-meta-tags-on-the-server" ], "Testing": ["running-tests", "debugging-tests"], "Deployment": ["publishing-components-to-npm", "deployment"],