Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enables cactus to support hugo's automatic related content. #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
88 changes: 66 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ Some works are still in progress. See [TODOS](#todos) below.
## Install

1. clone cactus to your hugo site's `themes` folder.

```
git clone https://github.com/monkeyWzr/hugo-theme-cactus.git themes/cactus
```

2. change your theme to cactus in your site config

```toml
# config.toml

Expand All @@ -22,6 +24,7 @@ theme = "cactus"

3. config your site. See [Config] or a [complete config sample](exampleSite/config.toml)
4. test your site

```
hugo server
```
Expand Down Expand Up @@ -75,50 +78,53 @@ weight = 4

### Homepage settings

* description: description will be displayed in the homepage. Markdown syntax is supported in the description string.
- description: description will be displayed in the homepage. Markdown syntax is supported in the description string.

```toml
[params]

description = "Hugo is a general-purpose website framework. Technically speaking, Hugo is a static site generator. Unlike systems that dynamically build a page with each visitor request, Hugo builds pages when you create or update your content. Since websites are viewed far more often than they are edited, Hugo is designed to provide an optimal viewing experience for your website’s end users and an ideal writing experience for website authors."
```

* set your main section (used as the link for the "writings" title on the homepage)
- set your main section (used as the link for the "writings" title on the homepage)

```toml
[params]
mainSection = "posts"
```

* change the default main section title from Writings, to something else:
- change the default main section title from Writings, to something else:

```toml
[params]
mainSectionTitle = "Blog"
```

* Show only the 5 most recent posts (default)
- Show only the 5 most recent posts (default)

```toml
[params]
showAllPostsOnHomePage = false
postsOnHomePage = 5
```
* show all posts

- show all posts

```toml
[params]
showAllPostsOnHomePage = true
postsOnHomePage = 5 # this option will be ignored
```

* show tagsoverview (default) or not
*
- show tagsoverview (default) or not
-

```toml
[params]
tagsOverview = true
```

* show projects list (default) or not.
- show projects list (default) or not.

```toml
[params]
Expand All @@ -134,20 +140,21 @@ Create your projects data file `data/projects.yaml|toml|json`. Hugo support yaml
for former hexo cactus users: please assign your json array to a `list` key.

for example, `data/projects.json`:

```json
{
"list": [
{
"name":"Hexo",
"url":"https://hexo.io/",
"desc":"A fast, simple & powerful blog framework"
},
{
"name":"Font Awesome",
"url":"http://fontawesome.io/",
"desc":"The iconic font and CSS toolkit"
}
]
"list": [
{
"name": "Hexo",
"url": "https://hexo.io/",
"desc": "A fast, simple & powerful blog framework"
},
{
"name": "Font Awesome",
"url": "http://fontawesome.io/",
"desc": "The iconic font and CSS toolkit"
}
]
}
```

Expand Down Expand Up @@ -182,6 +189,7 @@ copyright = "Zeran Wu" # cactus theme will use site title if copyright is not se
### Comments

Comments is disabled by default. Enable comments in your `.Site.Params`.

```toml
[params]
[params.comments]
Expand All @@ -190,6 +198,7 @@ Comments is disabled by default. Enable comments in your `.Site.Params`.
```

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

```yaml
comments: true
```
Expand Down Expand Up @@ -229,11 +238,13 @@ default config:
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.

```toml
googleAnalytics = "UA-XXXXXXXX-XX" # or G-XXXXXXXX if you are using Google Analytics v4 (gtag.js)
```

If you are using Google Analytics v3 (analytics.js), you can switch to asynchronous tracking by set `params.googleAnalyticsAsync` to `true`.

```toml
[params]
googleAnalyticsAsync = true # not required
Expand All @@ -252,22 +263,55 @@ The rss link will be `https://example.com/index.xml` assuming your `baseURL` is

Please also check [Configure RSS](https://gohugo.io/templates/rss/#configure-rss)

### Related content

Cactus supports hugo's automatic related content. You can enable it in your site config:

```toml
[related]
includeNewer = true
threshold = 10
toLower = true

[[related.indices]]
name = "keywords"
weight = 80

[[related.indices]]
name = "title"
weight = 80

[[related.indices]]
name = "tags"
weight = 100

[[related.indices]]
name = "date"
weight = 60
pattern = "2006"
```

Please also check [Related Content](https://gohugo.io/content-management/related/) & [Better Relationships in Hugo with Hugo's Related Content](https://www.regisphilibert.com/blog/2018/04/hugo-optmized-relashionships-with-related-content/).

### Mathjax

Cactus supports mathjax. Just add `mathjax` option in your site config:

```toml
[params]
mathjax = true # not required
```

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

```yaml
mathjax: true # or false
```

The site config will be ignored when `mathjax` option exists in front matter.

### Archive
### Archive

Pagination on posts archive can be disabled to show all posts in chronological order

```toml
Expand All @@ -285,7 +329,7 @@ Pagination on posts archive can be disabled to show all posts in chronological o
- [ ] toc template
- [ ] Customizable copyright year
- [ ] gallery
- [ ] expose [mathjax configuration](https://docs.mathjax.org/en/latest/web/configuration.html#web-configuration)
- [ ] expose [mathjax configuration](https://docs.mathjax.org/en/latest/web/configuration.html#web-configuration)

## License

Expand Down
9 changes: 9 additions & 0 deletions layouts/partials/related.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ $related := .Site.RegularPages.Related . | first 5 }} {{ with $related }}
<hr />
<h4>See Also</h4>
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
{{ end }}
8 changes: 5 additions & 3 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ <h1 class="posttitle" itemprop="name headline">
{{ .Title }}
</h1>
<div class="meta">
{{ if (or (isset .Site "author") (isset .Site "title"))}}
{{ if (or (.Site.Author) (.Site.Title))}}
<span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
<span itemprop="name">
{{ if isset .Site "author" }}
{{ if .Site.Author }}
{{ .Site.Author }}
{{ else if isset .Site "title" }}
{{ else if .Site.Title }}
{{ .Site.Title }}
{{ end }}
</span>
Expand Down Expand Up @@ -73,6 +73,8 @@ <h1 class="posttitle" itemprop="name headline">
</div>
</article>

{{ partial "related.html" . }}

{{ partial "comments.html" . }}

{{ partial "page_nav_mobile.html" . }}
Expand Down