Skip to content

Commit df03039

Browse files
committed
figures.md: fixes and improvements
Pull Request carpentries/styles#330 Closes carpentries/styles#343 1. Fix the script so that all figures are displayed. 2. Add image numbers. 3. Don't add headers for episodes without images. 4. Add horizontal rulers to better separate adjacent images. Don't add a ruler after the last image in the episode. 5. Add empty lines to `figures.md` to improve code readability. 6. Use classes for styling text and figures
1 parent 9af9525 commit df03039

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

assets/css/lesson.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ article h3 { margin: 40px 0 16px; }
163163
// Miscellaneous.
164164
//----------------------------------------
165165

166+
.figures h2 { margin-top: 100px; }
167+
166168
.maintitle {
167169
text-align: center;
168170
}

bin/boilerplate/_extras/figures.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,49 @@ title: Figures
55
window.onload = function() {
66
var lesson_episodes = [
77
{% for episode in site.episodes %}
8-
"{{ episode.url}}"{% unless forloop.last %},{% endunless %}
8+
"{{ episode.url }}"{% unless forloop.last %},{% endunless %}
99
{% endfor %}
1010
];
11+
1112
var xmlHttp = []; /* Required since we are going to query every episode. */
1213
for (i=0; i < lesson_episodes.length; i++) {
14+
1315
xmlHttp[i] = new XMLHttpRequest();
1416
xmlHttp[i].episode = lesson_episodes[i]; /* To enable use this later. */
1517
xmlHttp[i].onreadystatechange = function() {
18+
1619
if (this.readyState == 4 && this.status == 200) {
17-
var article_here = document.getElementById(this.episode);
1820
var parser = new DOMParser();
1921
var htmlDoc = parser.parseFromString(this.responseText,"text/html");
2022
var htmlDocArticle = htmlDoc.getElementsByTagName("article")[0];
21-
article_here.appendChild(htmlDocArticle.getElementsByTagName("h1")[0]);
22-
for (let image of htmlDocArticle.getElementsByTagName("img")) {
23-
article_here.appendChild(image);
23+
24+
var article_here = document.getElementById(this.episode);
25+
var images = htmlDocArticle.getElementsByTagName("img");
26+
27+
if (images.length > 0) {
28+
var h1text = htmlDocArticle.getElementsByTagName("h1")[0].innerHTML;
29+
30+
var htitle = document.createElement('h2');
31+
htitle.innerHTML = h1text;
32+
article_here.appendChild(htitle);
33+
34+
var image_num = 0;
35+
for (let image of images) {
36+
image_num++;
37+
38+
var title = document.createElement('p');
39+
title.innerHTML = "<strong>Figure " + image_num + ".</strong> " + image.alt;
40+
article_here.appendChild(title);
41+
42+
var img = document.createElement('img');
43+
img.src = image.src;
44+
article_here.appendChild(img);
45+
46+
if (image_num < images.length) {
47+
var hr = document.createElement('hr');
48+
article_here.appendChild(hr);
49+
}
50+
}
2451
}
2552
}
2653
}
@@ -34,7 +61,7 @@ title: Figures
3461
Create anchor for each one of the episodes.
3562
{% endcomment %}
3663
{% for episode in site.episodes %}
37-
<article id="{{ episode.url }}"></article>
64+
<article id="{{ episode.url }}" class="figures"></article>
3865
{% endfor %}
3966

4067
{% include links.md %}

0 commit comments

Comments
 (0)