在本文中,我们将学习如何设置和配置Jekyll开发站点。Jekyll在数据库驱动的站点中提供了内容管理系统(CMS)的优势,并具有性能和安全性。它也称为博客意识,具有处理按日期组织的内容的功能。它特别适合于离线工作的人员,该人员还为轻量级编辑器提供了内容管理,该管理具有用于跟踪其网站上所做更改的版本控制。
一台装有Ubuntu 16.04的计算机。
在计算机上具有Sudo权限的用户。
在开始实际安装之前,我们将首先使用以下命令更新系统。
$ sudo apt-get update Output: Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease Get:2 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB] Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease Fetched 95.7 kB in 1s (58.1 kB/s) Reading package lists... Done
更新完成后,我们将安装Jekyll所需的依赖项,因为我们需要Ruby和诸如Make和GCC之类的开发库来编译和安装Jekyll。
$ sudo apt-get install ruby ruby-dev make gcc
Reading package lists... Done Building dependency tree Reading state information... Done … … Setting up libgmp-dev:amd64 (2:6.1.0+dfsg-2) ... Setting up libjs-jquery (1.11.3+dfsg-4) ... Setting up make (4.1-6) ... Setting up manpages-dev (4.04-2) ... Setting up rubygems-integration (1.10) ... Setting up ruby-dev:amd64 (1:2.3.0+1) ... Setting up ruby (1:2.3.0+1) ... Setting up rake (10.5.0-2) ... Processing triggers for libc-bin (2.23-0ubuntu3) ...
安装完成后,我们可以将Ruby的gem软件包与Jekyll捆绑安装。
以下是使用gem installer安装Jekyll Development服务器的命令。
$ sudo gem install jekyll bundler Fetching: liquid-3.0.6.gem (100%) Successfully installed liquid-3.0.6 Fetching: kramdown-1.12.0.gem (100%) Successfully installed kramdown-1.12.0 Fetching: mercenary-0.3.6.gem (100%) Successfully installed mercenary-0.3.6 .. .. .. Installing ri documentation for rb-inotify-0.9.7 Parsing documentation for listen-3.0.8 Installing ri documentation for listen-3.0.8 Parsing documentation for jekyll-watch-1.5.0 Fetching: bundler-1.13.6.gem (100%) Successfully installed bundler-1.13.6 Parsing documentation for bundler-1.13.6 Installing ri documentation for bundler-1.13.6 Done installing documentation for bundler after 5 seconds 19 gems installed
首先,我们将检查防火墙的状态,以便在Web浏览器上允许该站点作为开发父亲。以下是检查防火墙状态的命令–
$ sudo ufw status Output: Status: active To Action From -- ------ ---- 22 ALLOW Anywhere 80 ALLOW Anywhere 22 (v6) ALLOW Anywhere (v6) 80 (v6) ALLOW Anywhere (v6)
如我们所见,只有SSH和WWW服务已启用,意味着端口22和端口80被允许,我们需要为Jekyll打开端口4000,这是Jekyll开发服务器的默认端口。
以下是在防火墙上启用4000端口的命令–
$ sudo ufw allow 4000 Output: Rule added Rule added (v6)
现在,我们将检查防火墙状态,以交叉检查端口4000(如果已启用)。
$ sudo ufw status Output: Status: active To Action From -- ------ ---- 22 ALLOW Anywhere 80 ALLOW Anywhere 4000 ALLOW Anywhere 22 (v6) ALLOW Anywhere (v6) 80 (v6) ALLOW Anywhere (v6) 4000 (v6) ALLOW Anywhere (v6)
由于开放了必要的开发港口,我们将创建开发地点。
在主目录中,我们将在名为www的文件夹中为演示站点创建一个脚手架。
$ cd ~ $ jekyll new www OutPut: New jekyll site installed in /home/ubuntu/www. Running bundle install in /home/ubuntu/www... Fetching gem metadata from https://rubygems.org/...........Fetching version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/.Resolving dependencies... Using public_suffix 2.0.4 Using colorator 1.1.0 Using ffi 1.9.14 Using forwardable-extended 2.6.0 Using sass 3.4.22 Using rb-fsevent 0.9.8 Using kramdown 1.12.0 Using liquid 3.0.6 Using mercenary 0.3.6 Using rouge 1.11.1 Using safe_yaml 1.0.4 Installing minima 2.0.0 Using bundler 1.13.6 Using addressable 2.5.0 Using rb-inotify 0.9.7 Using pathutil 0.14.0 Using jekyll-sass-converter 1.5.0 Using listen 3.0.8 Using jekyll-watch 1.5.0 Using jekyll 3.3.1 Installing jekyll-feed 0.8.0 Bundle complete! 3 Gemfile dependencies, 21 gems now installed. Use `bundle show [gemname]` to see where a bundled gem is installed. Post-install message from minima: ---------------------------------------------- Thank you for installing minima 2.0! Minima 2.0 comes with a breaking change that renders '<your-site>/css/main.scss' redundant. That file is now bundled with this gem as '<minima>/assets/main.scss'. More Information:https://github.com/jekyll/minima#customization----------------------------------------------
这将使用其Gemfiles指定默认主题,我们现在将运行捆绑软件以安装主题。
$ cd www $ bundle install Output: Using public_suffix 2.0.4 Using colorator 1.1.0 Using ffi 1.9.14 Using forwardable-extended 2.6.0 … … Using jekyll-watch 1.5.0 Using jekyll 3.3.1 Using jekyll-feed 0.8.0 Bundle complete! 3 Gemfile dependencies, 21 gems now installed. Use `bundle show [gemname]` to see where a bundled gem is installed.
www的树形结构如下所示–
. ├── about.md ├── _config.yml ├── Gemfile ├── Gemfile.lock ├── index.md └── _posts └── 2016-11-15-welcome-to-jekyll.markdown 1 directory, 6 files
在继续进行下一步之前,我们需要在_config.yml文件中进行一些配置更改。
$ vi ~/www/_config.yml Output: The configuration file will be looks like this title: Your awesome title email: your-email@domain.com description: > # this means to ignore newlines until "baseurl:" Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description. baseurl: "" # the subpath of your site, e.g. /blog url: "ubuntu-16" # the base hostname & protocol for your site, e.g. http://example.comtwitter_username: jekyllrb github_username: jekyll # Build settings markdown: kramdown theme: minima gems: - jekyll-feed exclude: - Gemfile - Gemfile.lock
我们需要找到以下行,并用您的网站域名替换示例
url: "http://example.com" # the base hostname & protocol for your site, e.g. http://example.com
配置完成后,我们现在启动Jekyll的Web服务器。
我们需要启动Jekyll的Web服务器,该服务器将通过监视目录中的文件来支持站点开发,该目录也将生成静态网站,并且可以随时保存更改。
$ jekyll serve --host=192.168.2.117 Output: Configuration file: /home/ubuntu/www/_config.yml Configuration file: /home/ubuntu/www/_config.yml Source: /home/ubuntu/www Destination: /home/ubuntu/www/_site Incremental build: disabled. Enable with --incremental Generating... done in 0.372 seconds. Auto-regeneration: enabled for '/home/ubuntu/www' Configuration file: /home/ubuntu/www/_config.yml Server address: http://192.168.2.117:4000/Server running... press ctrl-c to stop.
服务器运行后,网站即开始运行,我们可以使用IP地址或域名访问该站点,因为这是演示站点,我们将从本地IP地址https://192.168.2.197访问它。在本文中,我们将学习设置和配置Jekyll以及安装依赖项和配置Jekyll以创建演示网站,还将学习如何启动Jekyll Web服务器。