git ssb

2+

cel / scuttlebot.io



Tree: c83445d9bbe38b0be91be64d4cba8164efb72630

Files: c83445d9bbe38b0be91be64d4cba8164efb72630 / tmpl / com.part.js

1061 bytesRaw
1
2// `examples` is an object, mapping language->example
3module.exports.code = examples => {
4 return `<div class="code-examples">
5 <div class="head">
6 ${ Object.keys(examples).sort(langPrioritySort).map(lang => `<div class="tab">${lang}</div>`).join('') }
7 </div>
8 <div class="body">
9 ${ Object.keys(examples).sort(langPrioritySort).map(lang => `<pre><code class="language-${lang}">${cleanupCode(examples[lang])}</code></pre>`).join('') }
10 </div>
11 </div>`
12}
13
14module.exports.tableOfContents = items => {
15 items = items
16 .map(item => [item.children[0].url, item.children[1].value])
17 .filter(item => item[0] && item[1])
18 return `<div class="table-of-contents">
19 <a href="#">Jump to section</a>
20 <ul>
21 ${ items.map(item => `<li><a href="${item[0]}">${item[1]}</a></li>`).join('') }
22 </ul>
23 </div>`
24}
25
26// enforce an order to the language tabs
27function langPrioritySort (a, b) {
28 if (b == 'bash' && a != 'bash')
29 return 1
30 return -1
31}
32
33// do some cleanup on the code
34function cleanupCode (str) {
35 return str.trim()
36}

Built with git-ssb-web