John Siu Blog

Tech - Business Tool, Personal Toys

Hugo Theme SK3 with AdSense

☰ Table of Content

Full feature Hugo theme build on top of hugo-theme-sk2 with Google AdSense support.

SK Themes

ThemeGitHubHugoDemoDescription
SK1hugo-theme-sk1SK1sk1.jsiu.devFully functional basic Hugo theme with no css, no javascript.
SK2hugo-theme-sk2SK2sk2.jsiu.devFully functional basic Hugo theme with minimum css.
SK3hugo-theme-sk3SK3sk3.jsiu.devFull feature Hugo theme with Google AdSense support.

Sites

John Siu Blog: JohnSiu.com

SK3 demo site: sk3.jsiu.dev with content from hugoBasicExample

Version 2 Breaking Changes

When upgrading from v1.x.x to v2.x.x, config file need to be updated as there are lot of name changes.

Install

In site directory:

  • Using clone

    1
    
    git clone https://github.com/J-Siu/hugo-theme-sk3 themes/sk3
    
  • Using submodule

    1
    
    git submodule add https://github.com/J-Siu/hugo-theme-sk3 themes/sk3
    
  • Update submodule

    1
    
    git submodule update --recursive --remote
    

Testing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
git clone https://github.com/J-Siu/hugo-theme-sk3 sk3
cd sk3

# Pull example site.
git submodule update --recursive --init

cd exampleSite
hugo server -D --bind :: \
--disableFastRender \
--theme sk3 \
--themesDir ../../ \
--config config.toml,../config.demo.toml \
--verbose

Features

  • Blog
  • Custom CSS
  • Custom Javascript
  • Customizable
  • Disqus
  • Google Adsense
  • Google Analytics
  • Minimalist Design
  • Responsive
  • Social Links
  • Social Share

Layout

Markdown Style

Headline in markdown should start at level 3 (###), as site title is H1 and page title is H2.

Site Config

[Params]

FieldTypeDefault ValueDescription
customCsstext array[]See Custom CSS
customJstext array[]See Custom Javascript
descriptiontext""Open Graph / Twitter Card description
enableExternalSvgboolfalsetrue will load social icon using Font Awesome external css.
enableInfoBoxboolfalseEnable page info box style
enableListLastModifyboolfalseUse last modify date in list page.
enableOpenGraphboolfalseEnable Open Graph
enableOpenTocbooltrueControl if table of content(Toc) is open By default
enableTwitterCardboolfalseEnable Twitter Card
enableUserCanonicalboolfalseAdd rel="canonical" meta link with absolute URL to each page. Only use this if site require user-declared canonical meta. This is not related to Hugo Canonicalization nor canonifyurls.
favicontext""See Favicon
imagestext array[]Open Graph / Twitter Card image
mainSectionstextn/aHugo default to section with most entries when For generating homepage list.
pagewidthtext(px)“1200px”Page width will automatically set to 100% on small screen(<993px).
startdatetext""eg. “2012-12-02”. Year is extracted and generate copyright line “2012-(current year)”. Site copyright override this behavior.
subtitletext""If defined, sub-title appear after site title in smaller font.
titletext""Open Graph / Twitter Card title

Social Network

[Params.sociallink] Show social network buttons if IDs are provided.

FieldTypeDefault Value
facebooktext""
flickrtext""
instagramtext""
linkedintext""
pinteresttext""
reddittext""
rssboolfalse
tumblrtext""
twittertext""
vimeotext""
youtubechanneltext""
youtubeusertext""

Share Button

[Params.socialshare] Control if share buttons appear at the bottom of page.

FieldTypeDefault Value
facebookboolfalse
instagramboolfalse
linkedinboolfalse
pinterestboolfalse
redditboolfalse
telegramboolfalse
twitterboolfalse
vkboolfalse

Theme Color

[Params.color] Control theme color. Default is a dark theme.

FieldTypeDefault ValueLight Theme**
bgtext“#181a1b”“white”
bordertext“white”““black”
linktext“#3d84ff”“#3d84ff”
texttext“white”“black”

Layout Dimensions

[Params.card] Control list page layout.

FieldTypeDefault ValueDescription
datebooltrueShow data for each item in list
summarybooltrueShow summary for each item in list
widthtext(%)“32%”Control list page column width on desktop(>992px). 32% for 3 columns. 24% for 4 columns, etc. Single column use 100%.

Custom CSS

If you add custom css files like following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
./
├── archetypes/
├── content/
├── public/
├── resources/
├── static/
│   └── css/
│       ├── abc.css
│       └── def.css
├── themes/
└── config.toml

The final path of your css files will be /css/abc.css and /css/def.css:

1
2
[Params]
customCss = ["/css/abc.css", "/css/def.css"]

Custom Javascript

If you add custom javascript like following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
./
├── archetypes/
├── content/
├── public/
├── resources/
├── static/
│   └── js/
│       ├── abc.js
│       └── def.js
├── themes/
└── config.toml

The final path of your javascript files will be /js/abc.js and /js/def.js:

1
2
[Params]
customJs = ["/js/abc.js", "/js/def.js"]

Favicon

Path of favicon of the published site.

If favicon logo.svg is put inside static like following:

1
2
3
4
5
6
7
8
9
./
├── archetypes/
├── content/
├── public/
├── resources/
├── static/
│   └── logo.svg
├── themes/
└── config.toml

The final path will be /logo.svg:

1
2
[Params]
favicon = "/logo.svg"

SK themes come with default favicon. To disable it:

1
2
# At Hugo site root
touch static/favicon.ico

Google

[Params.google]

FieldTypeDefault ValueDescription
AdsenseIdtext"”AdSense ID/Tag.
enablePageLevelAdboolfalseEnable/Disable page level ads.
enableUAboolfalseSet this to ’true’ if using Google Analytics UA.

Paypal Button

[Params.paypal] Enable Paypal donation button along side share buttons.

FieldTypeDefault ValueDescription
amounttext“0”Default amount.
businessIdtext""Paypal business Id. Button will only show if this is set.
currencytext""Currency code, eg. “CAD”, “USD”.
enableRecurringboolfalseShow recurring check-box.

Information can be obtain by going through Paypal Donate Button. You need your own Paypal account to go through the button creation process.

Per Page Settings

  • Disable Disqus

  • Disable Prev/Next

  • Disable Related

  • Disable Table of Content

    To disable the above, in front matter:

    1
    2
    3
    4
    
    comment = false
    prevnext = false
    related = false
    toc = false
    

Sample Config

config.sample.toml located in theme dir.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
baseURL = "https://"
theme   = "sk3"
title   = ""

DefaultContentLanguage = "en"
enableGitInfo          = true
enableInlineShortcodes = true
languageCode           = "en"
paginate               = 15
relativeURLs           = true

#disqusShortname = ""
#googleAnalytics = ""

[Params]
customCss            = ["/css/abc.css", "/css/def.css"]
customJs             = ["/js/abc.js", "/js/def.js"]
enableExternalSvg    = false
enableInfoBox        = true
enableListLastModify = false
enableOpenToc        = false
enableUserCanonical  = false
favicon              = "/favicon.ico"
mainSections         = "post"
pagewidth            = "1200px"
startdate            = "2012-12-02"
subtitle             = "A Hugo Theme"

# Fill in following if using Open Graph / Twitter Card
description       = "A Hugo Theme"
enableOpenGraph   = true
enableTwitterCard = true
title             = "SK3"

	[Params.paypal]
	amount          = ""
	businessId      = ""
	currency        = ""
	enableRecurring = true

	[Params.google]
	AdsenseId         = ""
	enablePageLevelAd = false
	enableUA          = false

	[Params.card]
	date    = true
	summary = true
	width   = "32%"

	[Params.color]
	bg     = "#181a1b"
	border = "white"
	link   = "#3d84ff"
	text   = "white"

	[Params.sociallink]
	facebook       = ""
	flickr          = ""
	github         = ""
	instagram      = ""
	linkedin       = ""
	pinterest      = ""
	reddit         = ""
	rss            = true
	stack-exchange = ""
	stack-overflow  = ""
	tumblr         = ""
	twitter        = ""
	vimeo          = ""
	youtubechannel = ""
	youtubeuser    = ""

	[Params.socialshare]
	facebook  = true
	instagram = true
	linkedin  = true
	pinterest = true
	reddit    = true
	telegram  = true
	twitter   = true
	vk        = true

[markup]
	[markup.tableOfContents]
	endLevel   = 6
	startLevel = 1

Font Awesome

Social buttons provided by Font Awesome Brands(free).

fa-svg-extract.sh is used to extract icon from Font Awesome sprites/brands.svg and sprites/solid.svg.

1
2
./fa-svg-extract.sh brands.svg > sk3-fa.svg
./fa-svg-extract.sh solid.svg >> sk3-fa.svg

Thank You

Contributors

Change Log

  • 0.8.5
    • Initial Commit
  • 0.8.6
    • Share button in menu
    • Fixed
      • Adsense ID
      • CSS color conflict with syntax highlight
      • Display issue with Disqus
      • Display issue with prev/next
      • Unwanted title on homepage
  • 0.8.7
    • CSS clean up
    • Complete README.md
    • Default page width 1200px
    • Default card width 32%
    • Fixed menu bar top and left “leaking”
  • 0.8.8
    • CSS clean up
    • Improve header
    • Improve README.md
    • Fix margin/padding
  • 0.8.9
    • CSS / spacing update
    • Include config.sample.toml
    • Use Font Awesome web font
  • 0.9.0
    • Switch to Font Awesome SVG
  • 0.9.1
    • Add box style page info
    • CSS clean up
    • Do not render empty table of content
    • Fix highlight font conflict
  • 0.9.2
    • Add images
    • Demo config
    • Fix css
    • Improve menu
    • README.md update
    • Template .Site. -> site.
    • Use site.Params.mainSections
  • 0.9.3
    • Click anywhere to close menu
    • SVG external option
  • 0.9.4
    • Fix css spacing, kbd, social buttons, author box
    • Fix menu closing click through
  • 0.9.5
    • Add enableListLastModify
    • Fix H1 line height
    • Fix Google Analytics
    • Fix table for mobile screen
    • Refactor css margin/padding/font size
  • 0.9.6
    • Add default favicon.ico
    • Remove H1 from header.html & menu.html (Bing SEO)
    • Standardize .Site. -> site.
    • Update README.md
  • 0.9.7
    • Add custom css and js support
    • Add open toc by default
    • Add page related (enable/disable)
    • Add user-declared canonical support
    • Fix footer alignment
    • Update favicon instructions
  • 0.9.8
    • Add box to current list page button
    • Add external link open in new tab
    • Add rss
    • CSS cleanup
    • Center images
    • Fix <head> description, title
    • Fix html issues
    • Homepage title larger
    • Sort tags list / in page
    • Sticky menu button
  • 0.9.9
  • 1.0.0
    • Fixed head.html text color variable name issue #27
    • Fixed sk3.css box element color issue #27
  • v1.1.0
    • Support Google Analytics GA4 with googleAnalyticsUA
  • v1.2.0
    • Support AdSense page level control
  • v2.0.0
    • Restructure README.md
    • Breaking changes:
      • Params names changes
      • Google param section
  • v2.1.0
    • Support Paypal donation button

License

The MIT License (MIT)

Copyright (c) 2022 John, Sing Dao, Siu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

John Siu

Update: 2022-05-18
comments powered by Disqus