Hugo Netlify - No Code Syntax Highlighting
source link: http://brianyang.com/hugo-netlify-no-code-syntax-highlighting/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Hugo Netlify - No Code Syntax Highlighting
This tripped me up for an unusually long period of time. I'm documenting this here for anybody else who faces the same problem. I wasn't getting code syntax highlighting when deploying to Netlify.
TL;DR
update version of Hugo on Netlify by adding a netlify.toml file
I searched for:
hugo serve highlights code syntax
I wanted to see if somebody else had this same issue. When running hugo serve
then the code syntax was showing up. Came across a bunch of posts and none of these pointed me to the write direction. Looking at the deploy config in Netlify, it was running Hugo --gc --minify
.
So I ran a production build locally, and noticed I wasn't getting colors. Bingo, I had reproduced the issue locally and was getting closer. So I did some more reading and learned about Chroma. Running this command would now show syntax highlighting after running a production build, locally.
$ hugo gen chromastyles --style=monokai > syntax.css
This generated a syntax file in the root, but it still wasn't showing on Netlify.
So it had nothing to do with adding custom css
or context.production.environment
configuration in config.toml. Didn't add environment variables to change the Hugo version, though that works too.
In the end the problem was solved by adding a netlify.toml
file.
[build]
publish = "public"
command = "hugo --gc --minify"
[context.production.environment]
HUGO_VERSION = "0.65.3"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"
[context.split1]
command = "hugo --gc --minify --enableGitInfo"
[context.split1.environment]
HUGO_VERSION = "0.65.3"
HUGO_ENV = "production"
[context.deploy - preview]
command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"
[context.deploy - preview.environment]
HUGO_VERSION = "0.65.3"
[context.branch - deploy]
command = "hugo --gc --minify -b $DEPLOY_PRIME_URL"
[context.branch - deploy.environment]
HUGO_VERSION = "0.65.3"
[context.next.environment]
HUGO_ENABLEGITINFO = "true"
This was explained clearly in the Hugo docs but I skimmed past this part because I thought it wasn't relevant.
https://gohugo.io/hosting-and-deployment/hosting-on-netlify/
Checkout the Algorithms and Data Structures site I've created at:
Recommend
-
152
Python syntax highlighting for Vim This is an enhanced version of the original Vim 6.1 Python syntax highlighting python.vim by Neil Schemenauer. Features Enhanced highlighting for: Strings...
-
8
It's incredible what VS Code is able to do from month to month. The dev team has consistently put out features and updates every month. We've got 1.45 out this month with some ni...
-
3
用 R 语言的 blogdown+hugo+netlify+github 建博客 关键词:R; blogdown; netlify;...
-
12
Paul Oms Posted on Oct 13...
-
3
Markdown Code Block Syntax Highlighting and Diff Date Published: 03 November 2021
-
5
June 1, 2020 私有仓库发布跟public仓库稍有不同。增加了两步。这里记录一下。1. 登录Netlify生成deploy key
-
7
March 7, 2021 为什么需要 Netlify CMS⚓ Netlify CMS 主要是解决了,随时随地打开浏...
-
2
距离上一次搭建blog已经超过两年了,这两年并不是懒得写东西,而是实在是懒得折腾hexo了。 在看了好几种方案之后,最终还是选择了hugo。 why hugo?
-
5
使用hugo+netlify部署个人主页2019年7月27日|295 阅读本文为原创文章,转载注明出处,欢迎关注网站https://hkvision.cn起了无数次搭博客的心,前两天才下定决心...
-
4
In this tutorial, I will explain the process for setting up a blog using the static site generator Hugo, writing content using Markdown and
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK