Skip to content

Commit 4cda35a

Browse files
committed
Updating to latest template
2 parents 314c087 + c20de9a commit 4cda35a

19 files changed

+219
-75
lines changed

.config.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
collections:
55
en:
66
output: true
7-
permalink: /:collection/:title/
7+
permalink: /:collection/:title.html
88

99
# Specify the use of the "lesson" template for elements of the "en" collection.
1010
defaults:
@@ -42,5 +42,7 @@ exclude:
4242
- misc
4343
- node_modules
4444
- requirements.txt
45+
- site.mk
46+
- site.yml
4547
- src
4648
- tex

.gitignore

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@
99
*.pyg
1010
*.toc
1111
*~
12-
.cache
12+
.DS_Store
13+
.Rhistory
14+
.Rproj.user
15+
.cache/
16+
.coverage
1317
.jekyll-metadata
18+
.pytest_cache
19+
.~lock.*
1420
__pycache__
1521
_minted-*
1622
_site
1723
dist
18-
node_modules
24+
en_rmd/figures
25+
htmlcov
26+
node_modules/
1927
package-lock.json
28+
project/results/*.*
29+
tex/*/*.pdf
2030
tex/*/all.tex

Makefile

+32-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ $(warning Please set 'lang' with 'lang=en' or similar.)
44
lang=en
55
endif
66

7+
# Controls
8+
all : commands
9+
710
# Pick up project-specific setting for STEM.
11+
# (Must come after definition of 'all' to avoid confusion about default target.)
812
include site.mk
913

14+
# Overall configuration file.
15+
CONFIG_YML=_config.yml
16+
1017
# Tools.
1118
JEKYLL=jekyll
1219
PANDOC=pandoc
@@ -15,21 +22,20 @@ BIBTEX=bibtex
1522
PYTHON=python
1623

1724
# Language-dependent settings.
18-
CONFIG_YML=_config.yml
1925
DIR_MD=_${lang}
26+
DIR_RMD=${lang}_rmd
27+
RMD_SRC=$(wildcard ${DIR_RMD}/*.Rmd)
28+
RMD_DST=$(patsubst ${DIR_RMD}/%.Rmd,${DIR_MD}/%.md,${RMD_SRC})
2029
PAGES_MD=$(wildcard ${DIR_MD}/*.md)
2130
BIB_MD=${DIR_MD}/bib.md
2231
TOC_JSON=_data/${lang}_toc.json
2332
DIR_HTML=_site/${lang}
24-
PAGES_HTML=${DIR_HTML}/index.html $(patsubst ${DIR_MD}/%.md,${DIR_HTML}/%/index.html,$(filter-out ${DIR_MD}/index.md,${PAGES_MD}))
33+
PAGES_HTML=$(patsubst ${DIR_MD}/%.md,${DIR_HTML}/%.html,${PAGES_MD})
2534
DIR_TEX=tex/${lang}
2635
BIB_TEX=${DIR_TEX}/book.bib
2736
ALL_TEX=${DIR_TEX}/all.tex
2837
BOOK_PDF=${DIR_TEX}/${STEM}.pdf
2938

30-
# Controls
31-
all : commands
32-
3339
## commands : show all commands.
3440
commands :
3541
@grep -h -E '^##' ${MAKEFILE_LIST} | sed -e 's/## //g'
@@ -54,14 +60,18 @@ config : ${CONFIG_YML}
5460
## toc : regenerate the table of contents JSON file.
5561
toc : ${TOC_JSON}
5662

63+
## rmarkdown : rebuild Markdown source from R Markdown.
64+
rmarkdown : ${RMD_DST}
65+
5766
# ----------------------------------------
5867

5968
# Regenerate PDF once 'all.tex' has been created.
60-
${BOOK_PDF} : ${ALL_TEX} tex/settings.tex ${DIR_TEX}/book.tex ${BIB_TEX}
69+
${BOOK_PDF} : ${ALL_TEX} tex/settings.tex ${DIR_TEX}/book.tex ${DIR_TEX}/site.tex ${BIB_TEX}
6170
cd ${DIR_TEX} \
6271
&& ${LATEX} --shell-escape -jobname=${STEM} book \
6372
&& ${BIBTEX} ${STEM} \
6473
&& ${LATEX} --shell-escape -jobname=${STEM} book \
74+
&& ${LATEX} --shell-escape -jobname=${STEM} book \
6575
&& ${LATEX} --shell-escape -jobname=${STEM} book
6676

6777
# Create the unified LaTeX file (separate target to simplify testing).
@@ -83,6 +93,14 @@ test-pandoc:
8393
| ${PYTHON} bin/transform.py --pre ${lang} _includes \
8494
| ${PANDOC} --wrap=preserve -f html -t latex -o -
8595

96+
# Build Markdown from R Markdown.
97+
${DIR_MD}/%.md : ${DIR_RMD}/%.Rmd
98+
@bin/build.R $< $@
99+
@if [ -d ${DIR_RMD}/figures/$$(basename $< .Rmd) ]; \
100+
then \
101+
cp ${DIR_RMD}/figures/$$(basename $< .Rmd)/* ./figures/$$(basename $< .Rmd); \
102+
fi
103+
86104
# Create all the HTML pages once the Markdown files are up to date.
87105
${PAGES_HTML} : ${PAGES_MD} ${BIB_MD} ${CONFIG_YML} ${TOC_JSON}
88106
${JEKYLL} build
@@ -176,22 +194,28 @@ spelling :
176194
undone :
177195
@grep -l 'undone: true' _en/*.md | cat
178196

197+
## words : count words
198+
words :
199+
@for i in _en/*.md; do printf '%5d %s\n' $$(bin/uncode.py $$i | wc -w) $$i; done
200+
179201
## ----------------------------------------
180202

181203
## clean : clean up junk files.
182204
clean :
183-
@rm -r -f _config.yml _site dist
205+
@rm -r -f _site dist
184206
@find . -name '*~' -delete
185207
@find . -name __pycache__ -prune -exec rm -r "{}" \;
186208
@find . -name '_minted-*' -prune -exec rm -r "{}" \;
187-
@rm -r -f tex/*/all.tex tex/*/*.aux tex/*/*.bbl tex/*/*.blg tex/*/*.log tex/*/*.out tex/*/*.toc
209+
@rm -f tex/*/all.tex tex/*/*.{aux,bbl,blg,lof,log,lot,out,toc}
188210
@find . -name .DS_Store -prune -exec rm -r "{}" \;
189211

190212
## settings : show macro values.
191213
settings :
192214
@echo "CONFIG_YML=${CONFIG_YML}"
193215
@echo "JEKYLL=${JEKYLL}"
194216
@echo "DIR_MD=${DIR_MD}"
217+
@echo "RMD_SRC=${RMD_SRC}"
218+
@echo "RMD_DST=${RMD_DST}"
195219
@echo "PAGES_MD=${PAGES_MD}"
196220
@echo "BIB_MD=${BIB_MD}"
197221
@echo "DIR_HTML=${DIR_HTML}"

_config.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ datasource: "https://figshare.com/articles/Portal_Project_Teaching_Database/1314
5454
collections:
5555
en:
5656
output: true
57-
permalink: /:collection/:title/
57+
permalink: /:collection/:title.html
5858

5959
# Specify the use of the "lesson" template for elements of the "en" collection.
6060
defaults:
@@ -92,5 +92,7 @@ exclude:
9292
- misc
9393
- node_modules
9494
- requirements.txt
95+
- site.mk
96+
- site.yml
9597
- src
9698
- tex

_en/bib.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ title: "Bibliography"
1616

1717
**Meek2017**{:#b:Meek2017}: Elijah Meeks: *D3.js in Action*. Manning, 2017, <https://www.manning.com/books/d3js-in-action-second-edition>. *A comprehensive guide to the D3 visualization framework.*
1818

19-
**Mori2012**{:#b:Mori2012}: Andrew Morin and Jennifer Urban AND Piotr Sliz: "A Quick Guide to Software Licensing for the Scientist-Programmer". *PLoS Computational Biology*, 8(7), Jul 2012, <https://doi.org/10.1371/journal.pcbi.1002598>. *A short introduction to software licensing for non-specialists.*
19+
**Mori2012**{:#b:Mori2012}: Andrew Morin, Jennifer Urban, and Piotr Sliz: "A Quick Guide to Software Licensing for the Scientist-Programmer". *PLoS Computational Biology*, 8(7), Jul 2012, <https://doi.org/10.1371/journal.pcbi.1002598>. *A short introduction to software licensing for non-specialists.*
2020

2121
**Wils2018**{:#b:Wils2018}: Greg Wilson: *Teaching Tech Together*. Lulu.com, 2018, <http://teachtogether.tech>. *How to create and deliver lessons that work and build a teaching community around them.*
2222

_en/intro.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ since it isolates projects from one another.
8181
## Who We Are {#s:intro-contributors}
8282

8383
<!-- == noindent -->
84-
<img src="../../figures/hodges-toby.png" alt="Toby Hodges" width="100" />
84+
<img src="../figures/hodges-toby.png" alt="Toby Hodges" width="100" />
8585

8686
<!-- == noindent -->
8787
**[Toby Hodges][hodges-toby]** is a bioinformatician turned community
@@ -93,7 +93,7 @@ to thank his wife for her support and patience while he swore about how annoying
9393
JavaScript is to debug.
9494

9595
<!-- == noindent -->
96-
<img src="../../figures/wilson-greg.png" alt="Greg Wilson" width="100" />
96+
<img src="../figures/wilson-greg.png" alt="Greg Wilson" width="100" />
9797

9898
<!-- == noindent -->
9999
**[Greg Wilson][wilson-greg]** has worked for 35 years in both industry and

_includes/figure.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<figure id="{{include.id}}"> <img src="{{include.src}}" /> <figcaption>{{include.caption}}</figcaption> </figure>
1+
{%- assign figure_path = '/figures/' | append: page.slug | append: '/' | append: include.src -%}
2+
<figure id="{{include.id}}"> <img src="{{figure_path|relative_url}}" /> <figcaption>{{include.caption}}</figcaption> </figure>

_includes/toc-bib.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
<p>
66
{% if page.slug == "bib" %}<strong>{% endif %}
7-
<a href="{{'/'|append: include.language|append: '/bib/'|relative_url}}" class="toc">Bibliography</a>
7+
<a href="{{'/'|append: include.language|append: '/bib.html'|relative_url}}" class="toc">Bibliography</a>
88
{% if page.slug == "bib" %}</strong>{% endif %}
99
</p>

_includes/toc-section.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{% comment %}If there's a match, add a link to the generated ToC.{% endcomment %}
1717
{%- if lesson == chap.slug -%}
1818
<li>{% if page.slug == chap.slug %}<strong>{% endif %}
19-
<a href="{{'/'|append: include.language|append: '/'|append: chap.slug|append: '/'|relative_url}}" class="toc">
19+
<a href="{{'/'|append: include.language|append: '/'|append: chap.slug|append: '.html'|relative_url}}" class="toc">
2020
{% if chap.undone %}<em>{% endif %}{{chap.title}}{% if chap.undone %} &#9734;</em>{% endif %}
2121
</a>
2222
{% if page.slug == chap.slug %}</strong>{% endif %}

assets/site.css

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ figcaption {
138138
font-weight: bold;
139139
}
140140

141+
figure img {
142+
max-width: 90%;
143+
}
144+
141145
/* Mark quotations. */
142146
blockquote {
143147
border-radius: 10px;

assets/site.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ const fixTables = () => {
2323

2424
// Fix glossary reference URLs.
2525
const fixGlossRefs = () => {
26-
const pageIsRoot = document.currentScript.getAttribute('ROOT') != ''
27-
const bibStem = pageIsRoot ? './gloss/' : '../gloss/'
26+
const bibStem = './gloss.html'
2827
Array.from(document.querySelectorAll('a'))
2928
.filter(e => e.getAttribute('href').startsWith('#g:'))
3029
.forEach(e => {
@@ -35,8 +34,7 @@ const fixGlossRefs = () => {
3534

3635
// Convert bibliography citation links.
3736
const fixBibRefs = () => {
38-
const pageIsRoot = document.currentScript.getAttribute('ROOT') != ''
39-
const bibStem = pageIsRoot ? './bib/#b:' : '../bib/#b:'
37+
const bibStem = './bib.html#b:'
4038
Array.from(document.querySelectorAll('a'))
4139
.filter(e => e.getAttribute('href') == '#BIB')
4240
.forEach(e => {
@@ -52,7 +50,6 @@ const fixBibRefs = () => {
5250

5351
// Fix cross-reference links.
5452
const fixCrossRefs = () => {
55-
const prefix = document.currentScript.getAttribute('ROOT') != '' ? '.' : '..'
5653
const crossref = JSON.parse(document.currentScript.getAttribute('CROSSREF'))
5754
Array.from(document.querySelectorAll('a'))
5855
.filter(e => {
@@ -62,7 +59,7 @@ const fixCrossRefs = () => {
6259
.forEach(e => {
6360
const key = e.textContent
6461
const entry = crossref[key]
65-
const link = prefix + '/' + entry.slug + '/#' + key
62+
const link = './' + entry.slug + '.html#' + key
6663
const text = entry.text + '&nbsp;' + entry.value
6764
e.setAttribute('href', link)
6865
e.innerHTML = text
@@ -71,7 +68,6 @@ const fixCrossRefs = () => {
7168

7269
// Fix figure captions.
7370
const fixFigureCaptions = () => {
74-
const prefix = document.currentScript.getAttribute('ROOT') != '' ? '.' : '..'
7571
const crossref = JSON.parse(document.currentScript.getAttribute('CROSSREF'))
7672
Array.from(document.querySelectorAll('figure'))
7773
.forEach(e => {
@@ -84,7 +80,6 @@ const fixFigureCaptions = () => {
8480

8581
// Fix table captions.
8682
const fixTableCaptions = () => {
87-
const prefix = document.currentScript.getAttribute('ROOT') != '' ? '.' : '..'
8883
const crossref = JSON.parse(document.currentScript.getAttribute('CROSSREF'))
8984
Array.from(document.querySelectorAll('table'))
9085
.filter(e => e.hasAttribute('title'))

bin/build.R

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env Rscript
2+
3+
library(stringr)
4+
library(purrr)
5+
library(knitr)
6+
7+
USAGE = "Knit an RMarkdown files to create a Markdown file.
8+
9+
Usage: build.R source dest"
10+
11+
args <- commandArgs(trailingOnly = TRUE)
12+
if (((length(args) == 1) && (args[1] %in% c("-h", "--help"))) || (length(args) != 2)) {
13+
message(USAGE)
14+
quit(status = 0)
15+
}
16+
src = normalizePath(args[1])
17+
dst = normalizePath(args[2])
18+
setwd(dirname(src))
19+
knit(src, output = dst)

bin/check.py

+29-9
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def check_figures(language):
130130
'''
131131
def _ignore(filename):
132132
return filename.startswith('.') or \
133+
filename.endswith('.gif') or \
133134
filename.endswith('.odg') or \
134135
filename.endswith('.pdf') or \
135136
filename.endswith('.xml')
@@ -139,8 +140,12 @@ def _redundant(filename, defined):
139140
filename.replace('.png', '.svg') in defined
140141

141142
content = get_all_docs(language)
142-
used = _match_lines(content, r'{%\s+include\s+figure.html[^%]+src=".+/figures/([^"]+)"')
143-
defined = {f for f in os.listdir(FIGURE_DIR) if not _ignore(f)}
143+
by_doc = _match_lines_by_doc(content, r'{%\s+include\s+figure.html[^%]+src="([^"]+)"')
144+
used = set()
145+
for slug in by_doc:
146+
used |= {os.path.join(FIGURE_DIR, slug, filename) for filename in by_doc[slug]}
147+
used |= _match_lines(content, r'^!\[.+\]\(\.\./(.+)\)')
148+
defined = {f for f in glob.glob(os.path.join(FIGURE_DIR, '**/*.*')) if not _ignore(f)}
144149
defined -= {f for f in defined if _redundant(f, defined)}
145150
report('Figures', 'unused', defined - used)
146151
report('Figures', 'missing', used - defined)
@@ -224,7 +229,8 @@ def _unprefix(filename):
224229
return filename[prefix_len:]
225230

226231
content = get_all_docs(language, remove_code_blocks=False)
227-
referenced = match_body(content, r'{:\s+title="([^"]+)\s*"}')
232+
referenced = match_body(content, r'{:\s+title="([^"]+)\s*"[^}]*}') | \
233+
match_body(content, r'<!--\s+used="([^"]+)"\s+-->')
228234
actual = {_unprefix(filename)
229235
for filename in glob.iglob('{}/**/*.*'.format(SOURCE_DIR), recursive=True)
230236
if not _ignore_file(filename)}
@@ -278,15 +284,29 @@ def _match_lines(content, pattern, splitter=None):
278284
'''
279285
Find all matches in all lines, splitting and flattening if asked to do so.
280286
'''
281-
pat = re.compile(pattern)
287+
by_doc = _match_lines_by_doc(content, pattern, splitter=splitter)
282288
result = set()
289+
for doc in by_doc:
290+
result |= by_doc[doc]
291+
return result
292+
293+
294+
def _match_lines_by_doc(content, pattern, splitter=None):
295+
'''
296+
Find all matches in all lines, splitting and flattening if asked to do so.
297+
Return a dictionary of doc:match_set.
298+
'''
299+
pat = re.compile(pattern)
300+
result = {}
283301
for (slug, filename, body, lines) in content:
302+
temp = set()
284303
for line in lines:
285-
result |= set(pat.findall(line))
286-
if splitter is not None:
287-
result = {individual
288-
for group in result
289-
for individual in group.split(splitter)}
304+
temp |= set(pat.findall(line))
305+
if splitter is not None:
306+
temp = {individual
307+
for group in temp
308+
for individual in group.split(splitter)}
309+
result[slug] = temp
290310
return result
291311

292312

bin/get_body.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_all(source_dir):
3535
def make_filenames(source_dir, slugs):
3636
'''Turn slugs into filenames.'''
3737

38-
return [os.path.join(source_dir, s, 'index.html') for s in slugs]
38+
return [os.path.join(source_dir, '{}.html'.format(s)) for s in slugs]
3939

4040

4141
#-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)