Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 8fec65a
Author: Axel Bock <[email protected]>
Date:   Fri Apr 15 15:29:35 2022 +0200

    fix matomo integration

commit aae9f12
Author: Axel Bock <[email protected]>
Date:   Fri Mar 25 20:12:30 2022 +0100

    update theme installation in readme

commit f2b23c2
Author: Axel Bock <[email protected]>
Date:   Fri Mar 25 20:04:19 2022 +0100

    add optional <hr> element before comments

commit e88bc3e
Author: Axel Bock <[email protected]>
Date:   Fri Mar 25 19:55:47 2022 +0100

    add remark42 comment system

commit f786127
Author: Axel Bock <[email protected]>
Date:   Fri Mar 25 19:50:21 2022 +0100

    update comment documentation in readme

commit 33a77a0
Author: Axel Bock <[email protected]>
Date:   Fri Mar 25 19:44:19 2022 +0100

    don't include cactus coments script if not activated

commit c105fd3
Author: Axel Bock <[email protected]>
Date:   Fri Mar 25 19:26:39 2022 +0100

    add config for disabling page gallery

commit e339d02
Author: Axel Bock <[email protected]>
Date:   Fri Mar 25 18:45:02 2022 +0100

    add matomo integration based on hugo matomo module

Squashed commit of the following:

commit 60e7543
Author: Jayden Deng <[email protected]>
Date:   Sat Apr 2 01:50:50 2022 +0800

    Fixed navigation disappearing issue in chrome version 100.*

Squashed commit of the following:

commit f677fba
Author: Mehdi Hasan <[email protected]>
Date:   Tue Dec 29 15:02:57 2020 +0100

    show related posts if present

Squashed commit of the following:

commit 8351bf4
Author: andodet <[email protected]>
Date:   Wed Jul 14 14:40:43 2021 +0200

    Deactivate integrity check for css

Squashed commit of the following:

commit 584768a
Author: Shanhe Yi <[email protected]>
Date:   Sat Sep 4 23:54:12 2021 -0700

    add customizable copyright

    - years can be configured
    - fix monkeyWzr#56 copyright can be enabled/disabled
    - moved all copyright config under .Site.Params.Copyright
  • Loading branch information
ChrisMcKee committed Aug 5, 2022
1 parent a27a143 commit fcfc417
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 26 deletions.
79 changes: 72 additions & 7 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 @@ -178,12 +189,14 @@ The `name` key expects the name of a [Font Awesome icon](https://fontawesome.com

### Copyright

Assign your copy right to `.Site.Copyright`. Cactus will append current year to the head.

TODO: Customizable copyright year
Assign your copy right to `.Site.Params.Copyright.Name`.

```toml
copyright = "Zeran Wu" # cactus theme will use site title if copyright is not set
[params.copyright]
enabled = true # default
name = "Zeran Wu" # cactus will use title if copyright is not set
startYear = 2020 # if not provided, will use current year.
endYear = 2021 # if not provided, will use current year.
```

### Comments
Expand All @@ -193,24 +206,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 +263,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 +278,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 +336,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 All @@ -290,7 +355,7 @@ Pagination on posts archive can be disabled to show all posts in chronological o
- [x] Analytics
- [ ] Local Search
- [ ] toc template
- [ ] Customizable copyright year
- [x] Customizable copyright year
- [ ] gallery
- [ ] expose [mathjax configuration](https://docs.mathjax.org/en/latest/web/configuration.html#web-configuration)

Expand Down
10 changes: 9 additions & 1 deletion exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ baseURL = "https://example.com"
languageCode = "en-us"
title = "Cactus theme example"
theme = "cactus"
copyright = "You" # cactus will use title if copyright is not set
copyright = "You" # deprecated, please use params.copyright
disqusShortname = "example" # Used when comments is enabled. Cactus will use site title if not set
# googleAnalytics = "UA-1234-5"

Expand Down Expand Up @@ -81,6 +81,14 @@ weight = 4
#serverUrl = "" # Defaults to https://matrix.cactus.chat:8448 (Cactus Chat public server)
#serverName = "" # Defaults to cactus.chat

# Customize the copyright years
# Note: if startYear/endYear not provided, will use current year.
[params.copyright]
enabled = true # default
name = "You" # cactus will use title if copyright is not set
startYear = 2021
endYear = 2021

# the value of name should be an valid font awesome icon name (brands type)
# https://fontawesome.com/icons?d=gallery&s=brands
[[params.social]]
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>
12 changes: 11 additions & 1 deletion layouts/partials/footer.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<footer id="footer">
<div class="footer-left">
Copyright &copy; {{ now.Format "2006" }} {{ if .Site.Copyright }} {{ print .Site.Copyright | markdownify }} {{ else }} {{ print .Site.Title }} {{ end }}
{{ $copyrightEnabled := true }}
{{ if (isset .Site.Params "copyright") }}
{{ $copyrightEnabled = .Site.Params.Copyright.Enabled | default false }}
{{ end }}
{{ if $copyrightEnabled }}
{{ $startYear := .Site.Params.Copyright.StartYear | default (now.Format "2006") }}
{{ $endYear := .Site.Params.Copyright.EndYear | default (now.Format "2006") }}
Copyright &copy;
{{ if (eq $startYear $endYear) }} {{ $startYear }} {{ else }} {{ $startYear }}-{{ $endYear }} {{ end }} {{ if .Site.Params.Copyright.Name }} {{ print .Site.Params.Copyright.Name | markdownify }} {{ else }} {{ print .Site.Title }} {{ end }}
{{ end }}
</div>

<div class="footer-right">
<nav>
<ul>
Expand Down
14 changes: 13 additions & 1 deletion layouts/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,10 +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 (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 }}
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ if .IsPage }} {{ .Title }} | {{ end }}{{ .Site.Title }}</title>
Expand All @@ -23,7 +35,7 @@

{{- $options := (dict "targetPath" "css/styles.css" "outputStyle" "compressed" "enableSourceMap" "true") -}}
{{- $styles := resources.Get "scss/style.scss" | resources.ExecuteAsTemplate "scss/style.scss" . | resources.ToCSS $options | resources.Fingerprint "sha512" }}
<link rel="stylesheet" href="{{ $styles.Permalink }}" integrity="{{ $styles.Data.Integrity }}">
<link rel="stylesheet" href="{{ $styles.Permalink }}">

<!-- Custom CSS -->
{{ range .Site.Params.css }} <link rel="stylesheet" href="{{ . | absURL }}"> {{ end }}
Expand Down
10 changes: 10 additions & 0 deletions layouts/partials/related.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{ $related := .Site.RegularPages.Related . | first 5 }}
{{ with $related }}
<hr />
<h2>See Also</h2>
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
{{ end }}
10 changes: 7 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 All @@ -78,6 +80,8 @@ <h1 class="posttitle" itemprop="name headline">
</div>
</article>

{{ partial "related.html" . }}

{{ partial "comments.html" . }}

{{ partial "page_nav_mobile.html" . }}
Expand Down
4 changes: 2 additions & 2 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ $(document).ready(function() {
var topDistance = menu.offset().top;

// hide only the navigation links on desktop
if (!nav.is(":visible") && topDistance < 50) {
if (!nav.is(":visible") && topDistance < 88) {
nav.show();
} else if (nav.is(":visible") && topDistance > 100) {
nav.hide();
}

// on tablet, hide the navigation icon as well and show a "scroll to top
// icon" instead
if ( ! $( "#menu-icon" ).is(":visible") && topDistance < 50 ) {
if ( ! $( "#menu-icon" ).is(":visible") && topDistance < 88 ) {
$("#menu-icon-tablet").show();
$("#top-icon-tablet").hide();
} else if (! $( "#menu-icon" ).is(":visible") && topDistance > 100) {
Expand Down

0 comments on commit fcfc417

Please sign in to comment.