mirror of
https://github.com/jakejarvis/hugo-mod-twemoji.git
synced 2025-04-28 02:10:33 -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
|
||||
run: |
|
||||
./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)
|
||||
run: |
|
||||
test -f ./docs/public/twemoji/png/1f308.png
|
||||
- name: Is 💓 even real?!?!??! (svg)
|
||||
- name: Does true 💓 even exist?!?!??! (svg)
|
||||
run: |
|
||||
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
|
||||
|
||||
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
|
||||
<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:
|
||||
|
||||
```html
|
||||
<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>
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```html
|
||||
|
@ -2,12 +2,12 @@
|
||||
[module.hugoVersion]
|
||||
min = "0.64.1"
|
||||
extended = false
|
||||
[[module.mounts]]
|
||||
source = "assets"
|
||||
target = "assets"
|
||||
[[module.mounts]]
|
||||
source = "layouts"
|
||||
target = "layouts"
|
||||
[[module.mounts]]
|
||||
source = "static"
|
||||
target = "static"
|
||||
[[module.imports]]
|
||||
path = "github.com/twitter/twemoji"
|
||||
[[module.imports.mounts]]
|
||||
|
@ -1,2 +1,3 @@
|
||||
<script src="{{ "twemoji/js/twemoji.min.js" | absURL }}"></script>
|
||||
<script>twemoji.parse(document.body,{{ dict "base" ("/twemoji/" | absURL) "folder" "svg" "ext" ".svg" | jsonify | safeJS }})</script>
|
||||
{{ $twemoji := resources.Get "js/twemoji.min.js" }}
|
||||
<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