diff --git a/.gitignore b/.gitignore index 6452380..38c5505 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ resources/ public/ -.hugo_build.lock \ No newline at end of file +.hugo_build.lock +.vscode/ +exampleSite/assets/jsconfig.json \ No newline at end of file diff --git a/README.md b/README.md index 0067a62..dc1c484 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Add the component to your Hugo site's config: path = "github.com/gohugoio/hugo-mod-bootstrap-scss/v5" ``` +### SCSS + The Bootstrap SCSS will be mounted in `assets/scss/bootstrap`, so you can then import either all: ```scss @@ -25,7 +27,6 @@ The Bootstrap SCSS will be mounted in `assets/scss/bootstrap`, so you can then i Or only what you need: - ```scss // Configuration @import "bootstrap/functions"; @@ -72,6 +73,10 @@ Or only what you need: @import "bootstrap/utilities/api"; ``` +### JavaScript + +See the [./exampleSite](Example Site). + ## Versions 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 1. Verify that `go.mod` is updated with correct version (run `hugo mod graph`). 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). 1. Create a Pull Request and verify that it builds and that the Netlify preview works. - - diff --git a/config.toml b/config.toml index 6030be3..57569c3 100644 --- a/config.toml +++ b/config.toml @@ -5,8 +5,16 @@ extended = true # Workaround for https://github.com/gohugoio/hugo/issues/6945 source = "assets/scss/bootstrap/_vendor" target = "assets/scss/bootstrap/vendor" +[[module.mounts]] +source = "assets" +target = "assets" [[module.imports]] path="github.com/twbs/bootstrap" [[module.imports.mounts]] source = "scss" -target = "assets/scss/bootstrap" \ No newline at end of file +target = "assets/scss/bootstrap" +[[module.imports.mounts]] +source = "js" +target = "assets/js/bootstrap" +[[module.imports]] +path="github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2" diff --git a/exampleSite/assets/js/index.js b/exampleSite/assets/js/index.js new file mode 100644 index 0000000..9eb204c --- /dev/null +++ b/exampleSite/assets/js/index.js @@ -0,0 +1,22 @@ +// Import the Bootstrap components we want to use. +// See https://github.com/twbs/bootstrap/blob/main/js/index.umd.js +import Toast from "js/bootstrap/src/toast"; +import Popover from "js/bootstrap/src/popover"; + +(function () { + let toastElList = [].slice.call(document.querySelectorAll(".toast")); + let toastList = toastElList.map(function (toastEl) { + return new Toast(toastEl); + }); + + toastList.forEach(function (toast) { + toast.show(); + }); + + var popoverTriggerList = [].slice.call( + document.querySelectorAll('[data-bs-toggle="popover"]') + ); + var popoverList = popoverTriggerList.map(function (popoverTriggerEl) { + return new Popover(popoverTriggerEl); + }); +})(); diff --git a/exampleSite/go.mod b/exampleSite/go.mod index 0ebd9b3..a29be84 100644 --- a/exampleSite/go.mod +++ b/exampleSite/go.mod @@ -3,7 +3,6 @@ module github.com/gohugoio/hugo-mod-bootstrap-scss/exampleSite/v5 go 1.17 require ( - github.com/bep/empty-hugo-module v1.0.0 // indirect github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v5.90100.90300 // indirect ) diff --git a/exampleSite/go.sum b/exampleSite/go.sum index 30613b3..f05b3af 100644 --- a/exampleSite/go.sum +++ b/exampleSite/go.sum @@ -1,8 +1,4 @@ -github.com/bep/empty-hugo-module v1.0.0 h1:aYc9RWea644CdYjg9zCy8nkVF4KjC3fwhUTvvcXXg8s= -github.com/bep/empty-hugo-module v1.0.0/go.mod h1:whohinbSjMoFi/Skivj9kvdPs1tEgzYpZ4rXoQk/0/I= -github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v4.0.0-20220111121503-d09c70837b61 h1:rclBs01LjSeTPeN8/I4VASzgL/14HBnbMio6UQvGlSk= -github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v4.0.0-20220111121503-d09c70837b61/go.mod h1:QOfRknwQ8SbtzgHn+dkR+lnLbVSCG8U/1iqpDxk64QU= -github.com/twbs/bootstrap v4.6.1+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0= -github.com/twbs/bootstrap v5.0.2+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0= +github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 h1:GZxx4Hc+yb0/t3/rau1j8XlAxLE4CyXns2fqQbyqWfs= +github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000/go.mod h1:mFberT6ZtcchrsDtfvJM7aAH2bDKLdOnruUHl0hlapI= github.com/twbs/bootstrap v5.1.3+incompatible h1:19+1/69025oghttdacCOGvs1wv9D5lZnpfoCvKUsPCs= github.com/twbs/bootstrap v5.1.3+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0= diff --git a/exampleSite/layouts/index.html b/exampleSite/layouts/index.html index f0455c8..66d41ac 100644 --- a/exampleSite/layouts/index.html +++ b/exampleSite/layouts/index.html @@ -12,6 +12,8 @@ font-size: 12px; } + + {{/* Load Bootstrap SCSS. */}} {{ $options := dict "enableSourceMap" true }} {{ if hugo.IsProduction}} {{ $options := dict "enableSourceMap" false "outputStyle" "compressed" }} @@ -22,8 +24,14 @@ {{ $styles = $styles | fingerprint }} {{ end }} - + {{/* Load Bootstrap JS. */}} + {{ $js := resources.Get "js/index.js" }} + {{ $params := dict }} + {{ $sourceMap := cond hugo.IsProduction "" "inline" }} + {{ $opts := dict "sourceMap" $sourceMap "minify" hugo.IsProduction "target" "es2018" "params" $params }} + {{ $js = $js | js.Build $opts }} +

Bootstrap v5 Hugo Module

@@ -58,7 +66,19 @@

Dependencies

{{ end }} +

Toast (JS plugin)

+ +

Popover (JS plugin)

+
- \ No newline at end of file diff --git a/go.mod b/go.mod index 8039ce8..1468806 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/gohugoio/hugo-mod-bootstrap-scss/v5 go 1.16 -require github.com/twbs/bootstrap v5.1.3+incompatible // indirect +require ( + github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 // indirect + github.com/twbs/bootstrap v5.1.3+incompatible // indirect +) diff --git a/go.sum b/go.sum index 9e9864c..8c6a7ff 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 h1:GZxx4Hc+yb0/t3/rau1j8XlAxLE4CyXns2fqQbyqWfs= +github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000/go.mod h1:mFberT6ZtcchrsDtfvJM7aAH2bDKLdOnruUHl0hlapI= github.com/twbs/bootstrap v4.4.1+incompatible h1:AueNOcQyhFaWJDynY+tJaK1QR+9Dx2CpqW+EoTBUznk= github.com/twbs/bootstrap v4.4.1+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0= github.com/twbs/bootstrap v4.5.2+incompatible h1:QR6UOtm1+LCDK53CzEp8U0NPIYeRUktVgNhq0gaAGP0=