Fork Mainroad
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
public/
|
||||
themes
|
||||
@@ -0,0 +1,36 @@
|
||||
baseurl = "/"
|
||||
title = "Mainroad"
|
||||
languageCode = "en-us"
|
||||
paginate = "10" # Number of posts per page
|
||||
theme = "mainroad"
|
||||
disqusShortname = "" # Enable comments by entering your Disqus shortname
|
||||
googleAnalytics = "" # Enable Google Analytics by entering your tracking id
|
||||
|
||||
[Author]
|
||||
name = "John Doe"
|
||||
bio = "John Doe's true identity is unknown. Maybe he is a successful blogger or writer. Nobody knows it."
|
||||
avatar = "img/avatar.png"
|
||||
|
||||
[Params]
|
||||
description = "John Doe's Personal blog about everything" # Description of your site
|
||||
opengraph = true
|
||||
twitter_cards = false
|
||||
readmore = false # Show "Read more" button in list if true
|
||||
authorbox = true
|
||||
pager = true
|
||||
post_meta = ["date", "categories"] # Order of post meta information
|
||||
mainSections = ["post", "docs"]
|
||||
|
||||
[Params.logo]
|
||||
subtitle = "Just another site" # Logo subtitle
|
||||
|
||||
[Params.sidebar]
|
||||
home = "right" # Configure layout for home page
|
||||
list = "right" # Configure layout for list pages
|
||||
single = "right" # Configure layout for single pages
|
||||
# Enable widgets in given order
|
||||
widgets = ["search", "recent", "categories", "taglist"]
|
||||
|
||||
[Params.widgets]
|
||||
recent_num = 5 # Set the number of articles in the "Recent articles" widget
|
||||
tags_counter = false # Enable counter for each tag in "Tags" widget (disabled by default)
|
||||
@@ -0,0 +1,41 @@
|
||||
---
|
||||
title: About
|
||||
date: 2022-01-25T14:00:00.000Z
|
||||
authorbox: false
|
||||
sidebar: false
|
||||
menu: main
|
||||
---
|
||||
|
||||
Our website builds with [Hugo](https://gohugo.io/) static site generator and
|
||||
[Mainroad](https://github.com/vimux/mainroad) theme. This demo allows you to see what Mainroad based website looks like
|
||||
before deciding to go with it. Just keep in mind that the current demo shows the basics, a small part of what the
|
||||
combination of Hugo and Mainroad can do.
|
||||
|
||||
## About Mainroad
|
||||
|
||||
Mainroad is a responsive, simple, clean and content-focused Hugo theme based on the MH Magazine lite WordPress theme.
|
||||
|
||||
Main features:
|
||||
|
||||
* Responsive design
|
||||
* Main & secondary menus
|
||||
* Widgetized sidebar
|
||||
* Translations. Over 15 languages and counting
|
||||
* Configurable theme settings (sidebar position, author box, post navigation, highlight color) via config.toml
|
||||
* Hugo internal templates (Open Graph, Schema, Twitter Cards, Disqus, Google Analytics)
|
||||
* Wide cross-browser compatibility
|
||||
* Desktop: IE11+, Chrome, Firefox, Safari
|
||||
* Mobile: Android browser (on Android 4.4+), Safari (on iOS 7+), Google Chrome, Opera mini
|
||||
* Custom Google Fonts support, MathJax, Table of Contents, SVG icons and much more…
|
||||
|
||||
Learn more on [GitHub](https://github.com/vimux/mainroad). Mainroad theme is released under the
|
||||
[GPLv2 license](https://github.com/vimux/mainroad/blob/master/LICENSE.md).
|
||||
|
||||
## About Hugo
|
||||
|
||||
Hugo is a static HTML and CSS website generator written in Go. It is optimized for speed, ease of use, and
|
||||
configurability. Hugo takes a directory with content and templates and renders them into a full HTML website. With its
|
||||
amazing speed and flexibility, Hugo makes building websites fun again.
|
||||
|
||||
Learn more on [GitHub](https://github.com/gohugoio/hugo). Complete documentation is available at
|
||||
[Hugo Documentation](https://gohugo.io/getting-started/).
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: Documentation
|
||||
description: Mainroad theme documentation, including getting started, customization guides, and FAQ.
|
||||
---
|
||||
@@ -0,0 +1,269 @@
|
||||
---
|
||||
title: Customization
|
||||
description: Describes common Mainroad theme configuration parameters that can be adjusted via config file or via Front
|
||||
Matter section.
|
||||
lead: Describes common Mainroad theme configuration parameters that can be adjusted via config file or via Front Matter
|
||||
section.
|
||||
date: 2022-01-24T14:00:00.000Z
|
||||
thumbnail:
|
||||
src: "img/placeholder.png"
|
||||
visibility:
|
||||
- list
|
||||
authorbox: false
|
||||
sidebar: false
|
||||
pager: false
|
||||
weight: 2
|
||||
menu: main
|
||||
---
|
||||
|
||||
Customization page describes common Mainroad configuration parameters which can be specified via configuration file or
|
||||
via Front Matter section. That includes logo section tuning, adding a sidebar with widgets, adjusting highlight color,
|
||||
and more.
|
||||
|
||||
<!--more-->
|
||||
|
||||
This section will mainly cover customization settings that are unique to this theme. If something is not covered here,
|
||||
there's a good chance it is covered somewhere in [Hugo docs](https://gohugo.io/documentation/).
|
||||
|
||||
### Logo
|
||||
|
||||
**Mainroad** allows you to set a custom logo in the site header. You may use text, or image, or both. Use the following
|
||||
options in your site config:
|
||||
|
||||
```toml
|
||||
[Params.logo]
|
||||
image = "img/placeholder.png"
|
||||
title = "Mainroad"
|
||||
subtitle = "Just another site"
|
||||
```
|
||||
|
||||
**Note:** logo image will display at a maximum width of 128 pixels and a maximum height of 128 pixels
|
||||
when you use text and image simultaneously. When the only logo image is active, it will display at a maximum height of
|
||||
256 pixels. Ideally, your logo image should be SVG.
|
||||
|
||||
---
|
||||
|
||||
If you don't set any of these variables, the theme uses the site title as a logo title. Don't need a logo section?
|
||||
Disable it this way:
|
||||
|
||||
```toml
|
||||
[Params.logo]
|
||||
image = false
|
||||
title = false
|
||||
subtitle = false
|
||||
```
|
||||
|
||||
### Highlight color
|
||||
|
||||
Mainroad uses `#e22d30` as a default highlight color, but you may choose and set any other color.
|
||||
|
||||
```toml
|
||||
[Params.style.vars]
|
||||
highlightColor = "#e22d30"
|
||||
```
|
||||
|
||||
### Thumbnail visibility
|
||||
|
||||
By default, a thumbnail image has shown for a list and single pages simultaneously. In some cases, you may want to show
|
||||
a thumbnail for list-like pages only and hide it on single pages (or vice versa). Control global thumbnail visibility
|
||||
via config, use the key `visibility` with combination of valid values `"list"` and `"post"`.
|
||||
|
||||
```toml
|
||||
[Params.thumbnail]
|
||||
# Show thumbnail only for list items
|
||||
visibility = ["list"]
|
||||
```
|
||||
|
||||
Besides global configuration, you can change thumbnail visibility individually with extended thumbnail notation via
|
||||
front matter block.
|
||||
|
||||
```yaml
|
||||
thumbnail:
|
||||
src: "img/placeholder.png"
|
||||
visibility:
|
||||
- list
|
||||
- post
|
||||
```
|
||||
|
||||
This page is an example of list-only thumbnail visibility.
|
||||
|
||||
### Sidebar
|
||||
|
||||
**Mainroad** comes with a configurable sidebar that can be on the left, on the right, or disabled. The default layout
|
||||
can be specified in the `[Params.sidebar]` section of the configuration. The position can be specified for home, list
|
||||
and single pages individually. Use the keys `home`, `list` and `single` with values `"left"`, `"right"` or `false`.
|
||||
|
||||
```toml
|
||||
[Params.sidebar]
|
||||
home = "right"
|
||||
list = "right"
|
||||
single = "right"
|
||||
```
|
||||
|
||||
The layout can be configured per page, by setting the `sidebar` parameter with one of the same values (`"left"`,
|
||||
`"right"` or `false`) in the page's front matter.
|
||||
|
||||
```yaml
|
||||
sidebar: "left" # Enable sidebar (on the left side) per page
|
||||
```
|
||||
|
||||
The sidebar consists of multiple widgets. Widgets can be enabled individually using the `widgets` key with a list of
|
||||
widget names as value. You can add your own widgets, by placing a template under `layouts/partials/widgets/<name>.html`.
|
||||
|
||||
```toml
|
||||
[Params.sidebar]
|
||||
# Enable widgets in given order
|
||||
widgets = ["search", "recent", "categories", "taglist", "social", "languages"]
|
||||
```
|
||||
|
||||
The list of widgets can be overwritten from a page's front matter.
|
||||
|
||||
```yaml
|
||||
# Enable sidebar widgets in given order
|
||||
widgets:
|
||||
- "search"
|
||||
- "recent"
|
||||
- "taglist"
|
||||
```
|
||||
|
||||
Full list of available default widgets:
|
||||
|
||||
* `search`, `ddg-search`, `recent`, `categories`, `taglist`, `social`, `languages`
|
||||
|
||||
---
|
||||
|
||||
Some of our widgets respect optional configuration. Have a look at the `[Params.widgets]` and `[Params.widgets.social]`
|
||||
sections in the example below.
|
||||
|
||||
```toml
|
||||
[Params.widgets]
|
||||
recent_num = 5 # Set the number of articles in the "Recent articles" widget
|
||||
categories_counter = false # Enable counter for each category in "Categories" widget
|
||||
tags_counter = false # Enable counter for each tag in "Tags" widget
|
||||
```
|
||||
|
||||
```toml
|
||||
[Params.widgets.social]
|
||||
# Enable parts of social widget
|
||||
facebook = "username"
|
||||
twitter = "username"
|
||||
instagram = "username"
|
||||
linkedin = "username"
|
||||
telegram = "username"
|
||||
github = "username"
|
||||
gitlab = "username"
|
||||
bitbucket = "username"
|
||||
email = "example@example.com"
|
||||
```
|
||||
|
||||
### Social Widget: custom links
|
||||
|
||||
**Mainroad** contains built-in social links in the social widget. In addition to default social links, you may set
|
||||
custom links by adding `Params.widgets.social.custom` to your `config.toml`. Here is an example:
|
||||
|
||||
```toml
|
||||
[[Params.widgets.social.custom]]
|
||||
title = "My Home Page"
|
||||
url = "https://example.com"
|
||||
```
|
||||
|
||||
If you want to display an icon of your social link, you need to put SVG icon file in `layouts/partials` directory under
|
||||
your site's root. The `icon` key filed, which is optional, should be a path relative to `layouts/partials`.
|
||||
|
||||
```toml
|
||||
[[Params.widgets.social.custom]]
|
||||
title = "Youtube"
|
||||
url = "https://youtube.com/user/username"
|
||||
icon = "youtube.svg"
|
||||
```
|
||||
|
||||
**Note:** *Only* SVG files are supported to be used as custom social icons. If you use any other files, PNG for example,
|
||||
a compile error will be raised by Hugo. Moreover, not every SVG icon can be used. For better results, it should be
|
||||
one-color SVG file with a special class attribute `{{ with .class }}{{ . }} {{ end }}` and 24x24 size. At a minimum,
|
||||
custom SVG icon needs these attributes:
|
||||
|
||||
```html
|
||||
<svg class="{{ with .class }}{{ . }} {{ end }} icon" width="24" height="24">...</svg>
|
||||
```
|
||||
|
||||
### Menus
|
||||
|
||||
**Mainroad** supports multiple menus. The `main` menu is fully responsive and displayed right under the site header. The
|
||||
secondary menus `side` and `footer` are displayed in a sidebar widget and the page footer respectively. To add a page to
|
||||
a menu, add a `menu: <menu>` parameter to the page's front matter:
|
||||
|
||||
```yaml
|
||||
menu: main # Add page to a main menu
|
||||
```
|
||||
|
||||
**Note:** Don't forget to enable the `sidemenu` widget in the `widgets` configuration param if you want to use the
|
||||
`side` menu.
|
||||
|
||||
---
|
||||
|
||||
You can also add a page to multiple menus by providing a list:
|
||||
|
||||
```yaml
|
||||
# Add page to a main, side, and footer menu
|
||||
menu:
|
||||
- main
|
||||
- side
|
||||
- footer
|
||||
```
|
||||
|
||||
**Note:** Please keep in mind that Mainroad menus don't support nested items i.e. submenus.
|
||||
|
||||
See [Menus](https://gohugo.io/content-management/menus/#readout) from official Hugo documentation for more info.
|
||||
|
||||
### Custom Google Fonts support
|
||||
|
||||
Mainroad uses Open Sans from Google Fonts as a main font. But you can use any other font from Google Fonts if you'd
|
||||
like. Beware, in most cases, such changes require manual CSS adjustment because every set of fonts is different and
|
||||
might not look as good as our default font.
|
||||
|
||||
Follow the procedure below.
|
||||
|
||||
1. Open Google Fonts, choose font(s) that you prefer and copy href font link. For this particular example, we choose
|
||||
[Roboto with 3 different styles](https://fonts.google.com/share?selection.family=Roboto:ital,wght@0,400;0,700;1,400;1,700).
|
||||
Our href font link:
|
||||
|
||||
```
|
||||
https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400&display=swap
|
||||
```
|
||||
|
||||
1. Set `googleFontsLink` site's config param value to your href font link. For example:
|
||||
|
||||
```toml
|
||||
[Params]
|
||||
googleFontsLink = "https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400&display=swap"
|
||||
```
|
||||
|
||||
1. Override default font-family set(s):
|
||||
|
||||
```toml
|
||||
[Params.style.vars]
|
||||
fontFamilyPrimary = "'Roboto', sans-serif"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
It is possible to disable Google Fonts and use system font stack instead.
|
||||
|
||||
1. Disable Google Fonts include. Set `googleFontsLink` site's config param value to `false`:
|
||||
|
||||
```toml
|
||||
[Params]
|
||||
googleFontsLink = false
|
||||
```
|
||||
|
||||
1. Override font-family sets:
|
||||
|
||||
```toml
|
||||
[Params.style.vars]
|
||||
# Override font-family sets. Take care of different quotes OR escaping symbols in these params if necessary
|
||||
fontFamilyPrimary = "system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'Liberation Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'"
|
||||
# Secondary font-family set responsible for pre, code, kbd, and samp tags font
|
||||
fontFamilySecondary = "SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace"
|
||||
```
|
||||
|
||||
[Edit this page on GitHub](https://github.com/vimux/mainroad/blob/master/exampleSite/content/docs/customization.md)
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
title: Frequently asked questions (FAQ)
|
||||
description: Browse this FAQ page to find answers to frequently asked questions that have not been covered elsewhere in
|
||||
the documentation.
|
||||
date: 2022-01-24T14:00:00.000Z
|
||||
authorbox: false
|
||||
sidebar: false
|
||||
pager: false
|
||||
weight: 3
|
||||
menu:
|
||||
main:
|
||||
name: FAQ
|
||||
---
|
||||
|
||||
Browse this FAQ page to find a collection of answers to frequently asked questions that have not been covered elsewhere
|
||||
in the documentation.
|
||||
|
||||
<!--more-->
|
||||
|
||||
The answers have been categorized into two groups. Those are answers to general questions without any lines of code, and
|
||||
those are answers to technical questions with code snippets, step-by-step instructions, etc.
|
||||
|
||||
## General questions
|
||||
|
||||
### Do I need to have some prior experience before proceed with Mainroad theme?
|
||||
|
||||
**Yes.** We expect that you already have prior experience with Hugo, at least.
|
||||
[Our docs section]({{< ref "/docs/_index.md" >}} "Mainroad theme documentation") is for intermediate users and
|
||||
developers, not novice users with zero or minimal experience. Still, all documentation pages would be helpful even if
|
||||
you don't have such experience. Just don't expect all your typical questions answered here.
|
||||
|
||||
### Do I need to use the extended version of Hugo?
|
||||
|
||||
**No.** Mainroad theme intentionally does not use any features of the extended version. As such, the extended version of
|
||||
Hugo is not required (but applicable).
|
||||
|
||||
### Is there a list of all possible configuration options?
|
||||
|
||||
**Configuration:**
|
||||
|
||||
* See [All Configuration Settings](https://gohugo.io/getting-started/configuration/#all-configuration-settings) section
|
||||
for the full list of Hugo-defined variables with their default value.
|
||||
* See [Mainroad config.toml example](https://github.com/Vimux/Mainroad#configtoml-example) for the full list of
|
||||
Mainroad-specific variables.
|
||||
|
||||
**Front Matter:**
|
||||
|
||||
* See [Front Matter Variables](https://gohugo.io/content-management/front-matter#front-matter-variables) section for the
|
||||
list of Hugo-defined Front Matter variables.
|
||||
* See [Mainroad Front Matter example](https://github.com/Vimux/Mainroad#front-matter-example) section for the list of
|
||||
Mainroad-specific Front Matter variables.
|
||||
|
||||
### What if I have more questions? May I should create an issue?
|
||||
|
||||
**We don't provide free personal technical support.** As stated in
|
||||
[CONTRIBUTING](https://github.com/Vimux/Mainroad/blob/master/CONTRIBUTING.md), please do not use the issue tracker for
|
||||
personal support. This includes any reports like “how to do this or that”; “everything broken, help me”; “I changed
|
||||
something, it doesn't work anymore”; “It's not a personal issue, I just want to ask how X or Y works”; “I forked your
|
||||
theme, then something broken, fix this immediately” and so on. **The issue tracker is the preferred channel for bug
|
||||
reports, feature requests, and discussions that comply with our contributing rules**, nothing more. All other issues
|
||||
would be closed and marked as invalid.
|
||||
|
||||
## Technical questions
|
||||
|
||||
**I wanted to get the `favicon.ico` and `apple-touch-icon.png` to match my `hightlightColor`, what should I do?**
|
||||
|
||||
There is no way to do this on the fly with Hugo, but you may use two one-liners below with some preparations:
|
||||
|
||||
1. Copy:
|
||||
* `./themes/mainroad/favicon.ico` to `./static/favicon.ico`
|
||||
* `./themes/mainroad/apple-touch-icon.png` to `./static/apple-touch-icon.png`
|
||||
1. Replace the color in variable to your preferred at the beginning of both scripts. Beware, you should use full
|
||||
six-digit Hex triplet notation (e.g., `#E22D30`) to make it work properly.
|
||||
|
||||
Go to the root of your project directory in the terminal and execute this two commands accordingly.
|
||||
|
||||
```
|
||||
a=#E22D30;a=\\x${a:5:2}\\x${a:3:2}\\x${a:1:2};for i in 98 274 578;do printf $a|dd of=static/favicon.ico bs=1 seek=$i conv=notrunc;done
|
||||
```
|
||||
|
||||
```
|
||||
a=#E22D30;a=$(echo 504C54452A2A2A${a:1:6}|sed -e 's/../\\x&/g');printf $a|gzip|tail -c8|od -tx4 -N4 -An|xargs|sed -e 's/../\\x&/g'|printf $a$(cat -)|dd of=static/apple-touch-icon.png bs=1 seek=37 conv=notrunc
|
||||
```
|
||||
|
||||
[Edit this page on GitHub](https://github.com/vimux/mainroad/blob/master/exampleSite/content/docs/faq.md)
|
||||
@@ -0,0 +1,89 @@
|
||||
---
|
||||
title: Getting started
|
||||
description: This article helps you get started with the Mainroad theme, including installation and minimal
|
||||
configuration.
|
||||
lead: This article helps you get started with the Mainroad theme, including installation and minimal configuration.
|
||||
date: 2022-01-24T14:00:00.000Z
|
||||
tags:
|
||||
- "Installation"
|
||||
authorbox: false
|
||||
sidebar: false
|
||||
pager: false
|
||||
weight: 1
|
||||
menu: main
|
||||
---
|
||||
|
||||
Welcome to the Mainroad theme documentation. This quick guide has been written for intermediate and advanced users who
|
||||
are interested in getting started with the Mainroad theme, including installation and minimal configuration. To fully
|
||||
understand the rest of this guide, you need to be familiar with the main concepts of the [Hugo](https://gohugo.io/)
|
||||
static site generator.
|
||||
|
||||
<!--more-->
|
||||
|
||||
## Installation
|
||||
|
||||
To begin with **Mainroad** theme, you should have
|
||||
[**Hugo** (version 0.48 or later) installed](https://gohugo.io/getting-started/quick-start/#step-1-install-hugo) and
|
||||
[create a new site](https://gohugo.io/getting-started/quick-start/#step-2-create-a-new-site). For comprehensive Hugo
|
||||
installation guide, please visit [Hugo Documentation](https://gohugo.io/getting-started/installing/). After that, you
|
||||
are ready to install Mainroad theme.
|
||||
|
||||
There are a few options to install a theme in Hugo. This can be done via git submodule, git clone, Hugo modules, or even
|
||||
by downloading the archive and manually copying the files. Use what you know and what works best for you. Three
|
||||
installation options are described below.
|
||||
|
||||
### Option A: `git submodule`
|
||||
|
||||
*Additional requirements: git*
|
||||
|
||||
If you don't plan to make any significant changes but want to track and update the theme, you can add it as a [git
|
||||
submodule](https://git-scm.com/docs/git-submodule) by running the following command from the root directory of your Hugo
|
||||
site:
|
||||
|
||||
```sh
|
||||
git submodule add https://github.com/vimux/mainroad.git themes/mainroad
|
||||
```
|
||||
|
||||
**Note:**
|
||||
[Netlify expects git submodule](https://docs.netlify.com/configure-builds/common-configurations/hugo/#hugo-themes)
|
||||
instead of git clone.
|
||||
|
||||
### Option B: `git clone`
|
||||
|
||||
*Additional requirements: git*
|
||||
|
||||
Run this [git clone](https://git-scm.com/docs/git-clone) command from the root of your Hugo site:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/vimux/mainroad.git themes/mainroad
|
||||
```
|
||||
|
||||
### Option C: Manual install
|
||||
|
||||
If you do not want to use git for some reason, you can manually
|
||||
**[download ZIP](https://github.com/vimux/mainroad/archive/master.zip)** and extract it into the `themes/mainroad`
|
||||
within your Hugo site.
|
||||
|
||||
---
|
||||
|
||||
### Activate theme
|
||||
|
||||
No matter what option do you choose above, don't forget to edit `theme` param of the site configuration `config.toml`:
|
||||
|
||||
```toml
|
||||
theme = "mainroad"
|
||||
```
|
||||
|
||||
Done. Build the site via `hugo` command or make it available on a local server via `hugo server` to check it out.
|
||||
|
||||
## Minimal configuration
|
||||
|
||||
**We don't recommend copying [example config](https://github.com/vimux/mainroad#configtoml-example) as-is.**
|
||||
Mainroad theme contains required defaults, so you don't need to add all of configuration parameters to run the
|
||||
theme for the first time without errors from Hugo. Make sure that you edit the `theme` param inside the config file
|
||||
and check that theme works. Only then start to add theme-specific parameters that you really need.
|
||||
[Customization page]({{< relref "/docs/customization.md" >}} "Mainroad theme customization") describes common settings
|
||||
that you may want to change and our [demo config](https://github.com/vimux/mainroad/blob/master/exampleSite/config.toml)
|
||||
could help with configuration too.
|
||||
|
||||
[Edit this page on GitHub](https://github.com/vimux/mainroad/blob/master/exampleSite/content/docs/getting-started.md)
|
||||
@@ -0,0 +1,170 @@
|
||||
---
|
||||
title: Basic HTML Elements
|
||||
description: Example test article that contains basic HTML elements for text formatting on the Web.
|
||||
date: 2018-04-16
|
||||
categories:
|
||||
- "Development"
|
||||
tags:
|
||||
- "HTML"
|
||||
- "CSS"
|
||||
- "Basic Elements"
|
||||
menu:
|
||||
main:
|
||||
name: Basic Elements
|
||||
weight: 4
|
||||
---
|
||||
|
||||
The main purpose of this article is to make sure that all basic HTML Elements are decorated with CSS so as to not miss any possible elements when creating new themes for Hugo.
|
||||
<!--more-->
|
||||
|
||||
## Headings
|
||||
|
||||
Let's start with all possible headings. The HTML `<h1>`—`<h6>` elements represent six levels of section headings. `<h1>` is the highest section level and `<h6>` is the lowest.
|
||||
|
||||
# Heading 1
|
||||
## Heading 2
|
||||
### Heading 3
|
||||
#### Heading 4
|
||||
##### Heading 5
|
||||
###### Heading 6
|
||||
|
||||
***
|
||||
|
||||
## Paragraph
|
||||
|
||||
According to the [HTML5 specification](https://www.w3.org/TR/html5/dom.html#elements) by [W3C](https://www.w3.org/), **HTML documents consist of a tree of elements and text**. Each element is denoted in the source by a [start tag](https://www.w3.org/TR/html5/syntax.html#syntax-start-tags), such as `<body>`, and an [end tag](https://www.w3.org/TR/html5/syntax.html#syntax-end-tags), such as `</body>`. (*Certain start tags and end tags can in certain cases be omitted and are implied by other tags.*)
|
||||
|
||||
Elements can have attributes, which control how the elements work. For example, hyperlink are formed using the `a` element and its `href` attribute.
|
||||
|
||||
## List Types
|
||||
|
||||
### Ordered List
|
||||
|
||||
1. First item
|
||||
2. Second item
|
||||
3. Third item
|
||||
|
||||
### Unordered List
|
||||
|
||||
* List item
|
||||
* Another item
|
||||
* And another item
|
||||
|
||||
### Nested list
|
||||
|
||||
<ul>
|
||||
<li>First item</li>
|
||||
<li>Second item
|
||||
<ul>
|
||||
<li>Second item First subitem</li>
|
||||
<li>Second item second subitem
|
||||
<ul>
|
||||
<li>Second item Second subitem First sub-subitem</li>
|
||||
<li>Second item Second subitem Second sub-subitem</li>
|
||||
<li>Second item Second subitem Third sub-subitem</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Second item Third subitem
|
||||
<ol>
|
||||
<li>Second item Third subitem First sub-subitem</li>
|
||||
<li>Second item Third subitem Second sub-subitem</li>
|
||||
<li>Second item Third subitem Third sub-subitem</li>
|
||||
</ol>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Third item</li>
|
||||
</ul>
|
||||
|
||||
### Definition List
|
||||
|
||||
HTML also supports definition lists.
|
||||
|
||||
<dl>
|
||||
<dt>Blanco tequila</dt>
|
||||
<dd>The purest form of the blue agave spirit...</dd>
|
||||
<dt>Reposado tequila</dt>
|
||||
<dd>Typically aged in wooden barrels for between two and eleven months...</dd>
|
||||
</dl>
|
||||
|
||||
## Blockquotes
|
||||
|
||||
The blockquote element represents content that is quoted from another source, optionally with a citation which must be within a `footer` or `cite` element, and optionally with in-line changes such as annotations and abbreviations.
|
||||
|
||||
> Quoted text.
|
||||
> This line is part of the same quote.
|
||||
> Also you can *put* **Markdown** into a blockquote.
|
||||
|
||||
Blockquote with a citation.
|
||||
|
||||
<blockquote>
|
||||
<p>My goal wasn't to make a ton of money. It was to build good computers. I only started the company when I realized I could be an engineer forever.</p>
|
||||
<footer>— <cite>Steve Wozniak</cite></footer>
|
||||
</blockquote>
|
||||
|
||||
According to Mozilla's website, <q cite="https://www.mozilla.org/en-US/about/history/details/">Firefox 1.0 was released in 2004 and became a big success.</q>
|
||||
|
||||
## Tables
|
||||
|
||||
Tables aren't part of the core Markdown spec, but Hugo supports them.
|
||||
|
||||
| ID | Make | Model | Year |
|
||||
| --- | --------- | ------- | ---- |
|
||||
| 1 | Honda | Accord | 2009 |
|
||||
| 2 | Toyota | Camry | 2012 |
|
||||
| 3 | Hyundai | Elantra | 2010 |
|
||||
|
||||
Colons can be used to align columns.
|
||||
|
||||
| Tables | Are | Cool |
|
||||
|:----------- |:-------------:| ------------:|
|
||||
| align: left | align: center | align: right |
|
||||
| align: left | align: center | align: right |
|
||||
| align: left | align: center | align: right |
|
||||
|
||||
You can also use inline Markdown.
|
||||
|
||||
| Inline | Markdown | In | Table |
|
||||
| ---------- | --------- | ----------------- | ---------- |
|
||||
| *italics* | **bold** | ~~strikethrough~~ | `code` |
|
||||
|
||||
## Code
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Example HTML5 Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Test</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
{{< highlight html >}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Example HTML5 Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Test</p>
|
||||
</body>
|
||||
</html>
|
||||
{{< /highlight >}}
|
||||
|
||||
## Other stuff — abbr, sub, sup, kbd, etc.
|
||||
|
||||
<abbr title="Graphics Interchange Format">GIF</abbr> is a bitmap image format.
|
||||
|
||||
H<sub>2</sub>O
|
||||
|
||||
C<sub>6</sub>H<sub>12</sub>O<sub>6</sub>
|
||||
|
||||
X<sup>n</sup> + Y<sup>n</sup> = Z<sup>n</sup>
|
||||
|
||||
Press <kbd>X</kbd> to win. Or press <kbd><kbd>CTRL</kbd>+<kbd>ALT</kbd>+<kbd>F</kbd></kbd> to show FPS counter.
|
||||
|
||||
<mark>As a unit of information in information theory, the bit has alternatively been called a shannon</mark>, named after Claude Shannon, the founder of field of information theory.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,343 @@
|
||||
---
|
||||
title: "(Hu)go Template Primer"
|
||||
date: 2014-04-02
|
||||
thumbnail: "img/placeholder.png"
|
||||
tags:
|
||||
- "go"
|
||||
- "golang"
|
||||
- "templates"
|
||||
- "themes"
|
||||
- "development"
|
||||
categories:
|
||||
- "Development"
|
||||
- "golang"
|
||||
---
|
||||
|
||||
Hugo uses the excellent [Go][] [html/template][gohtmltemplate] library for
|
||||
its template engine. It is an extremely lightweight engine that provides a very
|
||||
small amount of logic. In our experience that it is just the right amount of
|
||||
logic to be able to create a good static website. If you have used other
|
||||
template systems from different languages or frameworks you will find a lot of
|
||||
similarities in Go templates.
|
||||
|
||||
<!--more-->
|
||||
|
||||
This document is a brief primer on using Go templates. The [Go docs][gohtmltemplate]
|
||||
provide more details.
|
||||
|
||||
## Introduction to Go Templates
|
||||
|
||||
Go templates provide an extremely simple template language. It adheres to the
|
||||
belief that only the most basic of logic belongs in the template or view layer.
|
||||
One consequence of this simplicity is that Go templates parse very quickly.
|
||||
|
||||
A unique characteristic of Go templates is they are content aware. Variables and
|
||||
content will be sanitized depending on the context of where they are used. More
|
||||
details can be found in the [Go docs][gohtmltemplate].
|
||||
|
||||
## Basic Syntax
|
||||
|
||||
Golang templates are HTML files with the addition of variables and
|
||||
functions.
|
||||
|
||||
**Go variables and functions are accessible within {{ }}**
|
||||
|
||||
Accessing a predefined variable "foo":
|
||||
|
||||
{{ foo }}
|
||||
|
||||
**Parameters are separated using spaces**
|
||||
|
||||
Calling the add function with input of 1, 2:
|
||||
|
||||
{{ add 1 2 }}
|
||||
|
||||
**Methods and fields are accessed via dot notation**
|
||||
|
||||
Accessing the Page Parameter "bar"
|
||||
|
||||
{{ .Params.bar }}
|
||||
|
||||
**Parentheses can be used to group items together**
|
||||
|
||||
{{ if or (isset .Params "alt") (isset .Params "caption") }} Caption {{ end }}
|
||||
|
||||
|
||||
## Variables
|
||||
|
||||
Each Go template has a struct (object) made available to it. In hugo each
|
||||
template is passed either a page or a node struct depending on which type of
|
||||
page you are rendering. More details are available on the
|
||||
[variables](/layout/variables) page.
|
||||
|
||||
A variable is accessed by referencing the variable name.
|
||||
|
||||
<title>{{ .Title }}</title>
|
||||
|
||||
Variables can also be defined and referenced.
|
||||
|
||||
{{ $address := "123 Main St."}}
|
||||
{{ $address }}
|
||||
|
||||
|
||||
## Functions
|
||||
|
||||
Go template ship with a few functions which provide basic functionality. The Go
|
||||
template system also provides a mechanism for applications to extend the
|
||||
available functions with their own. [Hugo template
|
||||
functions](/layout/functions) provide some additional functionality we believe
|
||||
are useful for building websites. Functions are called by using their name
|
||||
followed by the required parameters separated by spaces. Template
|
||||
functions cannot be added without recompiling hugo.
|
||||
|
||||
**Example:**
|
||||
|
||||
{{ add 1 2 }}
|
||||
|
||||
## Includes
|
||||
|
||||
When including another template you will pass to it the data it will be
|
||||
able to access. To pass along the current context please remember to
|
||||
include a trailing dot. The templates location will always be starting at
|
||||
the /layout/ directory within Hugo.
|
||||
|
||||
**Example:**
|
||||
|
||||
{{ template "chrome/header.html" . }}
|
||||
|
||||
|
||||
## Logic
|
||||
|
||||
Go templates provide the most basic iteration and conditional logic.
|
||||
|
||||
### Iteration
|
||||
|
||||
Just like in Go, the Go templates make heavy use of range to iterate over
|
||||
a map, array or slice. The following are different examples of how to use
|
||||
range.
|
||||
|
||||
**Example 1: Using Context**
|
||||
|
||||
{{ range array }}
|
||||
{{ . }}
|
||||
{{ end }}
|
||||
|
||||
**Example 2: Declaring value variable name**
|
||||
|
||||
{{range $element := array}}
|
||||
{{ $element }}
|
||||
{{ end }}
|
||||
|
||||
**Example 2: Declaring key and value variable name**
|
||||
|
||||
{{range $index, $element := array}}
|
||||
{{ $index }}
|
||||
{{ $element }}
|
||||
{{ end }}
|
||||
|
||||
### Conditionals
|
||||
|
||||
If, else, with, or, & and provide the framework for handling conditional
|
||||
logic in Go Templates. Like range, each statement is closed with `end`.
|
||||
|
||||
|
||||
Go Templates treat the following values as false:
|
||||
|
||||
* false
|
||||
* 0
|
||||
* any array, slice, map, or string of length zero
|
||||
|
||||
**Example 1: If**
|
||||
|
||||
{{ if isset .Params "title" }}<h4>{{ index .Params "title" }}</h4>{{ end }}
|
||||
|
||||
**Example 2: If -> Else**
|
||||
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{else}}
|
||||
{{ index .Params "caption" }}
|
||||
{{ end }}
|
||||
|
||||
**Example 3: And & Or**
|
||||
|
||||
{{ if and (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}}
|
||||
|
||||
**Example 4: With**
|
||||
|
||||
An alternative way of writing "if" and then referencing the same value
|
||||
is to use "with" instead. With rebinds the context `.` within its scope,
|
||||
and skips the block if the variable is absent.
|
||||
|
||||
The first example above could be simplified as:
|
||||
|
||||
{{ with .Params.title }}<h4>{{ . }}</h4>{{ end }}
|
||||
|
||||
**Example 5: If -> Else If**
|
||||
|
||||
{{ if isset .Params "alt" }}
|
||||
{{ index .Params "alt" }}
|
||||
{{ else if isset .Params "caption" }}
|
||||
{{ index .Params "caption" }}
|
||||
{{ end }}
|
||||
|
||||
## Pipes
|
||||
|
||||
One of the most powerful components of Go templates is the ability to
|
||||
stack actions one after another. This is done by using pipes. Borrowed
|
||||
from unix pipes, the concept is simple, each pipeline's output becomes the
|
||||
input of the following pipe.
|
||||
|
||||
Because of the very simple syntax of Go templates, the pipe is essential
|
||||
to being able to chain together function calls. One limitation of the
|
||||
pipes is that they only can work with a single value and that value
|
||||
becomes the last parameter of the next pipeline.
|
||||
|
||||
A few simple examples should help convey how to use the pipe.
|
||||
|
||||
**Example 1 :**
|
||||
|
||||
{{ if eq 1 1 }} Same {{ end }}
|
||||
|
||||
is the same as
|
||||
|
||||
{{ eq 1 1 | if }} Same {{ end }}
|
||||
|
||||
It does look odd to place the if at the end, but it does provide a good
|
||||
illustration of how to use the pipes.
|
||||
|
||||
**Example 2 :**
|
||||
|
||||
{{ index .Params "disqus_url" | html }}
|
||||
|
||||
Access the page parameter called "disqus_url" and escape the HTML.
|
||||
|
||||
**Example 3 :**
|
||||
|
||||
{{ if or (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}}
|
||||
Stuff Here
|
||||
{{ end }}
|
||||
|
||||
Could be rewritten as
|
||||
|
||||
{{ isset .Params "caption" | or isset .Params "title" | or isset .Params "attr" | if }}
|
||||
Stuff Here
|
||||
{{ end }}
|
||||
|
||||
|
||||
## Context (aka. the dot)
|
||||
|
||||
The most easily overlooked concept to understand about Go templates is that {{ . }}
|
||||
always refers to the current context. In the top level of your template this
|
||||
will be the data set made available to it. Inside of a iteration it will have
|
||||
the value of the current item. When inside of a loop the context has changed. .
|
||||
will no longer refer to the data available to the entire page. If you need to
|
||||
access this from within the loop you will likely want to set it to a variable
|
||||
instead of depending on the context.
|
||||
|
||||
**Example:**
|
||||
|
||||
{{ $title := .Site.Title }}
|
||||
{{ range .Params.tags }}
|
||||
<li> <a href="{{ $baseurl }}/tags/{{ . | urlize }}">{{ . }}</a> - {{ $title }} </li>
|
||||
{{ end }}
|
||||
|
||||
Notice how once we have entered the loop the value of {{ . }} has changed. We
|
||||
have defined a variable outside of the loop so we have access to it from within
|
||||
the loop.
|
||||
|
||||
# Hugo Parameters
|
||||
|
||||
Hugo provides the option of passing values to the template language
|
||||
through the site configuration (for sitewide values), or through the meta
|
||||
data of each specific piece of content. You can define any values of any
|
||||
type (supported by your front matter/config format) and use them however
|
||||
you want to inside of your templates.
|
||||
|
||||
|
||||
## Using Content (page) Parameters
|
||||
|
||||
In each piece of content you can provide variables to be used by the
|
||||
templates. This happens in the [front matter](/content/front-matter).
|
||||
|
||||
An example of this is used in this documentation site. Most of the pages
|
||||
benefit from having the table of contents provided. Sometimes the TOC just
|
||||
doesn't make a lot of sense. We've defined a variable in our front matter
|
||||
of some pages to turn off the TOC from being displayed.
|
||||
|
||||
Here is the example front matter:
|
||||
|
||||
```
|
||||
---
|
||||
title: "Permalinks"
|
||||
date: "2013-11-18"
|
||||
aliases:
|
||||
- "/doc/permalinks/"
|
||||
groups: ["extras"]
|
||||
groups_weight: 30
|
||||
notoc: true
|
||||
---
|
||||
```
|
||||
|
||||
Here is the corresponding code inside of the template:
|
||||
|
||||
{{ if not .Params.notoc }}
|
||||
<div id="toc" class="well col-md-4 col-sm-6">
|
||||
{{ .TableOfContents }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
|
||||
|
||||
## Using Site (config) Parameters
|
||||
In your top-level configuration file (eg, `config.yaml`) you can define site
|
||||
parameters, which are values which will be available to you in chrome.
|
||||
|
||||
For instance, you might declare:
|
||||
|
||||
```yaml
|
||||
params:
|
||||
CopyrightHTML: "Copyright © 2013 John Doe. All Rights Reserved."
|
||||
TwitterUser: "spf13"
|
||||
SidebarRecentLimit: 5
|
||||
```
|
||||
|
||||
Within a footer layout, you might then declare a `<footer>` which is only
|
||||
provided if the `CopyrightHTML` parameter is provided, and if it is given,
|
||||
you would declare it to be HTML-safe, so that the HTML entity is not escaped
|
||||
again. This would let you easily update just your top-level config file each
|
||||
January 1st, instead of hunting through your templates.
|
||||
|
||||
```
|
||||
{{if .Site.Params.CopyrightHTML}}<footer>
|
||||
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHtml}}</div>
|
||||
</footer>{{end}}
|
||||
```
|
||||
|
||||
An alternative way of writing the "if" and then referencing the same value
|
||||
is to use "with" instead. With rebinds the context `.` within its scope,
|
||||
and skips the block if the variable is absent:
|
||||
|
||||
```
|
||||
{{with .Site.Params.TwitterUser}}<span class="twitter">
|
||||
<a href="https://twitter.com/{{.}}" rel="author">
|
||||
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}"
|
||||
alt="Twitter"></a>
|
||||
</span>{{end}}
|
||||
```
|
||||
|
||||
Finally, if you want to pull "magic constants" out of your layouts, you can do
|
||||
so, such as in this example:
|
||||
|
||||
```
|
||||
<nav class="recent">
|
||||
<h1>Recent Posts</h1>
|
||||
<ul>{{range first .Site.Params.SidebarRecentLimit .Site.Recent}}
|
||||
<li><a href="{{.RelPermalink}}">{{.Title}}</a></li>
|
||||
{{end}}</ul>
|
||||
</nav>
|
||||
```
|
||||
|
||||
|
||||
[go]: https://golang.org/
|
||||
[gohtmltemplate]: https://golang.org/pkg/html/template/
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
title: Getting Started with Hugo
|
||||
date: 2014-04-02
|
||||
tags:
|
||||
- "go"
|
||||
- "golang"
|
||||
- "hugo"
|
||||
- "development"
|
||||
categories:
|
||||
- "Development"
|
||||
- "golang"
|
||||
---
|
||||
|
||||
## Step 1. Install Hugo
|
||||
|
||||
Go to [Hugo releases](https://github.com/spf13/hugo/releases) and download the
|
||||
appropriate version for your OS and architecture.
|
||||
|
||||
Save it somewhere specific as we will be using it in the next step.
|
||||
|
||||
More complete instructions are available at [Install Hugo](https://gohugo.io/getting-started/installing/)
|
||||
|
||||
## Step 2. Build the Docs
|
||||
|
||||
Hugo has its own example site which happens to also be the documentation site
|
||||
you are reading right now.
|
||||
|
||||
Follow the following steps:
|
||||
|
||||
1. Clone the [Hugo repository](https://github.com/spf13/hugo)
|
||||
2. Go into the repo
|
||||
3. Run hugo in server mode and build the docs
|
||||
4. Open your browser to http://localhost:1313
|
||||
|
||||
Corresponding pseudo commands:
|
||||
|
||||
git clone https://github.com/spf13/hugo
|
||||
cd hugo
|
||||
/path/to/where/you/installed/hugo server --source=./docs
|
||||
> 29 pages created
|
||||
> 0 tags index created
|
||||
> in 27 ms
|
||||
> Web Server is available at http://localhost:1313
|
||||
> Press ctrl+c to stop
|
||||
|
||||
Once you've gotten here, follow along the rest of this page on your local build.
|
||||
|
||||
## Step 3. Change the docs site
|
||||
|
||||
Stop the Hugo process by hitting Ctrl+C.
|
||||
|
||||
Now we are going to run hugo again, but this time with hugo in watch mode.
|
||||
|
||||
/path/to/hugo/from/step/1/hugo server --source=./docs --watch
|
||||
> 29 pages created
|
||||
> 0 tags index created
|
||||
> in 27 ms
|
||||
> Web Server is available at http://localhost:1313
|
||||
> Watching for changes in /Users/spf13/Code/hugo/docs/content
|
||||
> Press ctrl+c to stop
|
||||
|
||||
|
||||
Open your [favorite editor](http://vim.spf13.com) and change one of the source
|
||||
content pages. How about changing this very file to *fix the typo*. How about changing this very file to *fix the typo*.
|
||||
|
||||
Content files are found in `docs/content/`. Unless otherwise specified, files
|
||||
are located at the same relative location as the url, in our case
|
||||
`docs/content/overview/quickstart.md`.
|
||||
|
||||
Change and save this file.. Notice what happened in your terminal.
|
||||
|
||||
> Change detected, rebuilding site
|
||||
|
||||
> 29 pages created
|
||||
> 0 tags index created
|
||||
> in 26 ms
|
||||
|
||||
Refresh the browser and observe that the typo is now fixed.
|
||||
|
||||
Notice how quick that was. Try to refresh the site before it's finished building. I double dare you.
|
||||
Having nearly instant feedback enables you to have your creativity flow without waiting for long builds.
|
||||
|
||||
## Step 4. Have fun
|
||||
|
||||
The best way to learn something is to play with it.
|
||||
@@ -0,0 +1,151 @@
|
||||
---
|
||||
title: Migrate to Hugo from Jekyll
|
||||
date: 2014-03-10
|
||||
linktitle: Migrating from Jekyll
|
||||
---
|
||||
|
||||
## Move static content to `static`
|
||||
Jekyll has a rule that any directory not starting with `_` will be copied as-is to the `_site` output. Hugo keeps all static content under `static`. You should therefore move it all there.
|
||||
With Jekyll, something that looked like
|
||||
|
||||
▾ <root>/
|
||||
▾ images/
|
||||
logo.png
|
||||
|
||||
should become
|
||||
|
||||
▾ <root>/
|
||||
▾ static/
|
||||
▾ images/
|
||||
logo.png
|
||||
|
||||
Additionally, you'll want any files that should reside at the root (such as `CNAME`) to be moved to `static`.
|
||||
|
||||
## Create your Hugo configuration file
|
||||
Hugo can read your configuration as JSON, YAML or TOML. Hugo supports parameters custom configuration too. Refer to the [Hugo configuration documentation](/overview/configuration/) for details.
|
||||
|
||||
## Set your configuration publish folder to `_site`
|
||||
The default is for Jekyll to publish to `_site` and for Hugo to publish to `public`. If, like me, you have [`_site` mapped to a git submodule on the `gh-pages` branch](http://blog.blindgaenger.net/generate_github_pages_in_a_submodule.html), you'll want to do one of two alternatives:
|
||||
|
||||
1. Change your submodule to point to map `gh-pages` to public instead of `_site` (recommended).
|
||||
|
||||
git submodule deinit _site
|
||||
git rm _site
|
||||
git submodule add -b gh-pages git@github.com:your-username/your-repo.git public
|
||||
|
||||
2. Or, change the Hugo configuration to use `_site` instead of `public`.
|
||||
|
||||
{
|
||||
..
|
||||
"publishdir": "_site",
|
||||
..
|
||||
}
|
||||
|
||||
## Convert Jekyll templates to Hugo templates
|
||||
That's the bulk of the work right here. The documentation is your friend. You should refer to [Jekyll's template documentation](http://jekyllrb.com/docs/templates/) if you need to refresh your memory on how you built your blog and [Hugo's template](/layout/templates/) to learn Hugo's way.
|
||||
|
||||
As a single reference data point, converting my templates for [heyitsalex.net](http://heyitsalex.net/) took me no more than a few hours.
|
||||
|
||||
## Convert Jekyll plugins to Hugo shortcodes
|
||||
Jekyll has [plugins](http://jekyllrb.com/docs/plugins/); Hugo has [shortcodes](/doc/shortcodes/). It's fairly trivial to do a port.
|
||||
|
||||
### Implementation
|
||||
As an example, I was using a custom [`image_tag`](https://github.com/alexandre-normand/alexandre-normand/blob/74bb12036a71334fdb7dba84e073382fc06908ec/_plugins/image_tag.rb) plugin to generate figures with caption when running Jekyll. As I read about shortcodes, I found Hugo had a nice built-in shortcode that does exactly the same thing.
|
||||
|
||||
Jekyll's plugin:
|
||||
|
||||
module Jekyll
|
||||
class ImageTag < Liquid::Tag
|
||||
@url = nil
|
||||
@caption = nil
|
||||
@class = nil
|
||||
@link = nil
|
||||
// Patterns
|
||||
IMAGE_URL_WITH_CLASS_AND_CAPTION =
|
||||
IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK = /(\w+)(\s+)((https?:\/\/|\/)(\S+))(\s+)"(.*?)"(\s+)->((https?:\/\/|\/)(\S+))(\s*)/i
|
||||
IMAGE_URL_WITH_CAPTION = /((https?:\/\/|\/)(\S+))(\s+)"(.*?)"/i
|
||||
IMAGE_URL_WITH_CLASS = /(\w+)(\s+)((https?:\/\/|\/)(\S+))/i
|
||||
IMAGE_URL = /((https?:\/\/|\/)(\S+))/i
|
||||
def initialize(tag_name, markup, tokens)
|
||||
super
|
||||
if markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK
|
||||
@class = $1
|
||||
@url = $3
|
||||
@caption = $7
|
||||
@link = $9
|
||||
elsif markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION
|
||||
@class = $1
|
||||
@url = $3
|
||||
@caption = $7
|
||||
elsif markup =~ IMAGE_URL_WITH_CAPTION
|
||||
@url = $1
|
||||
@caption = $5
|
||||
elsif markup =~ IMAGE_URL_WITH_CLASS
|
||||
@class = $1
|
||||
@url = $3
|
||||
elsif markup =~ IMAGE_URL
|
||||
@url = $1
|
||||
end
|
||||
end
|
||||
def render(context)
|
||||
if @class
|
||||
source = "<figure class='#{@class}'>"
|
||||
else
|
||||
source = "<figure>"
|
||||
end
|
||||
if @link
|
||||
source += "<a href=\"#{@link}\">"
|
||||
end
|
||||
source += "<img src=\"#{@url}\">"
|
||||
if @link
|
||||
source += "</a>"
|
||||
end
|
||||
source += "<figcaption>#{@caption}</figcaption>" if @caption
|
||||
source += "</figure>"
|
||||
source
|
||||
end
|
||||
end
|
||||
end
|
||||
Liquid::Template.register_tag('image', Jekyll::ImageTag)
|
||||
|
||||
is written as this Hugo shortcode:
|
||||
|
||||
<!-- image -->
|
||||
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>
|
||||
{{ with .Get "link"}}<a href="{{.}}">{{ end }}
|
||||
<img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}"{{ end }} />
|
||||
{{ if .Get "link"}}</a>{{ end }}
|
||||
{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
|
||||
<figcaption>{{ if isset .Params "title" }}
|
||||
{{ .Get "title" }}{{ end }}
|
||||
{{ if or (.Get "caption") (.Get "attr")}}<p>
|
||||
{{ .Get "caption" }}
|
||||
{{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }}
|
||||
{{ .Get "attr" }}
|
||||
{{ if .Get "attrlink"}}</a> {{ end }}
|
||||
</p> {{ end }}
|
||||
</figcaption>
|
||||
{{ end }}
|
||||
</figure>
|
||||
<!-- image -->
|
||||
|
||||
### Usage
|
||||
I simply changed:
|
||||
|
||||
{% image full http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg "One of my favorite touristy-type photos. I secretly waited for the good light while we were "having fun" and took this. Only regret: a stupid pole in the top-left corner of the frame I had to clumsily get rid of at post-processing." ->http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/ %}
|
||||
|
||||
to this (this example uses a slightly extended version named `fig`, different than the built-in `figure`):
|
||||
|
||||
{{%/* fig class="full" src="http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg" title="One of my favorite touristy-type photos. I secretly waited for the good light while we were having fun and took this. Only regret: a stupid pole in the top-left corner of the frame I had to clumsily get rid of at post-processing." link="http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/" */%}}
|
||||
|
||||
As a bonus, the shortcode named parameters are, arguably, more readable.
|
||||
|
||||
## Finishing touches
|
||||
### Fix content
|
||||
Depending on the amount of customization that was done with each post with Jekyll, this step will require more or less effort. There are no hard and fast rules here except that `hugo server --watch` is your friend. Test your changes and fix errors as needed.
|
||||
|
||||
### Clean up
|
||||
You'll want to remove the Jekyll configuration at this point. If you have anything else that isn't used, delete it.
|
||||
|
||||
## A practical example in a diff
|
||||
[Hey, it's Alex](http://heyitsalex.net/) was migrated in less than a _father-with-kids day_ from Jekyll to Hugo. You can see all the changes (and screw-ups) by looking at this [diff](https://github.com/alexandre-normand/alexandre-normand/compare/869d69435bd2665c3fbf5b5c78d4c22759d7613a...b7f6605b1265e83b4b81495423294208cc74d610).
|
||||
Reference in New Issue
Block a user