Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ Some works are still in progress. See [TODOS](#todos) below.

## Install

### As Hugo module (preferred)

```toml
# config.toml
theme = "github.com/flypenguin/hugo-theme-cactus"
```

Now continue with step 3 below.

### As git submodule

1. clone cactus to your hugo site's `themes` folder.
```
git clone https://github.com/monkeyWzr/hugo-theme-cactus.git themes/cactus
Expand Down Expand Up @@ -193,24 +204,41 @@ Comments is disabled by default. Enable comments in your `.Site.Params`.
[params]
[params.comments]
enabled = true
# engine = "disqus" # in progress
insert_hr_line = false # inserts an <hr> element before comment block
engine = "disqus" # default if unset
# other options: disqus, utterances, cactus_comments, remark42
```

You can also enable/disable comments per post. in your posts' front matter, add:

```yaml
comments: true
```

The site config is ignored when `comments` option exists in front matter.

The default engine is disqus. **By now only disqus is supported in cactus.** I will add more options sooner or later. See [Comments Alternatives](https://gohugo.io/content-management/comments/#comments-alternatives)
#### Disqus notes

The default engine is disqus.

Before using disqus, you need to register and get your [disqus shortname](https://help.disqus.com/en/articles/1717111-what-s-a-shortname). Assign your shortname in `.Site.disqusShortname`, or cactus will use `.Site.Title` by default.

```
disqusShortname = "wzr" # cactus will use site title if not set
```

#### Remark42 configuration

```toml
[params.comments.remark42]
site_id = "changeme" # REQUIRED
url = "https://my.remark42.url" # REQUIRED
#locale = "en" # select locale, default "en"
#max_comments = 15 # display that many comments, default 15
#simple_view = false # enable simple view (no noticable effect?)
#theme = "light" # "light" | "dark", default "light"
```

### highlight

Use hugo's built-in [syntax highlighting](https://gohugo.io/getting-started/configuration-markup#highlight).
Expand All @@ -233,6 +261,8 @@ default config:

### Analytics

#### Google Analytics

Cactus uses hugo's bulit in analytics templates. Check [hugo's documents](https://gohugo.io/templates/internal#google-analytics) for details.

Set you tracking id in your site config.
Expand All @@ -246,6 +276,28 @@ If you are using Google Analytics v3 (analytics.js), you can switch to asynchron
googleAnalyticsAsync = true # not required
```

#### Matomo

Matomo can be configured by adding the [Hugo Matomo Module](https://github.com/holehan/hugo-component-matomo) and updating `config.toml` like this:

```toml
# in config.toml

[[module.imports]]
path = 'github.com/holehan/hugo-components-matomo'

[params]

# and add this line
[params.analytics.matomo]

# configure matomo settings, in detail described here:
# https://github.com/holehan/hugo-component-matomo
[params.matomo]
url = "https://example.org"
id = 1
```

### RSS

The rss feed is not generated by default. you can enable it in your site config:
Expand Down Expand Up @@ -282,6 +334,17 @@ Pagination on posts archive can be disabled to show all posts in chronological o
showAllPostsArchive = true # or false (default)
```

### Page image gallery

If you have images in your page bundle the theme will add them at the top of your page.
You can disable this behavior in `config.toml`.

```toml
# config.toml
[params]
disable_gallery = true
```

## TODOS

- [ ] More comments engines
Expand Down
5 changes: 5 additions & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="{{ .Site.LanguageCode }}">
{{ partial "head.html" . }}

<body class="max-width mx-auto px3 ltr">
<div class="content index py4">

Expand All @@ -17,4 +18,8 @@
<link rel="stylesheet" href={{ "lib/font-awesome/css/all.min.css" | relURL }}>
<script src={{ "lib/jquery/jquery.min.js" | relURL }}></script>
<script src={{ "js/main.js" | relURL }}></script>
{{- if (isset .Site.Params "matomo") }}
{{ partial "matomo-tracking" . }}
{{- end }}

</html>
16 changes: 5 additions & 11 deletions layouts/partials/comments.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
{{ if (not (isset .Site.Params "comments")) }}
{{ .Scratch.Set "enable_comments" false }}
{{ else if (isset .Params "comments") }}
{{ .Scratch.Set "enable_comments" .Params.comments }}
{{ else if (isset .Site.Params.Comments "enabled") }}
{{ .Scratch.Set "enable_comments" .Site.Params.Comments.Enabled }}
{{ else }}
{{ .Scratch.Set "enable_comments" true }}
{{ end }}

{{ $enable_comments := .Scratch.Get "enable_comments" }}
{{ if $enable_comments }}
{{ if $enable_comments -}}
{{- if .Site.Params.Comments.insert_hr_line -}}<hr/>
{{ end -}}
<div class="blog-post-comments">
{{ if (or (not (isset .Site.Params.Comments "engine")) (eq .Site.Params.Comments.Engine "disqus")) }}
{{ partial "comments/disqus.html" . }}
{{ else if eq .Site.Params.Comments.Engine "utterances" }}
{{ partial "comments/utterances.html" . }}
{{ else if eq .Site.Params.Comments.Engine "cactus_comments" }}
{{ partial "comments/cactus_comments.html" . }}
{{ else if eq .Site.Params.Comments.Engine "remark42" }}
{{ partial "comments/remark42.html" . }}
{{ end }}
</div>
{{ end }}
26 changes: 26 additions & 0 deletions layouts/partials/comments/remark42.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div id="remark42"></div>
<script type="text/javascript">
{{ `// docs see here: https://github.com/umputun/remark42#comments` | safeJS }}
var remark_config = {
host: {{ .Site.Params.comments.remark42.url | default "https://CHANGE.ME.IN.CONFIG.TOML" }},
site_id: {{ .Site.Params.comments.remark42.site_id | default "CHANGE ME IN CONFIG.TOML" }},
components: ['embed'],
url: {{ .Permalink }},
max_shown_comments: {{ .Site.Params.comments.remark42.max_comments | default 15 }},
theme: {{ .Site.Params.comments.remark42.theme | default "light" }},
page_title: {{ .Title }},
locale: {{ .Site.Params.comments.remark42.locale | default "en" }},
show_email_subscription: false,
simple_view: {{ .Site.Params.comments.remark42.simple_view | default false }}
};
</script>
<script>
! function(e, n) {
for (var o = 0; o < e.length; o++) {
var r = n.createElement("script"),
c = ".js",
d = n.head || n.body;
"noModule" in r ? (r.type = "module", c = ".mjs") : r.async = !0, r.defer = !0, r.src = remark_config.host + "/web/" + e[o] + c, d.appendChild(r)
}
}(remark_config.components || ["embed"], document);
</script>
16 changes: 13 additions & 3 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{{ if (not (isset .Site.Params "comments")) -}}
{{ .Scratch.Set "enable_comments" false -}}
{{ else if (isset .Params "comments") -}}
{{ .Scratch.Set "enable_comments" .Params.comments -}}
{{ else if (isset .Site.Params.Comments "enabled") -}}
{{ .Scratch.Set "enable_comments" .Site.Params.Comments.Enabled -}}
{{ else -}}
{{ .Scratch.Set "enable_comments" true -}}
{{ end -}}
{{ $enable_comments := .Scratch.Get "enable_comments" -}}
<head>
<link rel="preload" href="{{ "lib/font-awesome/webfonts/fa-brands-400.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="{{ "lib/font-awesome/webfonts/fa-regular-400.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="{{ "lib/font-awesome/webfonts/fa-solid-900.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="{{ "lib/JetBrainsMono/web/woff2/JetBrainsMono-Regular.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
{{ if eq .Site.Params.Comments.enabled true }}
{{- if (and ($enable_comments) (eq .Site.Params.Comments.Engine "cactus_comments")) }}
<script type="text/javascript" src="https://latest.cactus.chat/cactus.js"></script>
<link rel="stylesheet" href="https://latest.cactus.chat/style.css" type="text/css">
{{ end }}
{{- end }}
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ if .IsPage }} {{ .Title }} | {{ end }}{{ .Site.Title }}</title>
Expand Down Expand Up @@ -44,7 +54,7 @@
{{ end }}
{{ if .Site.GoogleAnalytics }}
{{ if .Site.Params.googleAnalyticsAsync }}
{{ template "_internal/google_analytics_async.html" . }}
{{ template "_internal/google_analytics.html" . }}
{{ else }}
{{ template "_internal/google_analytics.html" . }}
{{ end }}
Expand Down
8 changes: 5 additions & 3 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ <h1 class="posttitle" itemprop="name headline">
</div>
</header>

{{ with .Resources.ByType "image" }}
{{ if (or (not (isset .Site.Params "disable_gallery")) (not .Site.Params.disable_gallery)) -}}
{{ with .Resources.ByType "image" -}}
<div class="article-gallery">
{{ range $index, $value := . }}
<a class="gallery-item" href="{{ .RelPermalink }}" rel="gallery_{{ $index }}">
<img src="{{ .RelPermalink }}" itemprop="image" />
<img src="{{ .RelPermalink }}" itemprop="image" />
</a>
{{ end }}
</div>
{{ end }}
{{ end }}
{{- end }}
{{ if .Site.Params.tocInline }}
<div id="toc">
{{ .TableOfContents }}
Expand Down