Skip to content

Commit 01fd042

Browse files
authored
Restore www/_build/widgets.mjs deleted in cc754ce (#660)
The eleventy config was renamed from .eleventy.js to eleventy.config.mjs and updated to import from ./_build/widgets.mjs, but the widgets file was deleted instead of renamed. This broke the docs site build.
1 parent 48d3620 commit 01fd042

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ tmp/
99
test/.bundle/
1010
test-results/
1111
www/_site/
12-
www/_build/

www/_build/widgets.mjs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
export function addWidgets(config) {
2+
config.addPairedShortcode('example', (content, caption) => {
3+
let rv = "<figure class='box'>\n\n"
4+
if (caption) rv += `<figcaption class="allcaps" >Example: ${caption}</figcaption>\n\n`
5+
else rv += `<figcaption class="allcaps">Example</figcaption>\n\n`
6+
rv += " ~~~ html"
7+
rv += content
8+
rv += "~~~\n\n"
9+
rv += content
10+
rv += "</figure>"
11+
return rv
12+
})
13+
14+
function syntax(syntax) {
15+
syntax = syntax
16+
.replace(/\[\[([\*\+\?])\]\]/g,
17+
"<sup>$1</sup>"
18+
)
19+
.replace(/\[\[([a-zA-Z0-9 ]+)\]\]/g,
20+
'<b class="chip syntaxvar"><var>$1</var></b>'
21+
)
22+
23+
return `<code class="syntax">${syntax}</code>`
24+
}
25+
26+
config.addShortcode("syntax", syntax)
27+
28+
function syntaxify(line) {
29+
return line
30+
.replace(/`([^`]+)`/g, (match, p1) => syntax(p1))
31+
}
32+
33+
config.addPairedShortcode("syntaxes", content => {
34+
const buf = []
35+
const lines = content.split('\n');
36+
let dt = false;
37+
for (const line of lines) {
38+
if (isJustWhitespace(line)) {
39+
buf.push(line);
40+
} else if (!indented(line)) {
41+
dt = true;
42+
buf.push('\n<dt>' + syntaxify(line));
43+
} else {
44+
if (dt) buf.push('<dd>\n');
45+
dt = false;
46+
buf.push(dedent(line));
47+
}
48+
}
49+
return `<div class="box"><dl class="syntaxes">${buf.join('\n')}</dl></div>`;
50+
})
51+
}
52+
53+
function isJustWhitespace(str) { return /^\s*$/.test(str) }
54+
function dedent(str) { return str.replace(/^(\t| )/, '') }
55+
function indented(str) { return str.startsWith(' ') || str.startsWith('\t') }

0 commit comments

Comments
 (0)