<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sina</title>
    <description>The latest articles on DEV Community by Sina (@sinacodes).</description>
    <link>https://dev.to/sinacodes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F158959%2Ff890fed6-e218-481a-96a8-1d7d327e3ef6.jpeg</url>
      <title>DEV Community: Sina</title>
      <link>https://dev.to/sinacodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sinacodes"/>
    <language>en</language>
    <item>
      <title>Using Client-side Javascript Librarys with Next.js</title>
      <dc:creator>Sina</dc:creator>
      <pubDate>Thu, 25 Apr 2019 08:12:56 +0000</pubDate>
      <link>https://dev.to/sinacodes/using-client-side-javascript-librarys-with-next-js-22gh</link>
      <guid>https://dev.to/sinacodes/using-client-side-javascript-librarys-with-next-js-22gh</guid>
      <description>

&lt;p&gt;So, the other day I was trying to integrate &lt;a href="https://wowjs.uk/"&gt;wow.js&lt;/a&gt; in a &lt;a href="https://nextjs.org/"&gt;next.js&lt;/a&gt; Application for smooth onScroll Animations. It turned out: that’s not as trivial as I thought it would be, as wow.js is executed on the Client-side (as it needs the window attribute) and Next.js is famous for being Server-side rendered (SSR) React Code. Or to be precise, it’s not that difficult if you know how it works.&lt;/p&gt;

&lt;p&gt;That is to say, instead of the usual import on the top-level, you have to require the Library inside of the componentDidMount function, which is only executed in the client.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;componentDidMount() {

  if(typeof window !== 'undefined') {

    window.WOW = require('wowjs');

  }

  new WOW.WOW().init();

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After importing it this way, you can use wowJS the usual way via classNames:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div className="wow fadeInUp" data-wow-offset="20"&amp;gt;

  &amp;lt;h1&amp;gt;My awesome animated Component&amp;lt;/h1&amp;gt;

&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Good to know: wow.js needs to be rendered only once per View. For example, if you have a few Components that you want to animate, you can require wow.js in a wrapper Component. That way it’s only loaded once.&lt;/p&gt;

&lt;p&gt;Good to think about too: if there is one for your use case, consider using an react-alternative instead of this workaround. &lt;/p&gt;


</description>
      <category>nextjs</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>create a documentation with mdbook</title>
      <dc:creator>Sina</dc:creator>
      <pubDate>Sun, 21 Apr 2019 14:24:20 +0000</pubDate>
      <link>https://dev.to/sinacodes/create-a-documentation-with-mdbook-4120</link>
      <guid>https://dev.to/sinacodes/create-a-documentation-with-mdbook-4120</guid>
      <description>&lt;p&gt;&lt;a href="https://rust-lang-nursery.github.io/mdBook/"&gt;mdbook&lt;/a&gt; is a cool alternative to gitbook, built with &lt;a href="https://www.rust-lang.org/"&gt;rust&lt;/a&gt;. you don't need to manage any frontend work and besides the configuration at the beginning there is no backend to maintain. Most of the time this is just a shallow promise, but with mdbook I learned: If you know how, you can push a &lt;a href="https://rust-lang-nursery.github.io/mdBook/"&gt;mdbook&lt;/a&gt; to production in 20-30 minutes - which is really nice I think. That's why I will share my gained knowledge.&lt;/p&gt;

&lt;p&gt;As a complete beginner to rust I had no idea how to set up a rust website with this static site generator. But don't be afraid, you won't need to write rust-code to use this SSG, you don't even need to install rust or cargo or anything related, because you can install mdbook via homebrew or github, as it's available as a precompiled binary that will run natively on your OS - linux, mac and windows.&lt;/p&gt;

&lt;p&gt;So, our roadmap looks as follows:   &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;get up and running with mdbook on our local machine&lt;/li&gt;
&lt;li&gt;connect our local repository with our remote server&lt;/li&gt;
&lt;li&gt;configure that remote server (ubuntu digital ocean droplet)&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  1. mdbook development environment
&lt;/h1&gt;

&lt;p&gt;First we want to install the binary on our local machine. If you are running macOS (assuming homebrew is installed) run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install mdbook
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;otherwise you can get the fitting binary from the mdbook github page:&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/rust-lang-nursery/mdBook/releases"&gt;mdbook Releases&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;e.g. with curl, run (as of March 2019) this code in the right folder /usr/local/bin/:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -sL https://github.com/rust-lang/mdBook/releases/download/v0.3.5/mdbook-v0.3.5-x86_64-unknown-linux-gnu.tar.gz | tar xz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;now, if you run &lt;code&gt;$ mdbook -V&lt;/code&gt; in the terminal, you should see the currently installed version.&lt;/p&gt;




&lt;p&gt;Next we want to init our project, simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mdbook init myfirstmdbook &amp;amp;&amp;amp; cd myfirstmdbook
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;then (inside the newly created directory) run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mdbook serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then open &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt; and you will already see our newly created book - cool, heh?&lt;/p&gt;

&lt;p&gt;Now, to add new sites to your book, customize the file &lt;code&gt;src/summary.md&lt;/code&gt; - while mdbook serve is running, it will automagically create the new md-files, ready for you to write.&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Connect book to remote server
&lt;/h1&gt;

&lt;p&gt;Now we want to connect this project to our remote server! While on &lt;code&gt;master&lt;/code&gt; type into terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git remote add production ssh://YOUR_USER@YOUR_SERVER_IP/var/repo/myfirstmdbook.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now his command line instruction deploys to your server (but first we need to setup the server, see below):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push production master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h1&gt;
  
  
  3. Adjusting the Server
&lt;/h1&gt;

&lt;p&gt;I won't go too deep into configuring the basics of the server, I will assume you find your way to set up basic apache/nginx to create repositories inside of var/www/. For more Information, Digital Ocean has very helpful Tutorials.&lt;/p&gt;

&lt;p&gt;Installing mdbook on the remote host works the same way as on your local machine, as you need to install the binary.&lt;br&gt;&lt;br&gt;
So e.g. on a Linux Machine use the cURL code from above inside of usr/bin&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -sL https://github.com/rust-lang/mdBook/releases/download/v0.3.5/mdbook-v0.3.5-x86_64-unknown-linux-gnu.tar.gz | tar xz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Ok, so after that is done – on our remote server we also need to install git, (for example inside of the folder &lt;code&gt;/var/repo/&lt;/code&gt;). Then, inside of repo/, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir myfirstmdbook.git &amp;amp;&amp;amp; cd myfirstmdbook.git
$ git init --bare
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;nice to know:&lt;br&gt;
&lt;code&gt; - bare&lt;/code&gt;: this is only used on servers. It will create a repo with the sole purpose to receive pushes.&lt;/p&gt;



&lt;p&gt;Inside of myfirstmdbook.git find the &lt;code&gt;/hooks&lt;/code&gt;folder and create a file named &lt;code&gt;pre-receive&lt;/code&gt;. inside of that file, add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/sh
echo "removing old deployment"
targetdir=/var/www/pathToTargetDir/html
cd $targetdir
rm -rf *
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;this will remove everything inside of the directory, everytime you push - that way you can get rid of old deployments before a new deployment.&lt;/p&gt;

&lt;p&gt;now also create a file named &lt;code&gt;post-receive&lt;/code&gt;&lt;br&gt;
Inside here, type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/sh
echo "running deployment"
targetdir=/var/www/pathToTargetDir/html
git --work-tree=$targetdir --git-dir=/var/repo/myfirstmdbook.git checkout -f
cd $targetdir
#!/usr/bin/env mdbook
mdbook build
rm *
rm -rf src/
cp -r book/* .
rm -rf book/
echo "new mdbook build and deployed"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Explaining: this script will be executed whenever a "git push production master" happened. Then this script will move inside of your project-folder and execute an mdbook build. after that it will remove all the files (not directories) and move everything from the subdirectory /book/ (where the static site lies) one level up, so that only the static site is left.&lt;br&gt;
These two files now also need to be able to execute on your server. Inside of /hooks run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo chmod +x post-receive
$ sudo chmod +x pre-receive
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;p&gt;Et Voilà. Now you should be able to deploy your mdbook to production running&lt;br&gt;
&lt;code&gt;$ git push production master&lt;/code&gt; on your local machine. :)&lt;/p&gt;

</description>
      <category>git</category>
      <category>rust</category>
      <category>mdbook</category>
      <category>documentation</category>
    </item>
  </channel>
</rss>
