{"data":{"site":{"siteMetadata":{"title":"Developerayo","author":"Shodipo Ayomide"}},"markdownRemark":{"id":"072eed8e-eb04-57b5-aa14-6a36030abd5e","excerpt":"Most of us have been there: experiencing the point where the content of your article on your blog get’s to be copied and reused by someone else on their own…","html":"<p align=\"center\"><img src=\"https://res.cloudinary.com/developerayo/image/upload/v1573003584/Safeguard_your_blog_content_in_Reactjs_and_CSS.png\"></p>\n<p>Most of us have been there: experiencing the point where the content of your article on your blog get’s to be copied and reused by someone else on their own blog tagged to their name and zero credit to the writer/owner, the word for this is <code class=\"language-text\">PLAGIARISM</code>, now with the help of a simple css element and small bits of react, you can fix that.</p>\n<p>Here is a tweet (#thread) from <b>Prosper Otemuyiwa</b> about his plagiarism experience on one of his articles.</p>\n<blockquote class=\"twitter-tweet\" data-theme=\"light\"><p lang=\"en\" dir=\"ltr\">Do something today that your future self will thank you for. Might be for yourself, family or community.<br><br>A few days ago I wanted do something in <a href=\"https://twitter.com/vuejs?ref_src=twsrc%5Etfw\">@vuejs</a> &amp; I googled as usual. I came across an article and started reading, and it was really making sense until I got to....</p>&mdash; Prosper Otemuyiwa (@unicodeveloper) <a href=\"https://twitter.com/unicodeveloper/status/1143535311303000064?ref_src=twsrc%5Etfw\">June 25, 2019</a></blockquote> <script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n<p>Continue reading thread <a href=\"https://twitter.com/unicodeveloper/status/1143535311303000064\">here</a></p>\n<br>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Table of Contents\n- Prerequisites\n- Installing create-react-app\n- CodeSandbox\n- Setting up\n- Deploy it to Zeit Now\n- Conclusion</code></pre></div>\n<h2>Prerequisites</h2>\n<p>Most of us have been there: experiencing the point where the content of your article on your blog gets to be copied and reused by someone else on their blog tagged to their name and zero credit to the writer/owner, the word for this is <code class=\"language-text\">PLAGIARISM</code>, now with the help of a simple CSS element and small bits of react, you can fix that.</p>\n<h5>To create a new React project you’ll need</h5>\n<ul>\n<li><a href=\"https://nodejs.org/en/\">NodeJS</a> and <a href=\"https://docs.npmjs.com/\">NPM CLI</a> </li>\n<li><a href=\"https://code.visualstudio.com/download\">Visual Studio Code “VSCode”</a> or your preffered code-editor</li>\n</ul>\n<h5>So as to enable pushing your code to GitHub you’ll need</h5>\n<ul>\n<li><a href=\"https://git-scm.com/downloads\">GIT</a></li>\n</ul>\n<h5>For deployment, you’ll have to install</h5>\n<ul>\n<li><a href=\"https://zeit.co/docs/now-cli/\">ZEIT NOW</a></li>\n</ul>\n<h2>Installing create-react-app</h2>\n<p>Let’s start with installing <code class=\"language-text\">create-react-app</code></p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ npx create-react-app safeguard-content</code></pre></div>\n<h2>CodeSandbox</h2>\n<p>But in this case study I would be building this simple feature on <a href=\"https://codesandbox.io\">CodeSandbox</a></p>\n<p>Start by visiting <a href=\"https://codesandbox.io\">codesandbox.io</a>, sign up/login with GitHub, once that is done you would be redirected to your dashboard then click <code class=\"language-text\">Create Sandbox</code>, you’ll get to have five tabs click on the one that says <code class=\"language-text\">CLIENT TEMPLATES</code> under that list you’ll file react as a client template, click it.</p>\n<p align=\"center\"><img src=\"https://res.cloudinary.com/developerayo/image/upload/v1573000789/safe1.png\"></p>\n<p>Once created, you will get a demo app in ReactJS.</p>\n<h2>Setting up</h2>\n<p>Next up, we will setup our ReactJS app with some <code class=\"language-text\">HTML</code> tags.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">\"react-dom\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token string\">\"./styles.css\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\t<span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"App\"</span><span class=\"token operator\">></span>\n\t  <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello Developer 🔥🔥🔥🔥<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n\t  <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>Start editing to see some magic happen<span class=\"token operator\">!</span>😄🔥<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n\t  <span class=\"token operator\">&lt;</span>h3<span class=\"token operator\">></span>Hehehe<span class=\"token operator\">!</span> sorry<span class=\"token punctuation\">,</span> you can't 😅😎🔥🔥<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h3<span class=\"token operator\">></span>\n          <span class=\"token operator\">&lt;</span>h4<span class=\"token operator\">></span>But you can edit <span class=\"token keyword\">this</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h4<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n\t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> rootElement <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"root\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>App <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> rootElement<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<br>\n<p align=\"center\"><img src=\"https://res.cloudinary.com/developerayo/image/upload/v1572995248/gif1.gif\"></p>\n<p>In the code above you can see the simple output in the GIF below, and you can see in <code class=\"language-text\">line 4</code> that I am trying to import a <code class=\"language-text\">style.css</code> file.</p>\n<p>Next, let’s write some CSS</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.App</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">font-family</span><span class=\"token punctuation\">:</span> sans-serif<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">text-align</span><span class=\"token punctuation\">:</span> center<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">h1</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">user-select</span><span class=\"token punctuation\">:</span> none<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">h2</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">user-select</span><span class=\"token punctuation\">:</span> none<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">h3</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">user-select</span><span class=\"token punctuation\">:</span> none<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>In my <code class=\"language-text\">index.js</code> file I posted earlier I created three tags under the app function which are <code class=\"language-text\">&lt;h1&gt;, &lt;h2&gt; &lt;h3&gt; &amp; &lt;h4&gt;</code></p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span>Hello Developer 🔥🔥🔥🔥<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h2</span><span class=\"token punctuation\">></span></span>Start editing to see some magic happen!😄🔥<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h2</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h3</span><span class=\"token punctuation\">></span></span>Hehehe! sorry, you can't 😅😎🔥🔥<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h3</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h4</span><span class=\"token punctuation\">></span></span>But you can edit this<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h4</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>Which are under a function name <code class=\"language-text\">app</code> and <code class=\"language-text\">className</code> set as App, ref as <code class=\"language-text\">.App</code> in css</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n     <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"App\"</span><span class=\"token operator\">></span></code></pre></div>\n<p align=\"center\"><img src=\"https://res.cloudinary.com/developerayo/image/upload/v1572997195/chrome-capture.gif\"></p>\n<br>\n<p>In the GIF above, the first three texts cannot be selected because I used a CSS element called <code class=\"language-text\">user-select</code> and the attribute set as <code class=\"language-text\">none</code> which automatically disable Copying with mouse and <code class=\"language-text\">Ctrl + A</code> also. </p>\n<p>The <code class=\"language-text\">user-select</code> element with the attribute as <code class=\"language-text\">none</code> which was called for in our <code class=\"language-text\">style.css</code> and was attached to the <code class=\"language-text\">HTML</code> tags we declared in our react code in <code class=\"language-text\">index.html</code> which was referenced above. The as one could be selected because we did not attach a CSS element to the <code class=\"language-text\">&lt;h4&gt;</code> tag.</p>\n<h2>Deploy it to Zeit Now</h2>\n<p>First, we need to create a <code class=\"language-text\">now.json</code> file in our main directory, once done add the code below in it.</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"version\"</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"name\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Safeguard Content\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"alias\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"safeguard-content.now.sh\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"builds\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span><span class=\"token property\">\"src\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"package.json\"</span><span class=\"token punctuation\">,</span> <span class=\"token property\">\"use\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"@now/static-build\"</span><span class=\"token punctuation\">,</span> <span class=\"token property\">\"config\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token property\">\"distDir\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"build\"</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span> </code></pre></div>\n<p>ZEIT NOW owns two versions which are <code class=\"language-text\">Version 1 &amp; Version 2</code> and in this case, we are using version 2 <code class=\"language-text\">&quot;version&quot;: 2</code>. We are setting the name of our app as <code class=\"language-text\">Safeguard Content</code>.</p>\n<p>It is a best practice to always alias your domain to a particular one so you do not get a weird link at deployment, here our codebase has been aliased to <code class=\"language-text\">safeguard-content.now.sh</code>. </p>\n<p>For builds, we declared a <code class=\"language-text\">now-build</code> script in our <code class=\"language-text\">package.json</code> file under <code class=\"language-text\">scripts</code> to build our react app on the new server.</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"> <span class=\"token property\">\"scripts\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    ...\n    <span class=\"token property\">\"now-build\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"react-scripts build\"</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now that that is declared we would be rendering our app statically using the Zeit Now static build <code class=\"language-text\">@now/static-build</code>.</p>\n<p>Once that is done, we need to deploy to a new repo on GitHub</p>\n<p align=\"center\"><img src=\"https://res.cloudinary.com/developerayo/image/upload/v1572998837/safe2.png\"></p>\n<p>Look at the left-hand side of the repo, click the GitHub favicon and it gives you a second-half screen, put in your desired repo name, mine is <code class=\"language-text\">safeguard-content</code>, once written, create a repo. If you visit your GitHub profile you should find your repo there.</p>\n<p>Visit your <a href=\"https://zeit.co/dashboard\">Zeit dashboard</a> and you will find your deployed site there. </p>\n<p align=\"center\"><img src=\"https://res.cloudinary.com/developerayo/image/upload/v1572999390/now.png\"></p>\n<p>You can go to <a href=\"https://safeguard-content.now.sh/\">https://safeguard-content.now.sh/</a> and check it.</p>\n<h2>Conclusion</h2>\n<p>Having your content copied and no credit given to you as the initial writer is sad, and this is a way out, You do not necessarily need to deploy to Zeit Now, you can easily also deploy to <a href=\"https://netlify.com\">Netlify</a> or other services you use.</p>\n<p>I hope you found this tutorial helpful and will be able to secure your blog post, You can find a full source of the project <a href=\"https://github.com/Developerayo/safeguard-content\">here</a> on GitHub and CodeSandbox <a href=\"https://codesandbox.io/s/safeguard-content-5ut1q\">here</a></p>\n<p>Like this article? Follow <a href=\"https://twitter.com/developerayo\">@developerayo</a> on Twitter.</p>","timeToRead":5,"frontmatter":{"title":"Safeguard your blog content in Reactjs and CSS","date":"November 06, 2019","description":"hehehe, I dont know if this shit would work but let's do it!! Curious about how to safeguard your blog content in your ReactJS app using CSS? You are about to find out!"}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"slug":"/safeguard-your-blog-content-in-reactjs-and-css/","previous":{"fields":{"slug":"/unstack-2019-conference-recap/"},"frontmatter":{"title":"unStack 2019 event recap; All the announcements that matter"}},"next":null}}