Skip to content

Instantly share code, notes, and snippets.

View Elius94's full-sized avatar
🏔️

Elia Lazzari Elius94

🏔️
View GitHub Profile
@Elius94
Elius94 / seo-injector.md
Created March 10, 2022 15:04
How to programmatically update the HTML headers of a static site generated with create-react-app (CRA)

If you want to find an elegant way to dynamically insert HTML elements inside the block, such as all those needed for a good SEO (meta, open graph, twitter cards, icons etc...), you might have tried to use a React method that acts on the DOM of the application.

In the past I tried with the react-helmet library, which allows to insert free elements inside the headers. The problem is that when search engines or social networks try to generate the site preview, they don't see anything of the inserted meta. This issues is that the javascript method is only good if the site is then interpreted after react has rendered it. Search engine crawlers, but also social, use the bare index.html file as is. That way, react-helmet hasn't inserted the tags yet, and therefore doesn't see them.

To solve this problem, I made this library: Seo Injector

@TooTallNate
TooTallNate / mouse.js
Created January 30, 2012 05:55
Enable "mouse reporting" with Node.js
// Based on:
// http://groups.google.com/group/nodejs-dev/browse_thread/thread/a0c23008029e5fa7
process.stdin.resume();
process.stdin.on('data', function (b) {
var s = b.toString('utf8');
if (s === '\u0003') {
console.error('Ctrl+C');
process.stdin.pause();