mirror of
https://github.com/jakejarvis/hugo-mod-twemoji.git
synced 2025-04-29 11:30:29 -04:00
mount twemoji.min.js as an asset instead of static file, and get as resource in partial
This commit is contained in:
parent
ede8c23576
commit
cf01973921
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -48,12 +48,9 @@ jobs:
|
|||||||
- name: Build site
|
- name: Build site
|
||||||
run: |
|
run: |
|
||||||
./hugo --source docs/ --verbose
|
./hugo --source docs/ --verbose
|
||||||
- name: Does twemoji.min.js exist?
|
|
||||||
run: |
|
|
||||||
test -f ./docs/public/twemoji/js/twemoji.min.js
|
|
||||||
- name: Are 🌈s imaginary??? (png)
|
- name: Are 🌈s imaginary??? (png)
|
||||||
run: |
|
run: |
|
||||||
test -f ./docs/public/twemoji/png/1f308.png
|
test -f ./docs/public/twemoji/png/1f308.png
|
||||||
- name: Is 💓 even real?!?!??! (svg)
|
- name: Does true 💓 even exist?!?!??! (svg)
|
||||||
run: |
|
run: |
|
||||||
test -f ./docs/public/twemoji/svg/1f493.svg
|
test -f ./docs/public/twemoji/svg/1f493.svg
|
||||||
|
@ -39,20 +39,23 @@ For a quick start, an optional [partial template](https://gohugo.io/templates/pa
|
|||||||
|
|
||||||
### ⚙️ Manual
|
### ⚙️ Manual
|
||||||
|
|
||||||
If you don't use the partial, you'll want to call the script somewhere in your template or theme's `<head>`, for example:
|
If you don't use the partial, you'll want to call the `js/twemoji.min.js` asset as [a resource](https://gohugo.io/hugo-pipes/introduction/) somewhere in your template or theme's `<head>`, for example:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="{{ "twemoji/js/twemoji.min.js" | absURL }}"></script>
|
{{ $twemoji := resources.Get "js/twemoji.min.js" }}
|
||||||
|
<script src="{{ $twemoji.Permalink }}"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
...and then in order to actually swap out the emojis, you need to call the script's `twemoji.parse` method. This is where you can choose between SVGs (recommended) or 72x72 PNGs and tell the script where we've placed the graphics. The [official readme](https://github.com/twitter/twemoji#api) has a _lot_ of information about the API, but a good starting point is this one-liner:
|
...and then in order to actually swap out the emojis, you need to call the script's `twemoji.parse` method. This is where you can choose between SVGs (recommended) or 72x72 PNGs and tell the script where we've placed the graphics. The [official readme](https://github.com/twitter/twemoji#api) has a _lot_ of information about the API, but a good starting point is this one-liner:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script>
|
<script>
|
||||||
twemoji.parse(document.body, {{ dict "base" ("/twemoji/" | absURL) "folder" "svg" "ext" ".svg" | jsonify | safeJS }})
|
twemoji.parse(document.body, {{ dict "base" ("twemoji/" | absURL) "folder" "svg" "ext" ".svg" | jsonify | safeJS }})
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Simply change `svg` and `.svg` to `png` and `.png` respectively to use the provided 72x72 PNG icons instead.
|
||||||
|
|
||||||
After building the site this small script will turn into something like:
|
After building the site this small script will turn into something like:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
[module.hugoVersion]
|
[module.hugoVersion]
|
||||||
min = "0.64.1"
|
min = "0.64.1"
|
||||||
extended = false
|
extended = false
|
||||||
|
[[module.mounts]]
|
||||||
|
source = "assets"
|
||||||
|
target = "assets"
|
||||||
[[module.mounts]]
|
[[module.mounts]]
|
||||||
source = "layouts"
|
source = "layouts"
|
||||||
target = "layouts"
|
target = "layouts"
|
||||||
[[module.mounts]]
|
|
||||||
source = "static"
|
|
||||||
target = "static"
|
|
||||||
[[module.imports]]
|
[[module.imports]]
|
||||||
path = "github.com/twitter/twemoji"
|
path = "github.com/twitter/twemoji"
|
||||||
[[module.imports.mounts]]
|
[[module.imports.mounts]]
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
<script src="{{ "twemoji/js/twemoji.min.js" | absURL }}"></script>
|
{{ $twemoji := resources.Get "js/twemoji.min.js" }}
|
||||||
<script>twemoji.parse(document.body,{{ dict "base" ("/twemoji/" | absURL) "folder" "svg" "ext" ".svg" | jsonify | safeJS }})</script>
|
<script src="{{ $twemoji.Permalink }}"></script>
|
||||||
|
<script>twemoji.parse(document.body,{{ dict "base" ("twemoji/" | absURL) "folder" "svg" "ext" ".svg" | jsonify | safeJS }})</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user