Hosting a Hugo Site with Firebase
Old (rac.su)content/hugo/firebase.md
New (racic.ch)src/content/blog/hosting-hugo-site-firebase.md
rac.su (Old)

racic.ch (New)

+++
tags = [
"firebase",
"hosting",
"hugo"
]
categories = ["howto"]
date = "2017-03-05T00:09:41+01:00"
description = "Howto host you Hugo site on firebase using gitlab for source and CI"
title = "Hosting a Hugo site with firebase"
draft = false
thumbnail = "/img/logo/firebase.png"
aliases = ["/post/hugo/firebase"]---
title: "Hosting a Hugo Site with Firebase"
pubDate: 2017-03-05T00:09:41+01:00
description: "Howto host your Hugo site on firebase using gitlab for source and CI"
author: "Michel Racic"
category: "howto"
tags: ["hugo","firebase","hosting","deployment","static-site"]
heroImage: /images/firebase.png
aliases: ["/post/hugo/firebase", "/hugo/firebase"]
---+++This are all the steps needed to deploy your static [Hugo](/tags/hugo) page on [Firebase](/tags/firebase) for free (until you exceed the traffic of the free tier a.k.a Spark plan).
<!--more-->
# Firebase
## Setup
1. Go to https://console.firebase.google.com and create a new project (unless you already have a project and this is just an additional component to it).
2. Install `firebase-tools` (node.js) using: `npm install -g firebase-tools`
3. Login to firebase (setup on your local machine) using `firebase login` which opens a browser and you can select your account. Use `firebase logout` in case you are already logged in but to the wrong account.
3. In the root of your hugo site initialize the Firebase project with `firebase init`
4. Choose Hosting in the feature question
5. Choose the project you did just setup
6. Accept the default for database rules file
7. Accept the default for the publish directory which is `public`
8. Choose No in the question if it is a single-page app
## Deploy
Simply execute `hugo && firebase deploy` and your site will be up in no time.
Alternatively Create a `deploy.sh` file with the following content and make it executable `chmod +x deploy.sh`:
{{< highlight bash "style=emacs" >}}```sh#!/bin/sh
rm -rf public
hugo
firebase deploy{{< /highlight >}}```
## CI Setup
1. Generate a deploy token using `firebase login:ci`
2. Setup your CI
3. Add the token to a private variable like `$FIREBASE_DEPLOY_TOKEN`
> This is a private secret and it should not appear in a public repository. Make sure you understand you chosen CI and that it's not visible to others.
4. Add a step in your build to do `firebase deploy --token $FIREBASE_DEPLOY_TOKEN`
## Map a custom domain to a Firebase project
//TODO
# Gitlab.com
## Configure CI runner
1. Get a deploy token for your Firebase project executing ```firebase login:ci```which will bring up a browser with the authentication dialog and afterwards gives you a token to be used in CI
2. In your GitLab project, go to Pipelines > Environments and then add a new environment called Production
//TODO
## Reference links
* [Firebase CLI Reference](https://firebase.google.com/docs/cli/#administrative_commands)
Displaying GIT Metadata in Hugo Templates
Old (rac.su)content/hugo/gitinfo.md
New (racic.ch)src/content/blog/displaying-git-metadata-hugo-templates.md
rac.su (Old)

racic.ch (New)

+++
title = "Displaying GIT metadata in Hugo templates"
draft = false
thumbnail = ""
tags = ["hugo"]
categories = ["howto"]
date = "2017-02-21T18:14:01+01:00"
description = "Display GIT metadata in Hugo"
aliases = ["/post/hugo/gitinfo"]
+++---
title: "Displaying GIT Metadata in Hugo Templates"
pubDate: 2017-02-21T18:14:01+01:00
description: "Display GIT metadata in Hugo"
author: "Michel Racic"
category: "howto"
tags: ["hugo","git","ci","templates"]
heroImage: /images/git.png
aliases: ["/post/hugo/gitinfo", "/hugo/gitinfo"]
---
In order to display the last updated timestamp of a page, I had to set [EnableGitInfo](https://gohugo.io/extras/gitinfo/) to `true` in the `config.toml` but this caused CI on wercker to fail as soon as I did a `git push`.
<!--more-->
After some analysis, I found the root cause was with Unicode filenames which I used for some easter eggs in this page failing when gitinfo.go tries to fetch info for every file it encounters. I filed this on [hugo-3071](https://github.com/spf13/hugo/issues/3071). If you navigate to http://rac.su/💩 you will see one of the easter eggs and this uses a emoji for the path. While git itself had no troubles working with this, it did add it to the repository as `content/\360\237\222\251.md` and this then caused the failing on getting the meta data in `gitinfo.go`.After some analysis, I found the root cause was with Unicode filenames which I used for some easter eggs in this page failing when gitinfo.go tries to fetch info for every file it encounters. I filed this on [hugo-3071](https://github.com/spf13/hugo/issues/3071). If you navigate to http://rac.su/💩 (now migrated to http://racic.ch/💩 without hugo), you will see one of the easter eggs and this uses a emoji for the path. While git itself had no troubles working with this, it did add it to the repository as `content/\360\237\222\251.md` and this then caused the failing on getting the meta data in `gitinfo.go`.
# Solution
The solution was suggested by [bep](https://github.com/bep) and was to set the git option `core.quotePath` to false in order that it does not quote the Unicode filenames.
This worked on my local system (OSX) as well as on the [Debian](https://www.debian.org) [wercker](https://wercker.com) box, the `wercker.yml` now looks like:{{< highlight yaml "style=emacs" >}}```yamlbox: debian
build:
steps:
- install-packages:
packages: git
- script:
name: Set git config core.quotePath to false for emoji filenames
code: git config --global core.quotePath false
# Build the HUGO page in public folder
- arjen/hugo-build@1.14.1:
version: "0.18.1"
theme: mainroad
flags: --buildDrafts=false
deploy:
steps:
- install-packages:
packages: git ssh-client
# Deploy the public folder to gh_pages branch
- lukevivier/gh-pages@0.2.1:
token: $GIT_TOKEN
domain: rac.su
basedir: public{{< /highlight >}}```
# Template integration
I added following snippet to `layouts/_default/single.html`{{< highlight html "style=emacs" >}}```html<time class="post__meta-date" datetime="{{ .Date }}">
{{.Date.Format "January 02, 2006"}}
</time>
{{ if .GitInfo }}
(<time class="post__meta-date" datetime="{{ .GitInfo.AuthorDate }}">
{{.GitInfo.AuthorDate.Format "Last modified on January 02, 2006"}}
</time>)
{{ end }}{{< /highlight >}}```
Enabling Offline Usage of a Hugo Site (PWA)
Old (rac.su)content/hugo/pwa.md
New (racic.ch)src/content/blog/enabling-offline-usage-hugo-pwa.md
rac.su (Old)

racic.ch (New)
