创建hugo博客

Hugo is a great tool to use if you want to start a blog.

如果您想创建博客,Hugo是一个很好的工具。

I use Hugo myself for my blog, flaviocopes.com, and I've been using it for more than two years. I have a few reasons for loving Hugo.

我本人在博客flaviocopes.com上使用Hugo,并且已经使用了两年多。 我有几个爱雨果的理由。

First of all, it is simple, boring, flexible, and fast.

首先,它简单无聊灵活快速

The main reason is that it is simple. There’s not much you have to learn to get started.

主要原因是它很简单 。 入门不需要太多的学习。

You write content in Markdown, a format that lets me use my favorite editor (Bear) to write posts.

您以Markdown编写内容,该格式使我可以使用自己喜欢的编辑器(Bear)编写帖子。

Hugo is boring. Don’t get me wrong, this is a very positive thing. As a developer I am tempted to tweak things here and there all the time. There’s no fancy technology underlying Hugo. It’s built using Go, one of the languages I love the most, but that does not mean I want to dive into the internals of Hugo and change how it works.

雨果很无聊 。 不要误会我的意思,这是非常积极的事情。 作为开发人员,我很想一直在这里和那里进行调整。 雨果没有花哨的技术。 它是使用Go(我最喜欢的一种语言)构建的,但这并不意味着我想深入Hugo的内部并改变其工作方式。

And it does not surface any cool or next-generation stuff like many JavaScript frameworks tend to do.

而且它不会像许多JavaScript框架那样出现任何酷的或下一代的东西。

Hence it is boring, which gives me a lot of time to do what is really useful when working on a blog: writing content. I focus on the content, not on the content container.

因此,这很无聊,这使我有很多时间去做博客上真正有用的事情: 编写内容 。 我专注于内容,而不是内容容器。

That said, Hugo is pretty darn flexible. I started my own blog with an open source theme, then changed it completely over time. Sometimes I want to do things in my website that are out of the scope of a simple blog, and Hugo allows me to create those things.

就是说,雨果相当灵活 。 我以开源主题开始了自己的博客,然后随着时间的推移完全对其进行了更改。 有时我想在网站上做超出简单博客范围之内的事情,而Hugo允许我创建这些事情。

Finally, another reason I love Hugo is that it is fast. Why? First, it has Go at the core, which is known to be a very fast language. And in the Go ecosystem, there’s no concept of 100 megabytes dependencies. Things are made to be as fast as possible. Plus, Hugo does not need to do some of the fancy stuff that is needed when using fancy technology. This is a by-product of being boring.

最后,我爱雨果的另一个原因是它速度很快 。 为什么? 首先,它以Go为核心,这是一种非常快速的语言。 在Go生态系统中,没有100 MB依赖性的概念。 事情要尽可能快。 另外,Hugo不需要执行使用高级技术时所需的一些高级工作。 这是无聊的副产品。

Anyway, enough with words.

无论如何,用言语就足够了。

Hugo is amazing, especially if you are a developer and you’re willing to write in Markdown. Non-tech people might just refuse to use Markdown, and it’s perfectly understandable.

Hugo很棒,特别是如果您是开发人员并且愿意用Markdown编写。 非技术人员可能只是拒绝使用Markdown,这是完全可以理解的。

Also, you have to be prepared for a Git-centric workflow to make things really click.

另外,您还必须为以Git为中心的工作流程做好准备,以使事情真正发生点击。

This is the process for writing a blog:

这是写博客的过程:

  • write a post using Markdown, 使用Markdown撰写文章,
  • then commit your changes to a Git repository, most commonly on GitHub, 然后将您的更改提交到Git存储库(通常在GitHub上),
  • and then some glue technology deploys the changes on the server that hosts the site.然后一些粘合技术将所做的更改部署在托管站点的服务器上。

托管雨果网站 (Hosting a Hugo website)

A Hugo blog is completely static. This means you don’t need to host your own server, or use a special service for it.

一个雨果博客是完全静态的 。 这意味着您不需要托管自己的服务器,也无需为其使用特殊服务。

Netlify, Now and GitHub Pages are three great places where you can host a Hugo blog, for free.

Netlify,Now和GitHub Pages是您可以免费托管Hugo博客的三个好地方。

The only cost is the one you have to sustain for the domain name. I can’t stress enough the importance of having your own domain name. No .github.io or .netlify.com or .now.sh sites, please.

唯一的成本就是您必须维持的域名成本。 我不能太过强调拥有自己的域名的重要性。 请没有.github.io.netlify.com.now.sh网站。

My own Hugo sites are hosted on Netlify.

我自己的Hugo网站托管在Netlify上。

选择一个域 (Choose a domain)

Put your blog under your own domain. Pick one. Use your own name. And use .com or .blog. Don’t try to be clever by using a localized domain - for example, don’t use .io. .com just gives a better impression and it’s reusable for all your future projects, not just to host your blog. I picked that one.

将您的博客放在您自己的域下。 选一个。 使用您自己的名字。 并使用.com.blog 。 不要尝试通过使用本地化域来变得聪明-例如,不要使用.io.com只会给人留下更好的印象,它可用于您以后的所有项目,而不仅仅是托管您的博客。 我选了那个。

Oh and if you have an old domain lying around, just use that. Why? The older your domain is, the better.

哦,如果您周围有旧域名,请使用它。 为什么? 您的域越旧越好。

Note on subdomains: every subdomain, to Google, is a different website. So if your domain is flaviocopes.com, and you create your blog in blog.flaviocopes.com, then that’s a completely new website to Google, and it will have its own ranking separate from the main domain.

关于子域的注意事项:对于Google而言,每个子域都是一个不同的网站。 因此,如果您的域名是flaviocopes.com ,并且您在blog.flaviocopes.com创建了博客,那么对于Google而言,这是一个全新的网站,它将具有与主域名不同的排名。

My suggestion is to avoid subdomains completely.

我的建议是完全避免子域。

安装雨果 (Install Hugo)

To install Hugo on macOS, from your terminal run

要在macOS上安装Hugo,请从终端运行

brew install hugo

The brew command does not exist on your Mac? Check the Homebrew guide.

Mac上不存在brew命令? 查看Homebrew指南

For Windows and Linux, check the official installation guide.

对于Windows和Linux,请查看官方安装指南 。

创建一个雨果网站 (Create a Hugo site)

Once Hugo is installed, you can create a Hugo site by running

安装Hugo后,您可以通过运行以下命令创建一个Hugo网站

hugo new site myblog

I suggest that you run this into a www folder in your Home directory, because the command will create a new myblog folder where you run it.

我建议您将其运行到Home目录中的www文件夹中,因为该命令将在运行它的位置创建一个新的myblog文件夹。

选择一个主题 (Pick a theme)

Now before you can start you need to pick a theme. I wish Hugo included a default theme to make things straightforward, but it does not.

现在,在您可以开始之前,您需要选择一个主题。 我希望Hugo包含一个默认主题以使事情变得简单,但事实并非如此。

There are a lot of choices on https://themes.gohugo.io. My personal recommendation is to start with https://themes.gohugo.io/ghostwriter/ and tweak it later.

https://themes.gohugo.io上有很多选择。 我个人的建议是从https://themes.gohugo.io/ghostwriter/开始,然后进行调整。

I also recommend that you avoid the git clone workflow they suggest on that page. You’ll surely be tweaking the theme in the future, and I find it best to have a single repository for both content and theme. It simplifies deployment.

我还建议您避免他们在该页面上建议的git clone工作流程。 您肯定会在将来调整主题,而我发现最好为内容和主题有一个单一的存储库。 它简化了部署。

So, go to https://github.com/jbub/ghostwriter/archive/master.zip to download the current version of the theme.

因此,请转到https://github.com/jbub/ghostwriter/archive/master.zip下载当前版本的主题。

Then unpackage it in the themes/ghostwriter folder in your newly created Hugo website:

然后将其解包到新创建的Hugo网站的themes/ghostwriter文件夹中:

Notice there is an exampleSite folder in the themes/ghostwriter. Open it, and open its content subfolder. In there, you can see the page, post and project subfolders.

注意在themes/ghostwriter有一个exampleSite文件夹。 打开它,然后打开其content子文件夹。 在这里,您可以看到pagepostproject子文件夹。

Copy page and post in the content folder of the site:

复制pagepost到站点的content文件夹中:

配置 (The configuration)

The sample data also provide a sample config.toml file in themes/ghostwriter/exampleSite/config.toml. This is the Hugo configuration file, which tells Hugo some details of the configuration without you having to hardcode information in the theme.

示例数据还在themes/ghostwriter/exampleSite/config.toml提供了一个示例config.toml文件。 这是Hugo的配置文件,它告诉Hugo某些配置细节,而无需在主题中硬编码信息。

I recommend that you not copy that, because it has too many things, and instead use this:

我建议您不要复制它,因为它有太多东西,而应使用以下命令:

baseurl = "/"
title = "My blog"
theme = "ghostwriter"[Params]mainSections = ["post"]intro = trueheadline = "My headline"description = "My description"github = "https://github.com/XXX"twitter = "https://twitter.com/XXX"email = "XXX@example.com"opengraph = trueshareTwitter = truedateFormat = "Mon, Jan 2, 2006"[Permalinks]post = "/:filename/"

You can freely customize the information in this file later.

您以后可以自由自定义此文件中的信息。

Now from the command line, run:

现在从命令行运行:

hugo serve

Open http://localhost:1313 in your browser, and you should be able to see the site live!

在浏览器中打开http://localhost:1313 ,您应该可以看到该站点!

This is the site home page.

这是网站主页。

There is a list of posts that is taken from the content/post folder of your website:

以下是从您网站的content/post文件夹中获取的帖子列表:

Click the first, called “Creating a New Theme”:

单击第一个,即“创建新主题”:

You can open the file content/post/creating-a-new-theme.md to change anything in the post.

您可以打开文件content/post/creating-a-new-theme.md更改帖子中的任何内容。

If you save, the website will automatically update with the new content.

如果保存,网站将自动更新为新内容。

This is pretty awesome, right?

太棒了吧?

You can create a new post by creating a new .md file, prefixing it with anything you want. You can use incremental numbers, if you prefer. Or use a date.

您可以通过创建一个新的.md文件并在其前面加上所需的任何内容来创建新帖子。 如果愿意,可以使用增量数字。 或使用日期。

If something doesn't look the way you want, you can open the themes/ghostwriter/layouts folder and tweak it.

如果某些内容看起来不理想,可以打开themes/ghostwriter/layouts文件夹并进行调整。

The “post” template is defined in themes/ghostwriter/layouts/post/single.html:

“帖子”模板是在themes/ghostwriter/layouts/post/single.html

Hugo uses Go templates. The syntax can be pretty unfamiliar but the Hugo website does a very good job at explaining them in this Go templates introduction.

Hugo使用Go模板。 语法可能不熟悉,但是Hugo网站在此Go模板介绍中很好地解释了它们。

However, try to not look at customizing your template now.

但是,请尝试不要立即考虑自定义模板。

If you want to tweak the colors, add a <style> tag with some CSS in the themes/ghostwriter/layouts/partials/header.html.

如果要调整颜色,请在themes/ghostwriter/layouts/partials/header.html添加带有某些CSS的<style>标记。

For example, make links black:

例如,将链接设为黑色:

<style>
.site-title a, .button-square {background: black;
}
a {color: black;
}
</style>

Focus on the content instead.

专注于内容。

Remove the existing files, and write 2-3 posts to start with.

删除现有文件,并开始撰写2-3个帖子。

It’s too easy to get trapped in making things perfectly the way you want, but the important thing is the content.

被困于以您想要的方式完美地制作事物太容易了,但重要的是内容。

And the cleaner your site is, the better for your readers.

您的网站越干净,对您的读者越好。

Let me now write a little about deployment.

现在让我写一些有关部署的信息。

将Hugo网站部署到Netlify (Deploy the Hugo site to Netlify)

I want to showcase how to deploy a Hugo site in 2 of the services I enjoy the most: Netlify and Now.

我想展示如何在我最喜欢的两项服务中部署Hugo网站:Netlify和Now。

First, I’m going to create a GitHub repository to host the site.

首先,我将创建一个GitHub存储库来托管该站点。

I open GitHub Desktop, an app I use every day and that is part of my workflow. It’s the simplest way to use Git.

我打开GitHub Desktop,这是我每天使用的应用程序,它是我工作流程的一部分。 这是使用Git的最简单方法。

From the File menu, I pressed the “New Repository” option:

在“文件”菜单中,我按下了“新建存储库”选项:

The same screen can be generated by simply dragging the myblog folder into the app.

只需将myblog文件夹拖到应用中,即可生成同一屏幕。

I gave the myblog name to the repository, and picked the correct path for the repo.

我给存储库指定了myblog名称,并为仓库选择了正确的路径。

The process automatically makes the first commit:

该过程将自动进行第一次提交:

Now we can click the “Publish repository” button to push the repo to GitHub:

现在,我们可以单击“发布存储库”按钮将存储库推送到GitHub:

You can keep the repo private, of course.

当然,您可以将存储库设为私有。

Once the repo is in GitHub:

一旦仓库进入GitHub:

we can move to Netlify.

我们可以转到Netlify。

From my Netlify dashboard I pressed the “New site from Git” button:

在Netlify仪表板中,我按下了“来自Git的新站点”按钮:

I pressed GitHub, authorized Netlify to access my private repositories, then I picked the repo I just created:

我按下GitHub,授权Netlify访问我的私有存储库,然后选择了我刚创建的存储库:

Netlify automatically identified it as a Hugo repo, and entered the build command automatically:

Netlify自动将其标识为Hugo存储库,并自动输入build命令:

Clicking “Deploy site” starts the deploy process:

单击“部署站点”开始部署过程:

On a real site, I would set up a custom domain. Netlify has the option to purchase a domain through them, and it’s a very (VERY) straightforward process. I highly recommend it. The site can be live in just a few minutes after purchasing the domain.

在实际站点上,我将设置一个自定义域。 Netlify可以选择通过它们购买域名,这是一个非常非常简单的过程。 我强烈推荐它。 购买域名后,该网站仅需几分钟即可上线。

A random .netlify.com subdomain is attached to the site, in this case pedantic-engelbart-500c9a.netlify.com, and HTTPS is automatically enabled.

该站点附加一个随机的.netlify.com子域,在本例中为pedantic-engelbart-500c9a.netlify.com ,并且自动启用了HTTPS。

We can therefore immediately see the site live:

因此,我们可以立即看到该站点:

Now if you try to edit something in your local version, you just push the changes to GitHub, and Netlify will automatically update the site. You can see it building the site in the “Overview” panel of the site:

现在,如果您尝试编辑本地版本中的内容,则只需将更改推送到GitHub,Netlify就会自动更新站点。 您可以在网站的“概述”面板中看到它正在构建网站:

To learn more about Netlify I recommend that you check out my Netlify tutorial.

要了解有关Netlify的更多信息,建议您阅读我的Netlify教程 。

将Hugo网站部署到Zeit Now (Deploy the Hugo site to Zeit Now)

Another awesome platform you can use for your Hugo blog is Zeit Now.

您可以在Hugo博客上使用的另一个很棒的平台是Zeit Now。

Once you sign up, from the dashboard you press the New Project button.

注册后,从仪表板中按“ 新建项目”按钮。

The first time you deploy from GitHub you have to first install the GitHub app by clicking “Install Now For GitHub”:

首次从GitHub部署时,必须先通过单击“立即为GitHub安装”来安装GitHub应用程序:

This brings you to the GitHub page for the app, where you can authorize it for all your repos, or just for some:

这会将您带到该应用程序的GitHub页面,您可以在其中为所有存储库或仅对某些存储库进行授权:

Once you get back, click the “New Project From GitHub” button:

返回后,单击“来自GitHub的新项目”按钮:

Select the project and click “Import”:

选择项目,然后单击“导入”:

In the meantime, go into the main folder of mysite and add a package.json file with this content:

同时,进入mysite的主文件夹并添加具有以下内容的package.json文件:

{"scripts": {"build": "hugo"}
}

This tells Now how to deploy the site.

现在,这将告诉您如何部署站点。

When you get back to the dashboard, the new deploy should start soon, and you will see the site working live:

当回到仪表盘时,新的部署应该很快开始,您将看到该站点正在运行:

Note that in Now you have three URLs you can use to access the site:

请注意,在“现在”中,您可以使用三个URL来访问站点:

  • myblog.flaviocopes.now.sh

    myblog.flaviocopes.now.sh

  • myblog-alpha-swart.now.sh

    myblog-alpha-swart.now.sh

  • myblog-git-master.flaviocopes.now.sh

    myblog-git-master.flaviocopes.now.sh

You can choose the one you prefer.

您可以选择自己喜欢的一种。

Plus, each deployment has its own URL, too. In this case I had myblog-h8xks5jhn.now.sh but it changes with every deployment.

另外,每个部署也都有自己的URL。 在这种情况下,我有myblog-h8xks5jhn.now.sh但每次部署都会改变。

And of course you can add your domain, too. Zeit has a great service to purchase your domain directly from them, available at https://zeit.co/domains.

当然,您也可以添加您的域。 Zeit提供了一项很棒的服务,可以直接从他们那里购买您的域名, 网址为https://zeit.co/domains 。

And if you prefer working with the command line, the now command lets you purchase domains from there, as well.

而且,如果您更喜欢使用命令行,那么now命令也可以让您从那里购买域名。

I highly recommend that you check out my Zeit Now tutorial to learn more about this platform.

我强烈建议您查看我的Zeit Now教程,以了解有关此平台的更多信息。

结语 (Wrapping up)

I hope this tutorial can give you a little guidance if you are planning to start a new blog. Hugo is my favorite platform, but it's not unique of course. Ghost (the platform powering freeCodeCamp) is great too, along with WordPress of course, and Gatsby.

我希望本教程可以为您提供一些指导,如果您打算开始一个新博客。 Hugo是我最喜欢的平台,但是它并不是唯一的平台。 Ghost(支持freeCodeCamp的平台)也很棒,当然还有WordPress和Gatsby。

Pick your favorite. In my opinion the platform does not matter as much as your content does. So, choose one and start writing!

选择你喜欢的。 我认为平台与内容无关紧要。 因此,选择一个并开始写作!

翻译自: https://www.freecodecamp.org/news/your-first-hugo-blog-a-practical-guide/

创建hugo博客

创建hugo博客_如何创建您的第一个Hugo博客:实用指南相关推荐

  1. 怎么搭建自己的播客_如何创建和运行自己的音频播客

    怎么搭建自己的播客 Ever feel like taking your voice to the web, literally? Podcasts are a great way to intera ...

  2. 创建存储,修改存储_安全地创建和存储密码

    创建存储,修改存储 几乎每次涉及用户配置文件时,都必须管理用户凭据,从而能够创建和存储用户密码. 通常应该使用哈希密码和盐分密码来准备数据库公开和通过使用Rainbow表进行哈希逆转. 但是,找到以明 ...

  3. python创建类统计属性_轻松创建统计数据的Python包

    python创建类统计属性 介绍 (Introduction) Sometimes you may need a distribution figure for your slide or class ...

  4. 创建react应用程序_通过创建食谱应用程序来学习在React中使用API

    创建react应用程序 Learn how to use external APIs with React and React Router in a full tutorial from Hamza ...

  5. 怎么把网页源码家入hexo博客_一款被大厂选用的 Hexo 博客主题

    首先这是一篇自吹自擂的文章,主题是由多位非前端程序员共同开发,目前经过一年半的迭代已经到达 v1.8.0 版本,并且获得大量认可,甚至某大厂员工已经选用作为内部博客,因此我决定写这篇文章向更多人安利它 ...

  6. php创建mysql计划任务_有关创建PHP-MySQL后台任务的建议

    我正在寻找有关我正在构建的东西的建议:我有一个PHP应用程序,可以创建,更新和删除记录,但它紧密集成在一个传统的非基于SQL的数据库中,当你开始时它真的很慢做了很多数据库调用. 我想为用户提供更多的后 ...

  7. 无法创建系统映像_如何创建USB驱动器的映像

    无法创建系统映像 You can back up your USB drive by creating a saved image. You can then take that saved imag ...

  8. unity创建和销毁对象_如何创建和销毁对象

    unity创建和销毁对象 本文是我们名为" 高级Java "的学院课程的一部分. 本课程旨在帮助您最有效地使用Java. 它讨论了高级主题,包括对象创建,并发,序列化,反射等. 它 ...

  9. 微信创建二维码_如何创建二维码

    微信创建二维码 QR codes aren't everyone's cup of tea but I quite like them. If I see something I want to re ...

最新文章

  1. C语言文件操作解析(二)
  2. linux非root安装go,linux – go install总是使用GOROOT / bin而不是GOPATH
  3. 说一说ffmpeg到处都在使用的ff_thread_once函数
  4. hal库选择滴答时钟函数_stm32h7“理解hal库框架”
  5. ERROR 1130: Host '192.168.1.3' is not allowed to c
  6. 【英语学习】【Level 07】U02 Live Work L2 A place to call my home
  7. BigDecimal 转 String
  8. vue的table组件
  9. 数据库返回刚插入记录的ID
  10. 二维数组求最大子数组和
  11. PKUSC2019划水记
  12. 云南省人口密度格网数据
  13. 中国最美的经典古文名篇Top10,它们也是你心中的白月光吗?
  14. 我国重点区域加快智慧城市规划布局
  15. 笔记本WIFI时断时续(已解决)2021
  16. 物业养老,智慧养老新方式
  17. 《JAVA》编程创建一个Box类(长方体),在Box类中定义三个变量
  18. 向量的平面投影 ProjectOnPlane
  19. shell 数组介绍
  20. 城市三级联动功能实现

热门文章

  1. mmap父子进程间通信
  2. 目录操作相关的系统函数
  3. 利用python脚本程序监控文件被修改
  4. Luogu 4755 Beautiful Pair
  5. Windows半透明窗口开发技巧
  6. TCP/IP网络编程之基于TCP的服务端/客户端(二)
  7. PPPOE拨号上网流程及密码窃取具体实现
  8. tiny xml 使用总结
  9. 安装设置Android Studio Win7安装
  10. 8步教你打开Android之门 NDK入门教程