Skip to content

Commit

Permalink
Use partial context more efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
jygastaud committed Dec 11, 2019
1 parent 50e35e4 commit 06fe492
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 69 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,17 @@ hugo mod get github.com/jygastaud/hugo-microtypo/microtypo

## Usage

### Simple case: You want to apply microtypo to .Content variable

* Replace any `{{ .Content }}` call by `{{ partial "content.html" . }}`
* Replace any `{{ .Content }}` call by `{{ partial "content.html" .Content }}`
* Rebuild your site and you're done :tada:

### Advanced case: You want to apply microtypo to any variable with content inside

For that case, you can use the `microtypo.html` partial.

Let say you want to apply microtypo to the `.Summary` variable, you will have to
replace `{{ .Summary }}` call by `{{ partial "microtypo.html" (dict "Content" .Summary "CurrentLang" .Site.Language.Lang) }}`.
You can also use the content.html partial to replace any variable such as: `.Summary`...

To make it works for any other variable, you just have to replace `.Summary` variable in the `dict` function.

`"Content"` key and `"CurrentLang" .Site.Language.Lang` must be keep.
Some examples:

```
{{ partial "content.html" .Content }}
{{ partial "content.html" .Summary }}
```

## Contribute

Expand Down
6 changes: 3 additions & 3 deletions microtypo/layouts/partials/content.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{ $currentLang := .Site.Language.Lang }}
{{ $currentLang := site.Language.Lang }}

{{ if eq $currentLang "fr" }}

{{ $content := .Content }}
{{ $content := . }}

<!-- # Ordinals -->
{{ $content = $content | replaceRE "(\\s)(\\d+)(e|è)(r|me)?([\\s.,])" "$1$2<sup>$3$4</sup>$5" }}
Expand Down Expand Up @@ -52,5 +52,5 @@
{{ $content | safeHTML }}

{{ else }}
{{ .Content }}
{{ . }}
{{ end }}
54 changes: 0 additions & 54 deletions microtypo/layouts/partials/microtypo.html

This file was deleted.

0 comments on commit 06fe492

Please sign in to comment.