通过jekyll建立静态网页

部署一个网站需要三个步骤:(1) generating the site, (2) deploying it to the public Internet, and (3) assigning it a custom domain name. 下面就每一步做详细解释:

1.网站的生成

Jekyll是一个常用的简单地网站生成器。

1.1 首先,安装jekyll,打开终端,输入以下命令:

,如果权限不够,改为输入sudo gem install jekyll.

安装成功后会提示:

1.2 生成静态网页:首先我们要用jekyll的new 命令去生成一个目录,这个目录包含了你的网站的所有默认内容。在终端输入:

即生成了一个my-portfolio-site的网站目录,用ls命令可以去查看证实你的目录是否成功生成。

1.3 网站预览:要想在本地查看你的网站,首先你要用cd 命令进入你的网站目录,在该目录下输入

这个命令开启了一个本地的服务器,将你的文件提交到你的电脑,如果你想查看你对网站做出的修改,这条命令也是必要的。

默认的,jekyll的这个serve命令创建的本地服务器地址为http://localhost:4000/

打开浏览器,输入http://localhost:4000/。即可看到:

1.4 jekyll的目录结构

jekyll生成的网站和你自己建立的是不同的,它提供了一个标准的目录结构和组成部分,帮助你快速开发。下面来了解一下jekyll默认的网站目录结构和内容:

  1. _config.yml - 这是一个你只需要编辑一次的配置文件,需要配置的变量包括你网站的title,你的邮箱等。
  2. _includes/ - 这个目录包含了你网站要重复加载的相同部分,比如网站的header和footer。
  3. _posts/ -这个目录是用来存储blog posts,可以添加新的blog,可以根据网站的style进行渲染,只要文件名遵从jekyll的标准命名规则。
  4. _layouts/ -这个目录包含 该目录包含了用于设计某些类型的站点内的职位模板。例如,新的博客文章将使用post.html定义的HTML布局。

2. 部署你的网站到GitHub上的页面

有许多不同的方式来部署一个网站到公共互联网。在这个里,将使用GitHub的页面来部署自己的网站,因为GitHub上的页面为jekyll提供了丰富的集成和支持。 首先,创建一个github账号,这里不多赘述。接下来在 GitHub页面上新建一个repository用来存储你网站的内容。你的repository必须符合GitHub Page的命名规则,否则你的站点无法发布。具体的,应以以下形式命名repository:

下面,我们将使用git将你的站点目录push到你的新repo中,在这之前,我们先初始化你站点目录里的 Git repository

使用cd命令进入你的站点目录,输入以下命令初始化 Git repository

接着,Git需要知道哪个repo来存储你的站点,也就是我们之前建立的新repo,为了通过git明确是这个repo,我们需要添加一个remote,并且标签器为origin,remote是这个用来存储你的站点的repo的url,origin是remote的别名,可以把别名视为一个简称或者替代名,这就意味着不需要每次输入冗长的remote URL , 你只需要稍后将它指向origin即可。用如下命令在终端中添加remote:

If you accidentally make a mistake when adding the remote URL, you can start over and remove the remote with the following command:

为了确认remote是否成功添加,可输入:

通过下述命令添加你站点内的所有内容:

commit可以保存你对网站的修改和变化:

现在我们将用git的push命令将你的站点内容push到你的repo中:

回顾一下步骤2 :

Let‘s review what you accomplished in this unit:

  1. Created a GitHub account
  2. Created the required GitHub repo
  3. Used Git to add, commit, and push your website to the repo
  4. Succesfully used GitHub Pages to deploy your site to the Internet!

3.Assign a Custom Domain Name to Your Website  指定自定义域名到您的网站

去AWS(amazon web services)买域名,然后:

  1. Inform GitHub of the new domain name we‘ll be using (the one you purchased)
  2. Set up DNS records in Route 53 that direct to GitHub

具体操作为:

  1. open GitHub and access the repo you created earlier titled your-user-name.github.io.
  2. Click the "New file" button.
  3. Name the new file CNAME. Do not add a file name extension.
  4. In the file, on line 1, type the custom domain name you just purchased in the following format:

    You may have purchased a domain name with a TLD other than .com. In that case, make sure to use that TLD when creating the CNAME file.

  5. Commit the new file
  6. Under the title of the repo, click on "Settings." Scroll down to the section titled "GitHub Pages" and confirm that there is a message similar to the following:

  7. Next, we have to let the rest of the Internet know that we want to associate the custom domain name with your GitHub Pages site.We can do this by creating DNS records, which are globally accessible records that map domain names to servers.The DNS records are created inside of a Hosted Zone in Route 53. A Hosted Zone is essentially a group of DNS records for a single domain.
  8. access Route 53 once again. On the left side of the page, click on the title that says "Hosted Zones." Notice that you have a Hosted Zone for your new domain name.
  9. Domain names are associated with the correct DNS records by setting the domain name‘s name servers.

    After a domain name is typed into a browser, the computer first retrieves the name servers that correspond to that domain name. The name servers are important because they‘re responsible with providing the computer with other important information (in the form of DNS records) associated with the domain name.

    Setting your domain‘s name servers is important. The DNS is a global system, which means that anyone can create DNS records. We must verify that the DNS records we create were actually created by the owner of the domain name (in this case, you).

    By doing this, the owner of a domain name ensures that only they have exclusive control over their domain‘s DNS records.

    1. Notice that the Hosted Zone for your domain name already has an NS(Name server) record. This record contains four values. These are the Hosted Zone‘s unique name servers. Take note of these values and copy them down somewhere.
    2. On the left hand side, under "Domains," click on "Registered domains." Then, click on your domain name.
    3. On the right hand side of the page, locate the section titled "Name Servers." Notice that these are the same name servers that your Hosted Zone‘s NS record contained. Route 53 did this for you automatically.

    10.Now that your domain name is associated with the correct name servers, it‘s time to create some additional DNS records within the Hosted Zone.

    The records that we‘ll create will be used by the name servers to help locate your site when a computer wants to load it. Specifically, the name servers will be responsible for providing that computer with important information stored in the records.

    There are several different types of DNS records.

    We‘re going to start by creating an Arecord, which stands for Address record.

    An A record directs a domain name to an IP address. This record will associate our new custom domain name with Github‘s servers.

    1. inside of your Hosted Zone, click on the button at the top labeled "Create Record Set." A form will appear to the right. Leave the "Name:" field blank. Set the "Type:" field toA - IPv4 address.
    2. Leave the "TTL (Seconds)" value at the default of 300.
    3. In the "Value" text box, enter the following IP addresses (keep them on separate lines):

      These IP addresses belong to GitHub. We are specifying that when your custom domain name is requested, the DNS should direct the request to GitHub.

    4. Click the "Save Record Set" button at the bottom of the form.

    11.

    When setting up a website, it‘s also conventional to also set up a wwwsubdomain. www stands forworld wide web.

    Subdomains are part of a main (or root) domain. For example,www.yourcustomdomain.com is a subdomain of theyourcustomdomain.com root domain.

    We can set up a subdomain using aCNAME record, which stands forCanonical Name.

    CNAME record specifies that a domain name will be used as an alias, or substitute, for the true (canonical) domain name.

      1. Inside of your Hosted Zone, click on the button at the top labeled "Create Record Set".

    A form will appear to the right. In the "Name:" field, enter only www. Set the "Type: " field toCNAME - Canonical name. This step sets up the subdomain.

      2. In the Value text box, enter the domain name that GitHub assigned to you earlier (the canonical domain name:

      3.Click the "Save Record Set" button at the bottom of the form.

    Let‘s review your DNS setup so far.

    In Route 53, your domain name‘s Hosted Zone contains the following:

    1. The NS (Name Server) record for your domain name. When a domain name is typed into a browser, the DNS looks to these name servers to help direct the request.
    2. The A (or Alias) record. This record is used to direct requests of your domain name to GitHub‘s servers using their IP addresses.
    3. The CNAME (or Canonical name) record. This record specifies what custom domain will point to your true (canonical) domain.

    You‘ve now created two DNS records: anA record for yourcustomdomain.comand a CNAME record forwww.yourcustomdomain.com. Let‘s make sure they both work.

    1. try opening your website using your root domain in the web browser. You should see your new GitHub Pages site.
    2. Try opening your website using yourwww subdomain in the web browser. You should see your new GitHub Pages site.

    Note: It may take a few minutes for the DNS record to take effect.

    Success! Your website should now display in the browser when you navigate to your custom domain name.

    The DNS may take some time to update records. If your site still doesn‘t load in the browser using your custom domain name, simply wait a few minutes.

    We can also use the dig command in the terminal to look up your domain name and make sure that the CNAME and A records were properly set.

    The dig (domain information groper) command is a DNS lookup utility. It can be used for a variety of things. In this case, we will use it to verify your domain name‘s DNS records.

    1. Let‘s confirm that your DNS records are correct. Type the following into the terminal:

    dig www.yourcustomdomain.com

    If all is correct, you should see an A (forA record) in the output along with the two IP addresses we added for the A record.

    You should also see CNAME in the output along with your custom domain name and the GitHub default domain name.

时间: 2024-09-28 22:49:22

通过jekyll建立静态网页的相关文章

首次使用photoshop制作简单的静态网页页面

刚刚进入IT领域,我首先接触到的是PhotoShop软件.经过一周的学习,我对PS软件已经有了初步的认识.PS首先是一款修图软件,对于图片中不太美观的地方可以按照自己的想法做任意的修改,利用"蒙版"工具可以做图片间的融合,这给我们提供了巨大的创作空间:其次,它可以进行图片和动画的制作,静态网页页面和多张图片的联动动画都可以在这里完成. 周五我做了两个简单的静态网页页面:网上购物的注册界面和登录页面,也借此检测一下自己对PS软件的掌握程度.在制作过程中,我发现许多问题并从中总结到了一些经

静态网页与动态网页的理解

静态网页的工作原理 静态网页也称为普通网页,是相对网页而言的.静态网页不是指网页中的元素都是静止不动的,而是指网页文件中没有程序代码,只有HTML(超文本标记语言)标记,一般后缀为.htm..html..shtml或.xml等.在静态网页中,可以包括GIF动画,鼠标经过Flash按钮时,按钮可能会发生变化. 静态网页一经制成,内容就不会再变化,不管何人何时访问,显示的内容都是一样的. 如果要修改网页的内容,就必须修改其源代码,然后重新上传到服务器上. 对于静态网页,用户可以直接双击打开,看到的效

静态网页VS动态网页

在做<牛腩新闻发布系统>的时候,建立的网页有.html的,还有.aspx,刚开始接触,还以为这些东西是一样的呢,当看ASP.NET视频的时候,听见里面讲课的老师有提到了这两样,原来是静态网页和动态网页之分. 静态网页 网页里面没有程序代码,不被服务器执行,静态网页每个静态网页都有一个固定的URL,通常以.htm..html等常见形式为后缀,网页内容一经发布到网站服务器上,无论是否有用户访问,每个静态网页的内容都是保存在网站服务器上的,也就是说,静态网页是实实在在保存在服务器上的文件,每个网页都

.net快速生成静态网页的方法一

一般用.net生成静态化网页方法有两种,一般是通过浏览器去触发动态的.aspx文件来达到解析网页,然后再生成网页,这种方法我们不用(因为这种方法需要浪费比较大的服务器性能,而且速度比较慢,一秒大概只能生成10个网页左右),所以我们今天要讲的是第二种方法,写一个网页模板,然后再用.net去解析标签,然后以完成这一个生成网页静态化功能(独占网络(http://www.sz886.com)-深圳网站建设-http://www.sz886.com技术人员测试过1秒可以生成100多个网页,性能非常好而且稳

Freemarker入门小案例(生成静态网页的其中一种方式)

其实生成静态网页的方式有好多种,我昨天看了一下,Freemarker是其中一种,但是Freemarker现在我们都用得比较少了,现在用得ActiveMQ用来发送信息到静态页面,不过想了一下这个小东西,还是想给大家分享一下,我的小小心得. 若项目为Maven项目,那么可以如下 在Pom.xml文件里面添加 <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</arti

第一次在Django上编写静态网页

新建一个Python Django工程: Win+R进入cmd命令界面,并cd到指定工程目录下,比如我的工程目录是E:\wamp\Apache24\www\ 输入E: 跳转E盘 输入cd wamp\Apache24\ 跳转到指定目录下 输入django-admin.py startproject www 建立Python Django工程,生成了一个文件夹www,其结构为:www/manage.pywww/__init.pysettings.pyurls.pywsgi.py 其中:manage.

Java Web学习(2):静态网页与动态网页

一静态网页 (1)静态网页概述 在网站设计中,纯粹HTML(标准通用标记语言下的一个应用)格式的网页通常被称为"静态网页",静态网页是 标准的HTML文件,它的文件扩展名是.htm..html,可以包含文本.图像.声音.FLASH动画.客户端脚本和ActiveX 控件及JAVA小程序等.静态网页是网站建设的基础,早期的网站一般都是由静态网页制作的. 静态网页是相对于动态网页而言,是指没有后台数据库.不含程序和不可交互的网页.静态网页相对更新起来比 较麻烦,适用于一般更新较少的展示型网站

如何在github上搭建一个免费的 无限流量的静态网页博客Github pages

前言: 看到很多相关的教程,但是在实际操作的时候还是遇见了不少问题,这里记录分享一下我的操作流程.免费空间用过很多,博客也用过一些,听说了github后就想试着玩一下这个静态库,感觉挺不错的,操作也比较简单,可以放些demo觉得挺不错的,看自己的喜好来搭建吧~本文原创博客地址:http://www.cnblogs.com/unofficial官网地址:www.pushself.com) 1.注册github.com账户,具体操作不描述了,英文如果不是很好可以使用翻译软件 2.新开一个一个仓库(N

静态网页开发技术-HTML

今天我重新复习了一下静态网页开发技术,概括如下. 一 .HTML文档结构与基本语法 :放置了标签的文本文档,可供浏览器解释执行的网页文件 1.注释标记 2.标记 3.属性 二.基本标记与使用 1.网页基本结构与标记 2.文本与段落标记 3.列表标签 4.超链接标签 5.图片标记 6.定时刷新或跳转 7.表格 三 HTML表单标签与表单设计 1.<FORM>标记及其属性 2  <INPUT>标记及其属性 3 <下拉列表框<SELECT>,<OPTION>