Skip to content

Commit 5f1ee36

Browse files
committed
Add the Bootstrap JavaScript components
1 parent 5afcb5a commit 5f1ee36

File tree

9 files changed

+70
-15
lines changed

9 files changed

+70
-15
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
resources/
22
public/
3-
.hugo_build.lock
3+
.hugo_build.lock
4+
.vscode/
5+
exampleSite/assets/jsconfig.json

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Add the component to your Hugo site's config:
1717
path = "github.com/gohugoio/hugo-mod-bootstrap-scss/v5"
1818
```
1919

20+
### SCSS
21+
2022
The Bootstrap SCSS will be mounted in `assets/scss/bootstrap`, so you can then import either all:
2123

2224
```scss
@@ -25,7 +27,6 @@ The Bootstrap SCSS will be mounted in `assets/scss/bootstrap`, so you can then i
2527

2628
Or only what you need:
2729

28-
2930
```scss
3031
// Configuration
3132
@import "bootstrap/functions";
@@ -72,6 +73,10 @@ Or only what you need:
7273
@import "bootstrap/utilities/api";
7374
```
7475

76+
### JavaScript
77+
78+
See the [./exampleSite](Example Site).
79+
7580
## Versions
7681

7782
This repository will be versioned following https://github.com/bep/semverpair
@@ -84,5 +89,3 @@ This repository will be versioned following https://github.com/bep/semverpair
8489
1. Verify that `go.mod` is updated with correct version (run `hugo mod graph`).
8590
1. Do `cd exampleSite` and run `hugo server` and make sure it works (and that `github.com/twbs/bootstrap` version is as expected in the table).
8691
1. Create a Pull Request and verify that it builds and that the Netlify preview works.
87-
88-

config.toml

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ extended = true
55
# Workaround for https://github.com/gohugoio/hugo/issues/6945
66
source = "assets/scss/bootstrap/_vendor"
77
target = "assets/scss/bootstrap/vendor"
8+
[[module.mounts]]
9+
source = "assets"
10+
target = "assets"
811
[[module.imports]]
912
path="github.com/twbs/bootstrap"
1013
[[module.imports.mounts]]
1114
source = "scss"
12-
target = "assets/scss/bootstrap"
15+
target = "assets/scss/bootstrap"
16+
[[module.imports.mounts]]
17+
source = "js"
18+
target = "assets/js/bootstrap"
19+
[[module.imports]]
20+
path="github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2"

exampleSite/assets/js/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Import the Bootstrap components we want to use.
2+
// See https://github.com/twbs/bootstrap/blob/main/js/index.umd.js
3+
import Toast from "js/bootstrap/src/toast";
4+
import Popover from "js/bootstrap/src/popover";
5+
6+
(function () {
7+
let toastElList = [].slice.call(document.querySelectorAll(".toast"));
8+
let toastList = toastElList.map(function (toastEl) {
9+
return new Toast(toastEl);
10+
});
11+
12+
toastList.forEach(function (toast) {
13+
toast.show();
14+
});
15+
16+
var popoverTriggerList = [].slice.call(
17+
document.querySelectorAll('[data-bs-toggle="popover"]')
18+
);
19+
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
20+
return new Popover(popoverTriggerEl);
21+
});
22+
})();

exampleSite/go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/gohugoio/hugo-mod-bootstrap-scss/exampleSite/v5
33
go 1.17
44

55
require (
6-
github.com/bep/empty-hugo-module v1.0.0 // indirect
76
github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v5.90100.90300 // indirect
87
)
98

exampleSite/go.sum

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
github.com/bep/empty-hugo-module v1.0.0 h1:aYc9RWea644CdYjg9zCy8nkVF4KjC3fwhUTvvcXXg8s=
2-
github.com/bep/empty-hugo-module v1.0.0/go.mod h1:whohinbSjMoFi/Skivj9kvdPs1tEgzYpZ4rXoQk/0/I=
3-
github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v4.0.0-20220111121503-d09c70837b61 h1:rclBs01LjSeTPeN8/I4VASzgL/14HBnbMio6UQvGlSk=
4-
github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v4.0.0-20220111121503-d09c70837b61/go.mod h1:QOfRknwQ8SbtzgHn+dkR+lnLbVSCG8U/1iqpDxk64QU=
5-
github.com/twbs/bootstrap v4.6.1+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0=
6-
github.com/twbs/bootstrap v5.0.2+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0=
1+
github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 h1:GZxx4Hc+yb0/t3/rau1j8XlAxLE4CyXns2fqQbyqWfs=
2+
github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000/go.mod h1:mFberT6ZtcchrsDtfvJM7aAH2bDKLdOnruUHl0hlapI=
73
github.com/twbs/bootstrap v5.1.3+incompatible h1:19+1/69025oghttdacCOGvs1wv9D5lZnpfoCvKUsPCs=
84
github.com/twbs/bootstrap v5.1.3+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0=

exampleSite/layouts/index.html

+22-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
font-size: 12px;
1313
}
1414
</style>
15+
16+
{{/* Load Bootstrap SCSS. */}}
1517
{{ $options := dict "enableSourceMap" true }}
1618
{{ if hugo.IsProduction}}
1719
{{ $options := dict "enableSourceMap" false "outputStyle" "compressed" }}
@@ -22,8 +24,14 @@
2224
{{ $styles = $styles | fingerprint }}
2325
{{ end }}
2426
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" />
25-
</head>
2627

28+
{{/* Load Bootstrap JS. */}}
29+
{{ $js := resources.Get "js/index.js" }}
30+
{{ $params := dict }}
31+
{{ $sourceMap := cond hugo.IsProduction "" "inline" }}
32+
{{ $opts := dict "sourceMap" $sourceMap "minify" hugo.IsProduction "target" "es2018" "params" $params }}
33+
{{ $js = $js | js.Build $opts }} <script src="{{ $js.RelPermalink }}" {{ if hugo.IsProduction }}integrity="{{ $js.Data.Integrity }}"{{ end }} defer></script>
34+
</head>
2735
<body>
2836
<div class="container mt-5">
2937
<h1>Bootstrap v5 Hugo Module</h1>
@@ -58,7 +66,19 @@ <h2 class="mt-4">Dependencies</h2>
5866
{{ end }}
5967
</tbody>
6068
</table>
69+
<h2 class="my-4">Toast (JS plugin)</h2>
70+
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
71+
<div class="toast-header">
72+
<strong class="me-auto">Bootstrap</strong>
73+
<small>11 mins ago</small>
74+
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
75+
</div>
76+
<div class="toast-body">
77+
Hello, world! This is a toast message.
78+
</div>
79+
</div>
80+
<h2 class="my-4">Popover (JS plugin)</h2>
81+
<button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
6182
</div>
6283
</body>
63-
6484
</html>

go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/gohugoio/hugo-mod-bootstrap-scss/v5
22

33
go 1.16
44

5-
require github.com/twbs/bootstrap v5.1.3+incompatible // indirect
5+
require (
6+
github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 // indirect
7+
github.com/twbs/bootstrap v5.1.3+incompatible // indirect
8+
)

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 h1:GZxx4Hc+yb0/t3/rau1j8XlAxLE4CyXns2fqQbyqWfs=
2+
github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000/go.mod h1:mFberT6ZtcchrsDtfvJM7aAH2bDKLdOnruUHl0hlapI=
13
github.com/twbs/bootstrap v4.4.1+incompatible h1:AueNOcQyhFaWJDynY+tJaK1QR+9Dx2CpqW+EoTBUznk=
24
github.com/twbs/bootstrap v4.4.1+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0=
35
github.com/twbs/bootstrap v4.5.2+incompatible h1:QR6UOtm1+LCDK53CzEp8U0NPIYeRUktVgNhq0gaAGP0=

0 commit comments

Comments
 (0)