Skip to content

Commit

Permalink
use js for better randomization of calligrams
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivia206 committed Sep 19, 2024
1 parent 442e704 commit c4adf9b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
29 changes: 29 additions & 0 deletions assets/js/design-system/pageCalligram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class PageCalligram {
constructor () {
this.calligram = document.querySelector('.calligram');
if (!this.calligram) {
return;
}
this.images = [
{ url: "/assets/images/calligrammes/calligramme-1.svg", orientation: "landscape" },
{ url: "/assets/images/calligrammes/calligramme-2.svg", orientation: "portrait" },
{ url: "/assets/images/calligrammes/calligramme-3.svg", orientation: "landscape" },
{ url: "/assets/images/calligrammes/calligramme-4.svg", orientation: "landscape" }
];

this.listen();
}

listen () {
this.randomImage = Math.floor(Math.random() * this.images.length);
this.image = this.images[this.randomImage];

this.setCalligram();
}
setCalligram () {
this.calligram.src = this.image.url;
this.calligram.className += this.image.orientation;
}
}

export default new PageCalligram();
3 changes: 2 additions & 1 deletion assets/js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './vendors/lightbox';
import './theme/';

import './design-system/homeHero';
import './design-system/homeHero';
import './design-system/pageCalligram';
10 changes: 0 additions & 10 deletions config/_default/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ paginate: 18
enableRobotsTXT: true
removePathAccents: true
params:
footer:
images:
- url: "/assets/images/calligrammes/calligramme-1.svg"
orientation: "landscape"
- url: "/assets/images/calligrammes/calligramme-2.svg"
orientation: "portrait"
- url: "/assets/images/calligrammes/calligramme-3.svg"
orientation: "landscape"
- url: "/assets/images/calligrammes/calligramme-4.svg"
orientation: "landscape"
summary:
position: content
search:
Expand Down
7 changes: 2 additions & 5 deletions layouts/partials/footer/footer-simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
"class" "nav-social"
)}}
{{ end }}

{{ $images := site.Params.footer.images }}
{{ $shuffledImages := shuffle $images }}
{{ $calligram := index $shuffledImages 0 }}
<img class="calligram {{ $calligram.orientation }}" src="{{ $calligram.url }}" alt="" />

<img class="calligram " alt="">

{{ with (or site.Params.social site.Data.website.social) }}
{{ $site_social_links := . }}
Expand Down

0 comments on commit c4adf9b

Please sign in to comment.