2017-02-23 03:59:06 +08:00
<!DOCTYPE html>
< html class = "no-js" >
< head lang = "en-us" >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1" >
< meta http-equiv = "X-UA-Compatible" content = "IE=10" / >
2017-03-11 02:48:13 +08:00
< title > Getting Started - Laradock< / title >
2017-04-10 02:39:25 +08:00
< meta name = "generator" content = "Hugo 0.19" / >
2017-02-23 03:59:06 +08:00
< meta name = "description" content = "Laradock documentations." >
2017-02-23 04:13:04 +08:00
< link rel = "canonical" href = "http://laradock.io/getting-started/" >
2017-02-23 03:59:06 +08:00
< meta name = "author" content = "Mahmoud Zalt" >
2017-02-23 04:13:04 +08:00
< meta property = "og:url" content = "http://laradock.io/getting-started/" >
2017-03-11 02:48:13 +08:00
< meta property = "og:title" content = "Laradock" >
2017-02-23 12:08:54 +08:00
2017-03-11 02:48:13 +08:00
< meta name = "apple-mobile-web-app-title" content = "Laradock" >
2017-02-23 03:59:06 +08:00
< meta name = "apple-mobile-web-app-capable" content = "yes" >
< meta name = "apple-mobile-web-app-status-bar-style" content = "black-translucent" >
2017-02-23 04:13:04 +08:00
< link rel = "shortcut icon" type = "image/x-icon" href = "http://laradock.io/images/favicon.ico" >
< link rel = "icon" type = "image/x-icon" href = "http://laradock.io/images/favicon.ico" >
2017-02-23 03:59:06 +08:00
< style >
@font-face {
font-family: 'Icon';
2017-02-23 04:13:04 +08:00
src: url('http://laradock.io/fonts/icon.eot');
src: url('http://laradock.io/fonts/icon.eot')
2017-02-23 03:59:06 +08:00
format('embedded-opentype'),
2017-02-23 04:13:04 +08:00
url('http://laradock.io/fonts/icon.woff')
2017-02-23 03:59:06 +08:00
format('woff'),
2017-02-23 04:13:04 +08:00
url('http://laradock.io/fonts/icon.ttf')
2017-02-23 03:59:06 +08:00
format('truetype'),
2017-02-23 04:13:04 +08:00
url('http://laradock.io/fonts/icon.svg')
2017-02-23 03:59:06 +08:00
format('svg');
font-weight: normal;
font-style: normal;
}
< / style >
2017-02-23 04:13:04 +08:00
< link rel = "stylesheet" href = "http://laradock.io/stylesheets/application.css" >
< link rel = "stylesheet" href = "http://laradock.io/stylesheets/temporary.css" >
< link rel = "stylesheet" href = "http://laradock.io/stylesheets/palettes.css" >
< link rel = "stylesheet" href = "http://laradock.io/stylesheets/highlight/highlight.css" >
2017-02-23 03:59:06 +08:00
2017-02-23 12:08:54 +08:00
< link rel = "stylesheet" href = "//fonts.googleapis.com/css?family=Doctarine:400,700|Source+Code+Pro" >
2017-02-23 03:59:06 +08:00
< style >
body, input {
2017-02-23 12:08:54 +08:00
font-family: 'Doctarine', Helvetica, Arial, sans-serif;
2017-02-23 03:59:06 +08:00
}
pre, code {
2017-02-23 12:08:54 +08:00
font-family: 'Source Code Pro', 'Courier New', 'Courier', monospace;
2017-02-23 03:59:06 +08:00
}
< / style >
2017-02-23 04:13:04 +08:00
< script src = "http://laradock.io/javascripts/modernizr.js" > < / script >
2017-02-23 03:59:06 +08:00
< / head >
2017-03-11 02:48:13 +08:00
< body class = "palette-primary-deep-purple palette-accent-purple" >
2017-02-23 03:59:06 +08:00
< div class = "backdrop" >
< div class = "backdrop-paper" > < / div >
< / div >
< input class = "toggle" type = "checkbox" id = "toggle-drawer" >
< input class = "toggle" type = "checkbox" id = "toggle-search" >
< label class = "toggle-button overlay" for = "toggle-drawer" > < / label >
< header class = "header" >
< nav aria-label = "Header" >
< div class = "bar default" >
< div class = "button button-menu" role = "button" aria-label = "Menu" >
< label class = "toggle-button icon icon-menu" for = "toggle-drawer" >
< span > < / span >
< / label >
< / div >
< div class = "stretch" >
< div class = "title" >
2017-03-11 02:48:13 +08:00
< b > Laradock< / b > < span style = "color: rgba(249, 245, 255, 0.63);" > / Getting Started< / span >
2017-02-23 03:59:06 +08:00
< / div >
< / div >
< div class = "button button-github" role = "button" aria-label = "GitHub" >
2017-03-11 02:48:13 +08:00
< a style = "padding: 0px; font-size:40px" href = "https://github.com/laradock/laradock" title = "@laradock/laradock on GitHub" target = "_blank" class = "toggle-button icon icon-github" > < / a >
2017-02-23 03:59:06 +08:00
< / div >
2017-03-11 02:48:13 +08:00
< p style = "font-size: 18px; padding: 8px" > Github< / p >
2017-02-23 03:59:06 +08:00
< / div >
< div class = "bar search" >
< div class = "button button-close" role = "button" aria-label = "Close" >
< label class = "toggle-button icon icon-back" for = "toggle-search" > < / label >
< / div >
< div class = "stretch" >
< div class = "field" >
< input class = "query" type = "text" placeholder = "Search" autocapitalize = "off" autocorrect = "off" autocomplete = "off" spellcheck >
< / div >
< / div >
< div class = "button button-reset" role = "button" aria-label = "Search" >
< button class = "toggle-button icon icon-close" id = "reset-search" > < / button >
< / div >
< / div >
< / nav >
2017-03-11 02:48:13 +08:00
2017-02-23 03:59:06 +08:00
< / header >
< main class = "main" >
< div class = "drawer" >
< nav aria-label = "Navigation" >
2017-03-11 02:48:13 +08:00
2017-02-23 03:59:06 +08:00
2017-03-11 02:48:13 +08:00
2017-02-23 03:59:06 +08:00
< div class = "scrollable" >
< div class = "wrapper" >
< div class = "toc" >
< ul >
< li >
2017-02-23 12:08:54 +08:00
< a title = "Introduction" href = "http://laradock.io/introduction/" >
2017-02-23 03:59:06 +08:00
2017-02-23 12:08:54 +08:00
Introduction
2017-02-23 03:59:06 +08:00
< / a >
< / li >
< li >
2017-02-23 04:58:06 +08:00
< a class = "current" title = "Getting Started" href = "http://laradock.io/getting-started/" >
2017-02-23 03:59:06 +08:00
2017-02-23 04:58:06 +08:00
Getting Started
2017-02-23 03:59:06 +08:00
< / a >
< ul id = "scrollspy" >
< / ul >
< / li >
< li >
2017-02-23 04:13:04 +08:00
< a title = "Documentation" href = "http://laradock.io/documentation/" >
Documentation
< / a >
< / li >
< li >
2017-04-14 16:43:26 +08:00
< a title = "Giudes" href = "http://laradock.io/guides/" >
Giudes
< / a >
< / li >
< li >
2017-04-14 16:44:50 +08:00
< a title = "Help & Questions" href = "http://laradock.io/help/" >
2017-02-23 04:13:04 +08:00
2017-04-14 16:44:50 +08:00
Help & Questions
2017-02-23 04:13:04 +08:00
< / a >
< / li >
< li >
2017-04-14 16:44:50 +08:00
< a title = "Related Projects" href = "http://laradock.io/related-projects/" >
2017-02-23 04:13:04 +08:00
2017-04-14 16:44:50 +08:00
Related Projects
2017-02-23 04:13:04 +08:00
< / a >
< / li >
< li >
< a title = "Contributing" href = "http://laradock.io/contributing/" >
Contributing
< / a >
< / li >
< li >
< a title = "License" href = "http://laradock.io/license/" >
2017-02-23 03:59:06 +08:00
License
< / a >
< / li >
< / ul >
2017-03-11 02:48:13 +08:00
2017-02-23 03:59:06 +08:00
< ul >
2017-03-11 02:48:13 +08:00
2017-02-23 03:59:06 +08:00
< / ul >
< / div >
< / div >
< / div >
< / nav >
< / div >
< article class = "article" >
< div class = "wrapper" >
2017-02-23 04:58:06 +08:00
< h1 > Getting Started < / h1 >
2017-02-23 03:59:06 +08:00
2017-02-23 04:58:06 +08:00
< h2 id = "requirements" > Requirements< / h2 >
2017-02-23 03:59:06 +08:00
< ul >
< li > < a href = "https://git-scm.com/downloads" > Git< / a > < / li >
< li > < a href = "https://www.docker.com/products/docker/" > Docker< / a > < code > > = 1.12< / code > < / li >
< / ul >
2017-02-23 04:58:06 +08:00
< h2 id = "installation" > Installation< / h2 >
2017-02-23 03:59:06 +08:00
< p > Choose the setup the best suits your needs.< / p >
2017-03-17 05:03:05 +08:00
< ul >
< li > < a href = "#A" > A) Setup for Single Project< / a >
< ul >
< li > < a href = "#A1" > A.1) Already have a PHP project< / a > < / li >
< li > < a href = "#A2" > A.2) Don’ t have a PHP project yet< / a > < / li >
< / ul > < / li >
< li > < a href = "#B" > B) Setup for Multiple Projects< / a > < / li >
< / ul >
< p > < a name = "A" > < / a > < / p >
2017-03-17 05:44:14 +08:00
< h3 id = "a-setup-for-single-project" > A) Setup for Single Project< / h3 >
2017-03-17 05:03:05 +08:00
< blockquote >
< p > (Follow these steps if you want a separate Docker environment for each project)< / p >
< / blockquote >
2017-02-23 03:59:06 +08:00
2017-03-17 05:03:05 +08:00
< p > < a name = "A1" > < / a > < / p >
2017-02-23 03:59:06 +08:00
2017-03-17 05:44:14 +08:00
< h3 id = "a-1-already-have-a-php-project" > A.1) Already have a PHP project:< / h3 >
2017-02-23 03:59:06 +08:00
2017-03-17 05:03:05 +08:00
< p > 1 - Clone laradock on your project root directory:< / p >
2017-02-23 03:59:06 +08:00
< pre > < code class = "language-bash" > git submodule add https://github.com/Laradock/laradock.git
< / code > < / pre >
2017-03-17 05:03:05 +08:00
< p > < strong > Notes:< / strong > < / p >
2017-02-23 03:59:06 +08:00
2017-03-17 05:03:05 +08:00
< ul >
< li > < p > If you are not using Git yet for your project, you can use < code > git clone< / code > instead of < code > git submodule< / code > .< / p > < / li >
2017-04-10 02:39:25 +08:00
< li > < p > Note 2: To keep track of your Laradock changes, between your projects and also keep Laradock updated. < a href = "http://laradock.io/documentation/#keep-track-of-your-laradock-changes" > Check this< / a > < / p > < / li >
2017-03-17 05:03:05 +08:00
< / ul >
2017-02-23 03:59:06 +08:00
2017-03-17 05:03:05 +08:00
< p > Your folder structure should look like this:< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< pre > < code > + project-a
+ laradock-a
+ project-b
+ laradock-b
2017-02-23 03:59:06 +08:00
< / code > < / pre >
2017-03-17 14:46:19 +08:00
< p > (It’ s important to rename the folders differently in each project.)< / p >
< blockquote >
< p > < strong > Now jump to the < a href = "#Usage" > Usage< / a > section.< / strong > < / p >
< / blockquote >
2017-03-17 07:28:01 +08:00
2017-03-17 05:03:05 +08:00
< p > < a name = "A2" > < / a > < / p >
2017-02-23 03:59:06 +08:00
2017-03-17 05:44:14 +08:00
< h3 id = "a-2-don-t-have-a-php-project-yet" > A.2) Don’ t have a PHP project yet:< / h3 >
2017-03-17 05:03:05 +08:00
2017-02-23 03:59:06 +08:00
< p > 1 - Clone this repository anywhere on your machine:< / p >
2017-02-23 04:13:04 +08:00
< pre > < code class = "language-bash" > git clone https://github.com/laradock/laradock.git
2017-02-23 03:59:06 +08:00
< / code > < / pre >
2017-03-17 05:03:05 +08:00
< p > Your folder structure should look like this:< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< pre > < code > + laradock
+ project-z
2017-02-23 03:59:06 +08:00
< / code > < / pre >
2017-03-17 08:53:14 +08:00
< p > 2 - Edit your web server sites configuration.< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< p > < strong > In case of NGINX:< / strong > open < code > nginx/sites/default.conf< / code > and change the < code > root< / code > from < code > /var/www/public< / code > to < code > /var/www/{my-project-folder-name}/public< / code > .< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< p > < em > Or you can keep < code > default.conf< / code > as it is, and create a separate config < code > my-site.conf< / code > file for it.< / em > < / p >
2017-04-10 02:39:25 +08:00
< p > < strong > In case of Apache:< / strong > :P< / p >
< p > < br > < / p >
2017-03-17 08:53:14 +08:00
2017-03-17 14:46:19 +08:00
< blockquote >
< p > < strong > Now jump to the < a href = "#Usage" > Usage< / a > section.< / strong > < / p >
< / blockquote >
2017-02-23 03:59:06 +08:00
2017-03-17 05:03:05 +08:00
< p > < a name = "B" > < / a > < / p >
2017-03-17 05:44:14 +08:00
< h3 id = "b-setup-for-multiple-projects" > B) Setup for Multiple Projects:< / h3 >
2017-02-23 03:59:06 +08:00
2017-03-17 05:03:05 +08:00
< blockquote >
2017-03-17 08:53:14 +08:00
< p > (Follow these steps if you want a single Docker environment for all your project)< / p >
2017-03-17 05:03:05 +08:00
< / blockquote >
2017-03-17 08:53:14 +08:00
< p > 1 - Clone this repository anywhere on your machine (similar to < a href = "#A2" > Steps A.2. from above< / a > ):< / p >
2017-02-23 03:59:06 +08:00
2017-02-23 04:13:04 +08:00
< pre > < code class = "language-bash" > git clone https://github.com/laradock/laradock.git
2017-02-23 03:59:06 +08:00
< / code > < / pre >
2017-03-17 08:53:14 +08:00
< p > Your folder structure should look like this:< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< pre > < code > + laradock
+ project-1
+ project-2
2017-02-23 03:59:06 +08:00
< / code > < / pre >
2017-03-17 08:53:14 +08:00
< p > 2 - Go to < code > nginx/sites< / code > and create config files to point to different project directory when visiting different domains.< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< p > Laradock by default includes < code > project-1.conf< / code > and < code > project-2.conf< / code > as working samples.< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< p > 3 - change the default names < code > project-n< / code > :< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< p > You can rename the config files, project folders and domains as you like, just make sure the < code > root< / code > in the config files, is pointing to the correct project folder name.< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< p > 4 - Add the domains to the < strong > hosts< / strong > files.< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 08:53:14 +08:00
< pre > < code > 127.0.0.1 project-1.dev
127.0.0.1 project-2.dev
2017-02-23 03:59:06 +08:00
< / code > < / pre >
2017-03-17 14:46:19 +08:00
< blockquote >
< p > < strong > Now jump to the < a href = "#Usage" > Usage< / a > section.< / strong > < / p >
< / blockquote >
< p > < a name = "Usage" > < / a > < / p >
2017-02-23 03:59:06 +08:00
2017-02-23 04:58:06 +08:00
< h2 id = "usage" > Usage< / h2 >
2017-02-23 03:59:06 +08:00
< p > < strong > Read Before starting:< / strong > < / p >
< p > If you are using < strong > Docker Toolbox< / strong > (VM), do one of the following:< / p >
< ul >
2017-04-10 02:39:25 +08:00
< li > Upgrade to Docker < a href = "https://www.docker.com/products/docker" > Native< / a > for Mac/Windows (Recommended). Check out < a href = "http://laradock.io/documentation/#upgrading-laradock" > Upgrading Laradock< / a > < / li >
< li > Use Laradock v3.*. Visit the < a href = "https://github.com/laradock/laradock/tree/LaraDock-ToolBox" > LaraDock-ToolBox< / a > branch. < em > (outdated)< / em > < / li >
2017-02-23 03:59:06 +08:00
< / ul >
< p > < br > < / p >
< blockquote >
2017-03-17 05:03:05 +08:00
< p > < strong > Warning:< / strong > If you used an older version of Laradock it’ s highly recommended to rebuild the containers you need to use < a href = "#Build-Re-build-Containers" > see how you rebuild a container< / a > in order to prevent as much errors as possible.< / p >
2017-02-23 03:59:06 +08:00
< / blockquote >
< p > < br > < / p >
2017-03-17 14:46:19 +08:00
< p > 1 - Enter the laradock folder and rename < code > env-example< / code > to < code > .env< / code > < / p >
< pre > < code class = "language-shell" > cp env-example .env
< / code > < / pre >
< p > You can edit the < code > .env< / code > file to chose which software’ s you want to be installed in your environment. You can always refer to the < code > docker-compose.yml< / code > file to see how those variables are been used.< / p >
< p > 2 - Build the enviroment and run it using < code > docker-compose< / code > < / p >
2017-02-23 03:59:06 +08:00
2017-03-17 14:46:19 +08:00
< p > In this example we’ ll see how to run NGINX (web server) and MySQL (database engine) to host a PHP Web Scripts:< / p >
2017-02-23 03:59:06 +08:00
< pre > < code class = "language-bash" > docker-compose up -d nginx mysql
< / code > < / pre >
2017-02-23 04:58:06 +08:00
< p > < strong > Note< / strong > : The < code > workspace< / code > and < code > php-fpm< / code > will run automatically in most of the cases, so no need to specify them in the < code > up< / code > command. If you couldn’ t find them running then you need specify them as follow: < code > docker-compose up -d nginx php-fpm mysql workspace< / code > .< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 14:46:19 +08:00
< p > You can select your own combination of containers form the list below:< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 14:46:19 +08:00
< blockquote >
2017-04-10 02:39:25 +08:00
< p > < code > nginx< / code > , < code > hhvm< / code > , < code > php-fpm< / code > , < code > mysql< / code > , < code > redis< / code > , < code > postgres< / code > , < code > mariadb< / code > , < code > neo4j< / code > , < code > mongo< / code > , < code > apache2< / code > , < code > caddy< / code > , < code > memcached< / code > , < code > beanstalkd< / code > , < code > beanstalkd-console< / code > , < code > rabbitmq< / code > , < code > beanstalkd-console< / code > , < code > workspace< / code > , < code > phpmyadmin< / code > , < code > adminer< / code > , < code > aerospike< / code > , < code > pgadmin< / code > , < code > elasticsearch< / code > , < code > rethinkdb< / code > , < code > postgres-postgis< / code > , < code > certbot< / code > , < code > mailhog< / code > , < code > minio< / code > and more… !< / p >
2017-03-17 14:46:19 +08:00
< / blockquote >
2017-03-17 05:03:05 +08:00
< p > < em > (Please note that sometimes we forget to update the docs, so check the < code > docker-compose.yml< / code > file to see an updated list of all available containers).< / em > < / p >
2017-02-23 03:59:06 +08:00
< p > < br >
2017-03-17 14:46:19 +08:00
3 - Enter the Workspace container, to execute commands like (Artisan, Composer, PHPUnit, Gulp, … )< / p >
2017-02-23 03:59:06 +08:00
< pre > < code class = "language-bash" > docker-compose exec workspace bash
< / code > < / pre >
2017-03-17 14:46:19 +08:00
< p > < em > Alternatively, for Windows PowerShell users: execute the following command to enter any running container:< / em > < / p >
2017-02-23 03:59:06 +08:00
< pre > < code class = "language-bash" > docker exec -it {workspace-container-id} bash
< / code > < / pre >
2017-03-17 05:03:05 +08:00
< p > < strong > Note:< / strong > You can add < code > --user=laradock< / code > to have files created as your host’ s user. Example:< / p >
< pre > < code class = "language-shell" > docker-compose exec --user=laradock workspace bash
< / code > < / pre >
2017-03-17 14:46:19 +08:00
< p > < em > You can change the PUID (User id) and PGID (group id) variables from the < code > .env< / code > file)< / em > < / p >
2017-02-23 03:59:06 +08:00
< p > < br >
2017-03-17 14:46:19 +08:00
4 - Update your project configurations to use the database host< / p >
2017-02-23 03:59:06 +08:00
2017-03-17 14:46:19 +08:00
< p > Open your PHP project’ s < code > .env< / code > file or whichever configuration file you are reading from, and set the database host < code > DB_HOST< / code > to < code > mysql< / code > :< / p >
2017-02-23 03:59:06 +08:00
< pre > < code class = "language-env" > DB_HOST=mysql
< / code > < / pre >
2017-03-17 05:03:05 +08:00
< p > < em > If you want to install Laravel as PHP project, see < a href = "#Install-Laravel" > How to Install Laravel in a Docker Container< / a > .< / em > < / p >
2017-02-23 03:59:06 +08:00
< p > < br >
2017-03-17 14:46:19 +08:00
5 - Open your browser and visit your localhost address < code > http://localhost/< / code > . If you followed the multiple projects setup, you can visit < code > http://project-1.dev/< / code > and < code > http://project-2.dev/< / code > . But first don’ t< / p >
2017-02-23 03:59:06 +08:00
< aside class = "copyright" role = "note" >
Documentation built with
< a href = "https://www.gohugo.io" target = "_blank" > Hugo< / a >
using the
< a href = "http://github.com/digitalcraftsman/hugo-material-docs" target = "_blank" > Material< / a > theme.
< / aside >
< footer class = "footer" >
< nav class = "pagination" aria-label = "Footer" >
< div class = "previous" >
2017-02-23 12:08:54 +08:00
< a href = "http://laradock.io/introduction/" title = "Introduction" >
2017-02-23 04:58:06 +08:00
< span class = "direction" >
Previous
< / span >
< div class = "page" >
< div class = "button button-previous" role = "button" aria-label = "Previous" >
< i class = "icon icon-back" > < / i >
< / div >
< div class = "stretch" >
< div class = "title" >
2017-02-23 12:08:54 +08:00
Introduction
2017-02-23 04:58:06 +08:00
< / div >
< / div >
< / div >
< / a >
2017-02-23 03:59:06 +08:00
< / div >
< div class = "next" >
2017-02-23 04:13:04 +08:00
< a href = "http://laradock.io/documentation/" title = "Documentation" >
2017-02-23 03:59:06 +08:00
< span class = "direction" >
Next
< / span >
< div class = "page" >
< div class = "stretch" >
< div class = "title" >
2017-02-23 04:13:04 +08:00
Documentation
2017-02-23 03:59:06 +08:00
< / div >
< / div >
< div class = "button button-next" role = "button" aria-label = "Next" >
< i class = "icon icon-forward" > < / i >
< / div >
< / div >
< / a >
< / div >
< / nav >
< / footer >
< / div >
< / article >
< div class = "results" role = "status" aria-live = "polite" >
< div class = "scrollable" >
< div class = "wrapper" >
< div class = "meta" > < / div >
< div class = "list" > < / div >
< / div >
< / div >
< / div >
< / main >
< script >
2017-03-11 02:48:13 +08:00
var base_url = '';
var repo_id = '';
2017-02-23 03:59:06 +08:00
< / script >
2017-02-23 04:13:04 +08:00
< script src = "http://laradock.io/javascripts/application.js" > < / script >
2017-02-23 03:59:06 +08:00
< script >
/* Add headers to scrollspy */
var headers = document.getElementsByTagName("h2");
var scrollspy = document.getElementById('scrollspy');
if(scrollspy) {
if(headers.length > 0) {
for(var i = 0; i < headers.length ; i + + ) {
var li = document.createElement("li");
li.setAttribute("class", "anchor");
var a = document.createElement("a");
a.setAttribute("href", "#" + headers[i].id);
a.setAttribute("title", headers[i].innerHTML);
a.innerHTML = headers[i].innerHTML;
li.appendChild(a)
scrollspy.appendChild(li);
}
} else {
scrollspy.parentElement.removeChild(scrollspy)
}
/* Add permanent link next to the headers */
var headers = document.querySelectorAll("h1, h2, h3, h4, h5, h6");
for(var i = 0; i < headers.length ; i + + ) {
var a = document.createElement("a");
a.setAttribute("class", "headerlink");
a.setAttribute("href", "#" + headers[i].id);
a.setAttribute("title", "Permanent link")
a.innerHTML = "#";
headers[i].appendChild(a);
}
}
< / script >
2017-02-23 12:08:54 +08:00
< script >
(function(i,s,o,g,r,a,m){
i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||
[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;
m.parentNode.insertBefore(a,m)
})(window, document,
'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-37514928-9', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
var buttons = document.querySelectorAll('a');
Array.prototype.map.call(buttons, function(item) {
if (item.host != document.location.host) {
item.addEventListener('click', function() {
var action = item.getAttribute('data-action') || 'follow';
ga('send', 'event', 'outbound', action, item.href);
});
}
});
var query = document.querySelector('.query');
query.addEventListener('blur', function() {
if (this.value) {
var path = document.location.pathname;
ga('send', 'pageview', path + '?q=' + this.value);
}
});
< / script >
2017-02-23 03:59:06 +08:00
< script src = "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js" > < / script >
< script > hljs . initHighlightingOnLoad ( ) ; < / script >
< / body >
< / html >